about summary refs log tree commit diff
diff options
context:
space:
mode:
authorblyxyas <blyxyas@gmail.com>2023-02-18 20:05:30 +0100
committerblyxyas <blyxyas@gmail.com>2023-02-18 20:05:30 +0100
commit89fde4abf2c689c0ad5a09cc423a0a7be475d6ee (patch)
tree87e38184807d89fee07be1629c1cab988b697937
parent6ef34bf009343a398b3d04850c5f0784329ebe99 (diff)
downloadrust-89fde4abf2c689c0ad5a09cc423a0a7be475d6ee.tar.gz
rust-89fde4abf2c689c0ad5a09cc423a0a7be475d6ee.zip
Add placeholders, remove name suggesting
-rw-r--r--clippy_lints/src/functions/impl_trait_in_params.rs34
-rw-r--r--tests/ui/impl_trait_in_params.stderr8
2 files changed, 9 insertions, 33 deletions
diff --git a/clippy_lints/src/functions/impl_trait_in_params.rs b/clippy_lints/src/functions/impl_trait_in_params.rs
index 1f00e357bfa..2811a73f6c1 100644
--- a/clippy_lints/src/functions/impl_trait_in_params.rs
+++ b/clippy_lints/src/functions/impl_trait_in_params.rs
@@ -1,6 +1,6 @@
 use clippy_utils::{diagnostics::span_lint_and_then, is_in_test_function};
 
-use rustc_hir::{intravisit::FnKind, Body, Generics, HirId};
+use rustc_hir::{intravisit::FnKind, Body, HirId};
 use rustc_lint::LateContext;
 use rustc_span::Span;
 
@@ -19,13 +19,12 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
                         param.span,
                         "'`impl Trait` used as a function parameter'",
                         |diag| {
-                            let next_letter = next_valid_letter(generics);
                             if let Some(gen_span) = generics.span_for_param_suggestion() {
                                 diag.span_suggestion_with_style(
                                     gen_span,
                                     "add a type paremeter",
-                                    format!(", {next_letter}: {}", &param.name.ident().as_str()[5..]),
-                                    rustc_errors::Applicability::MaybeIncorrect,
+                                    format!(", {{ /* Generic name */ }}: {}", &param.name.ident().as_str()[5..]),
+                                    rustc_errors::Applicability::HasPlaceholders,
                                     rustc_errors::SuggestionStyle::ShowAlways,
                                 );
                             } else {
@@ -37,8 +36,8 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
                                         ident.span.parent(),
                                     ),
                                     "add a type paremeter",
-                                    format!("<{next_letter}: {}>", &param.name.ident().as_str()[5..]),
-                                    rustc_errors::Applicability::MaybeIncorrect,
+                                    format!("<{{ /* Generic name */ }}: {}>", &param.name.ident().as_str()[5..]),
+                                    rustc_errors::Applicability::HasPlaceholders,
                                     rustc_errors::SuggestionStyle::ShowAlways,
                                 );
                             }
@@ -49,26 +48,3 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
         }
     }
 }
-
-fn next_valid_letter(generics: &Generics<'_>) -> char {
-    let mut generics_names = Vec::new();
-
-    generics.params.iter().for_each(|param| {
-        generics_names.push(param.name.ident().as_str().to_owned());
-    });
-
-    // If T exists, try with U, then with V, and so on...
-    let mut current_letter = 84u32; // ASCII code for "T"
-    while generics_names.contains(&String::from(char::from_u32(current_letter).unwrap())) {
-        current_letter += 1;
-        if current_letter == 91 {
-            // ASCII code for "Z"
-            current_letter = 65;
-        } else if current_letter == 83 {
-            // ASCII "S"
-            current_letter = 97; // "a"
-        };
-    }
-
-    char::from_u32(current_letter).unwrap()
-}
diff --git a/tests/ui/impl_trait_in_params.stderr b/tests/ui/impl_trait_in_params.stderr
index c0bcdfd6d42..acfcc21445e 100644
--- a/tests/ui/impl_trait_in_params.stderr
+++ b/tests/ui/impl_trait_in_params.stderr
@@ -7,8 +7,8 @@ LL | pub fn a(_: impl Trait) {}
    = note: `-D clippy::impl-trait-in-params` implied by `-D warnings`
 help: add a type paremeter
    |
-LL | pub fn a<T: Trait>(_: impl Trait) {}
-   |         ++++++++++
+LL | pub fn a<{ /* Generic name */ }: Trait>(_: impl Trait) {}
+   |         +++++++++++++++++++++++++++++++
 
 error: '`impl Trait` used as a function parameter'
   --> $DIR/impl_trait_in_params.rs:9:29
@@ -18,8 +18,8 @@ LL | pub fn c<C: Trait>(_: C, _: impl Trait) {}
    |
 help: add a type paremeter
    |
-LL | pub fn c<C: Trait, T: Trait>(_: C, _: impl Trait) {}
-   |                  ++++++++++
+LL | pub fn c<C: Trait, { /* Generic name */ }: Trait>(_: C, _: impl Trait) {}
+   |                  +++++++++++++++++++++++++++++++
 
 error: aborting due to 2 previous errors