Skip to content

Commit b522965

Browse files
committed
Ignore synthetic type parameters for extra_unused_type_parameters
1 parent ad2135e commit b522965

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

clippy_lints/src/extra_unused_type_parameters.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ declare_clippy_lint! {
2121
///
2222
/// ### Example
2323
/// ```rust
24-
/// // unused type parameters
2524
/// fn unused_ty<T>(x: u8) {
2625
/// // ..
2726
/// }
@@ -43,7 +42,7 @@ declare_lint_pass!(ExtraUnusedTypeParameters => [EXTRA_UNUSED_TYPE_PARAMETERS]);
4342
/// trait bounds those parameters have.
4443
struct TypeWalker<'cx, 'tcx> {
4544
cx: &'cx LateContext<'tcx>,
46-
/// Collection of all the type parameters and their spans.
45+
/// Collection of all the function's type parameters.
4746
ty_params: FxHashMap<DefId, Span>,
4847
/// Collection of any (inline) trait bounds corresponding to each type parameter.
4948
bounds: FxHashMap<DefId, Span>,
@@ -64,8 +63,8 @@ impl<'cx, 'tcx> TypeWalker<'cx, 'tcx> {
6463
.params
6564
.iter()
6665
.filter_map(|param| {
67-
if let GenericParamKind::Type { .. } = param.kind {
68-
Some((param.def_id.into(), param.span))
66+
if let GenericParamKind::Type { synthetic, .. } = param.kind {
67+
(!synthetic).then_some((param.def_id.into(), param.span))
6968
} else {
7069
if !param.is_elided_lifetime() {
7170
all_params_unused = false;

tests/ui/extra_unused_type_parameters.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ where
6666
.filter_map(move |(i, a)| if i == index { None } else { Some(a) })
6767
}
6868

69+
fn unused_opaque<A, B>(dummy: impl Default) {}
70+
6971
fn main() {}

tests/ui/extra_unused_type_parameters.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,13 @@ LL | fn unused_ty_impl<T>(&self) {}
5555
|
5656
= help: consider removing the parameter
5757

58-
error: aborting due to 7 previous errors
58+
error: type parameters go unused in function definition
59+
--> $DIR/extra_unused_type_parameters.rs:69:17
60+
|
61+
LL | fn unused_opaque<A, B>(dummy: impl Default) {}
62+
| ^^^^^^
63+
|
64+
= help: consider removing the parameters
65+
66+
error: aborting due to 8 previous errors
5967

0 commit comments

Comments
 (0)