Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive for unit_arg when forwarding arguments #6447

Closed
csnover opened this issue Dec 12, 2020 · 1 comment · Fixed by #6601
Closed

False positive for unit_arg when forwarding arguments #6447

csnover opened this issue Dec 12, 2020 · 1 comment · Fixed by #6601
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@csnover
Copy link

csnover commented Dec 12, 2020

I tried this code:

trait Tr {
    type Args;
    fn do_it(args: Self::Args);
}

struct A;
impl Tr for A {
    type Args = ();
    fn do_it(_: Self::Args) {}
}

struct B;
impl Tr for B {
    type Args = <A as Tr>::Args;

    fn do_it(args: Self::Args) {
        A::do_it(args)
    }
}

I expected to see this happen: No lint trigger.

Instead, this happened:

warning: passing a unit value to a function
  --> src/lib.rs:17:9
   |
17 |         A::do_it(args)
   |         ^^^^^^^^^^^^^^
   |
   = note: `#[warn(clippy::unit_arg)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
   |
17 |         args;
18 |         A::do_it(())
   |

Meta

  • cargo clippy -V: clippy 0.0.212 (7eac88abb 2020-11-16)
  • rustc -Vv:
    rustc 1.48.0 (7eac88abb 2020-11-16)
    binary: rustc
    commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
    commit-date: 2020-11-16
    host: x86_64-apple-darwin
    release: 1.48.0
    LLVM version: 11.0
    

Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=00536070342bc4272bf55d028d065d03

@csnover csnover added the C-bug Category: Clippy is not doing the correct thing label Dec 12, 2020
@csnover csnover changed the title False positive for unit_arg False positive for unit_arg when forwarding arguments Dec 12, 2020
@ebroto ebroto added the good-first-issue These issues are a good way to get started with Clippy label Dec 13, 2020
@mdm
Copy link
Contributor

mdm commented Dec 16, 2020

First time contributor here. I would like to work on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants