Closed
Description
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).
- https://github.com/dtolnay/proc-macro2/blob/4822d05db17faa0639a3e0200aaf79cdacac16e0/tests/marker.rs#L12
- https://github.com/tokio-rs/tokio/blob/01bb1ecf4dee073da65dfede4c845ac27c555af0/tokio/src/lib.rs#L633
- https://github.com/tokio-rs/axum/blob/main/axum/src/test_helpers/mod.rs#L8-L10
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