Skip to content

Commit 89fde4a

Browse files
committed
Add placeholders, remove name suggesting
1 parent 6ef34bf commit 89fde4a

File tree

2 files changed

+9
-33
lines changed

2 files changed

+9
-33
lines changed
Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::{diagnostics::span_lint_and_then, is_in_test_function};
22

3-
use rustc_hir::{intravisit::FnKind, Body, Generics, HirId};
3+
use rustc_hir::{intravisit::FnKind, Body, HirId};
44
use rustc_lint::LateContext;
55
use rustc_span::Span;
66

@@ -19,13 +19,12 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
1919
param.span,
2020
"'`impl Trait` used as a function parameter'",
2121
|diag| {
22-
let next_letter = next_valid_letter(generics);
2322
if let Some(gen_span) = generics.span_for_param_suggestion() {
2423
diag.span_suggestion_with_style(
2524
gen_span,
2625
"add a type paremeter",
27-
format!(", {next_letter}: {}", &param.name.ident().as_str()[5..]),
28-
rustc_errors::Applicability::MaybeIncorrect,
26+
format!(", {{ /* Generic name */ }}: {}", &param.name.ident().as_str()[5..]),
27+
rustc_errors::Applicability::HasPlaceholders,
2928
rustc_errors::SuggestionStyle::ShowAlways,
3029
);
3130
} else {
@@ -37,8 +36,8 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
3736
ident.span.parent(),
3837
),
3938
"add a type paremeter",
40-
format!("<{next_letter}: {}>", &param.name.ident().as_str()[5..]),
41-
rustc_errors::Applicability::MaybeIncorrect,
39+
format!("<{{ /* Generic name */ }}: {}>", &param.name.ident().as_str()[5..]),
40+
rustc_errors::Applicability::HasPlaceholders,
4241
rustc_errors::SuggestionStyle::ShowAlways,
4342
);
4443
}
@@ -49,26 +48,3 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
4948
}
5049
}
5150
}
52-
53-
fn next_valid_letter(generics: &Generics<'_>) -> char {
54-
let mut generics_names = Vec::new();
55-
56-
generics.params.iter().for_each(|param| {
57-
generics_names.push(param.name.ident().as_str().to_owned());
58-
});
59-
60-
// If T exists, try with U, then with V, and so on...
61-
let mut current_letter = 84u32; // ASCII code for "T"
62-
while generics_names.contains(&String::from(char::from_u32(current_letter).unwrap())) {
63-
current_letter += 1;
64-
if current_letter == 91 {
65-
// ASCII code for "Z"
66-
current_letter = 65;
67-
} else if current_letter == 83 {
68-
// ASCII "S"
69-
current_letter = 97; // "a"
70-
};
71-
}
72-
73-
char::from_u32(current_letter).unwrap()
74-
}

tests/ui/impl_trait_in_params.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LL | pub fn a(_: impl Trait) {}
77
= note: `-D clippy::impl-trait-in-params` implied by `-D warnings`
88
help: add a type paremeter
99
|
10-
LL | pub fn a<T: Trait>(_: impl Trait) {}
11-
| ++++++++++
10+
LL | pub fn a<{ /* Generic name */ }: Trait>(_: impl Trait) {}
11+
| +++++++++++++++++++++++++++++++
1212

1313
error: '`impl Trait` used as a function parameter'
1414
--> $DIR/impl_trait_in_params.rs:9:29
@@ -18,8 +18,8 @@ LL | pub fn c<C: Trait>(_: C, _: impl Trait) {}
1818
|
1919
help: add a type paremeter
2020
|
21-
LL | pub fn c<C: Trait, T: Trait>(_: C, _: impl Trait) {}
22-
| ++++++++++
21+
LL | pub fn c<C: Trait, { /* Generic name */ }: Trait>(_: C, _: impl Trait) {}
22+
| +++++++++++++++++++++++++++++++
2323

2424
error: aborting due to 2 previous errors
2525

0 commit comments

Comments
 (0)