Skip to content

Commit f6b292b

Browse files
committed
Ignore synthetic type parameters for extra_unused_type_parameters
1 parent 595f783 commit f6b292b

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
@@ -23,7 +23,6 @@ declare_clippy_lint! {
2323
///
2424
/// ### Example
2525
/// ```rust
26-
/// // unused type parameters
2726
/// fn unused_ty<T>(x: u8) {
2827
/// // ..
2928
/// }
@@ -45,7 +44,7 @@ declare_lint_pass!(ExtraUnusedTypeParameters => [EXTRA_UNUSED_TYPE_PARAMETERS]);
4544
/// trait bounds those parameters have.
4645
struct TypeWalker<'cx, 'tcx> {
4746
cx: &'cx LateContext<'tcx>,
48-
/// Collection of all the type parameters and their spans.
47+
/// Collection of all the function's type parameters.
4948
ty_params: FxHashMap<DefId, Span>,
5049
/// Collection of any (inline) trait bounds corresponding to each type parameter.
5150
bounds: FxHashMap<DefId, Span>,
@@ -69,8 +68,8 @@ impl<'cx, 'tcx> TypeWalker<'cx, 'tcx> {
6968
.params
7069
.iter()
7170
.filter_map(|param| {
72-
if let GenericParamKind::Type { .. } = param.kind {
73-
Some((param.def_id.into(), param.span))
71+
if let GenericParamKind::Type { synthetic, .. } = param.kind {
72+
(!synthetic).then_some((param.def_id.into(), param.span))
7473
} else {
7574
if !param.is_elided_lifetime() {
7675
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
@@ -71,6 +71,8 @@ where
7171
.filter_map(move |(i, a)| if i == index { None } else { Some(a) })
7272
}
7373

74+
fn unused_opaque<A, B>(dummy: impl Default) {}
75+
7476
mod issue10319 {
7577
fn assert_send<T: Send>() {}
7678

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)