Skip to content

extra_unused_type_parameters probably should not warn empty functions #10319

Closed
@taiki-e

Description

@taiki-e

Summary

It is a popular pattern to define an empty function with an unused type parameter with trait bounds to ensure that the type implements the trait.
extra_unused_type_parameters probably should not warn this pattern (at least by default).

Mentioning @mkrasnitski who implemented this lint in #10028.

Lint Name

extra_unused_type_parameters

Reproducer

I tried this code:

#![warn(clippy::extra_unused_type_parameters)]

#[allow(dead_code)]
fn assert_send<T: Send>() {}

#[allow(dead_code)]
struct S(());

const _: fn() = || {
    assert_send::<S>();
};

I saw this happen:

warning: type parameter goes unused in function definition
 --> src/lib.rs:4:15
  |
4 | fn assert_send<T: Send>() {}
  |               ^^^^^^^^^
  |
  = 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: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::extra_unused_type_parameters)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I expected to see this happen: no warning

Version

rustc 1.69.0-nightly (2773383a3 2023-02-10)
binary: rustc
commit-hash: 2773383a314a4b8f481ce2bed12c32de794ffbe9
commit-date: 2023-02-10
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

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 have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions