11use 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 } ;
44use rustc_lint:: LateContext ;
55use 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- }
0 commit comments