Skip to content

Wired false negative of clippy::extra_unused_type_parameters #12820

Closed
@mu001999

Description

@mu001999

Summary

For the following code:

fn foo<T>() { () }

fn main() {
    foo::<i32>();
}

We can get:

warning: unneeded unit expression
 --> src/main.rs:1:15
  |
1 | fn foo<T>() { () }
  |               ^^ help: remove the final `()`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
  = note: `#[warn(clippy::unused_unit)]` on by default

warning: type parameter `T` goes unused in function definition
 --> src/main.rs:1:7
  |
1 | fn foo<T>() { () }
  |       ^^^ help: consider removing the parameter
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters
  = note: `#[warn(clippy::extra_unused_type_parameters)]` on by default

But no warning after removing the unneeded unit expression in foo.

Lint Name

extra_unused_type_parameters

Reproducer

I tried this code:

fn foo<T>() {}

fn main() {
    foo::<i32>();
}

I expected to see this happen:

warning: type parameter `T` goes unused in function definition
 --> src/main.rs:1:7
  |
1 | fn foo<T>() { () }
  |       ^^^ help: consider removing the parameter
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters
  = note: `#[warn(clippy::extra_unused_type_parameters)]` on by default

Instead, nothing happened.

Version

1.80.0-nightly
(2024-05-18 b1ec1bd65f89c1375d2c)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions