Skip to content

Commit

Permalink
Ignore synthetic params when forming help message.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrasnitski committed Feb 12, 2023
1 parent ad2135e commit 2e208ba
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 3 additions & 4 deletions clippy_lints/src/extra_unused_type_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ declare_clippy_lint! {
///
/// ### Example
/// ```rust
/// // unused type parameters
/// fn unused_ty<T>(x: u8) {
/// // ..
/// }
Expand All @@ -43,7 +42,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>,
Expand All @@ -64,8 +63,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;
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/extra_unused_type_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,6 @@ where
.filter_map(move |(i, a)| if i == index { None } else { Some(a) })
}

fn unused_opaque<A, B>(dummy: impl Default) {}

fn main() {}
10 changes: 9 additions & 1 deletion tests/ui/extra_unused_type_parameters.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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:69:17
|
LL | fn unused_opaque<A, B>(dummy: impl Default) {}
| ^^^^^^
|
= help: consider removing the parameters

error: aborting due to 8 previous errors

0 comments on commit 2e208ba

Please sign in to comment.