Skip to content

False positive for unit_arg when forwarding arguments #6447

Closed
@csnover

Description

@csnover

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions