about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Krasnitski <michael.krasnitski@gmail.com>2023-02-12 14:45:44 -0500
committerMichael Krasnitski <michael.krasnitski@gmail.com>2023-02-15 10:01:33 -0500
commit1ee4651ca1c31b39f106079e7546a47d00a3d945 (patch)
tree0583893b1a43381f82acfb6da442267075ff0e22
parent595f783f2212a551fe513c05922d4eda0b8bda7b (diff)
downloadrust-1ee4651ca1c31b39f106079e7546a47d00a3d945.tar.gz
rust-1ee4651ca1c31b39f106079e7546a47d00a3d945.zip
Ignore synthetic type parameters for `extra_unused_type_parameters`
-rw-r--r--clippy_lints/src/extra_unused_type_parameters.rs7
-rw-r--r--tests/ui/extra_unused_type_parameters.rs2
-rw-r--r--tests/ui/extra_unused_type_parameters.stderr10
3 files changed, 14 insertions, 5 deletions
diff --git a/clippy_lints/src/extra_unused_type_parameters.rs b/clippy_lints/src/extra_unused_type_parameters.rs
index 9e9ad80b334..040473c9ffc 100644
--- a/clippy_lints/src/extra_unused_type_parameters.rs
+++ b/clippy_lints/src/extra_unused_type_parameters.rs
@@ -23,7 +23,6 @@ declare_clippy_lint! {
     ///
     /// ### Example
     /// ```rust
-    /// // unused type parameters
     /// fn unused_ty<T>(x: u8) {
     ///     // ..
     /// }
@@ -45,7 +44,7 @@ declare_lint_pass!(ExtraUnusedTypeParameters => [EXTRA_UNUSED_TYPE_PARAMETERS]);
 /// trait bounds those parameters have.
 struct TypeWalker<'cx, 'tcx> {
     cx: &'cx LateContext<'tcx>,
-    /// Collection of all the type parameters and their spans.
+    /// Collection of all the function's type parameters.
     ty_params: FxHashMap<DefId, Span>,
     /// Collection of any (inline) trait bounds corresponding to each type parameter.
     bounds: FxHashMap<DefId, Span>,
@@ -69,8 +68,8 @@ impl<'cx, 'tcx> TypeWalker<'cx, 'tcx> {
             .params
             .iter()
             .filter_map(|param| {
-                if let GenericParamKind::Type { .. } = param.kind {
-                    Some((param.def_id.into(), param.span))
+                if let GenericParamKind::Type { synthetic, .. } = param.kind {
+                    (!synthetic).then_some((param.def_id.into(), param.span))
                 } else {
                     if !param.is_elided_lifetime() {
                         all_params_unused = false;
diff --git a/tests/ui/extra_unused_type_parameters.rs b/tests/ui/extra_unused_type_parameters.rs
index a1cd8a0d085..2894fda2f47 100644
--- a/tests/ui/extra_unused_type_parameters.rs
+++ b/tests/ui/extra_unused_type_parameters.rs
@@ -71,6 +71,8 @@ where
         .filter_map(move |(i, a)| if i == index { None } else { Some(a) })
 }
 
+fn unused_opaque<A, B>(dummy: impl Default) {}
+
 mod issue10319 {
     fn assert_send<T: Send>() {}
 
diff --git a/tests/ui/extra_unused_type_parameters.stderr b/tests/ui/extra_unused_type_parameters.stderr
index 69a067bd849..aea3ee310f7 100644
--- a/tests/ui/extra_unused_type_parameters.stderr
+++ b/tests/ui/extra_unused_type_parameters.stderr
@@ -55,5 +55,13 @@ LL |     fn unused_ty_impl<T>(&self) {}
    |
    = help: consider removing the parameter
 
-error: aborting due to 7 previous errors
+error: type parameters go unused in function definition
+  --> $DIR/extra_unused_type_parameters.rs:74:17
+   |
+LL | fn unused_opaque<A, B>(dummy: impl Default) {}
+   |                 ^^^^^^
+   |
+   = help: consider removing the parameters
+
+error: aborting due to 8 previous errors