1
1
use clippy_utils:: { diagnostics:: span_lint_and_then, is_in_test_function} ;
2
2
3
- use rustc_hir:: { intravisit:: FnKind , Body , Generics , HirId } ;
3
+ use rustc_hir:: { intravisit:: FnKind , Body , HirId } ;
4
4
use rustc_lint:: LateContext ;
5
5
use rustc_span:: Span ;
6
6
@@ -19,13 +19,12 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
19
19
param. span ,
20
20
"'`impl Trait` used as a function parameter'" ,
21
21
|diag| {
22
- let next_letter = next_valid_letter ( generics) ;
23
22
if let Some ( gen_span) = generics. span_for_param_suggestion ( ) {
24
23
diag. span_suggestion_with_style (
25
24
gen_span,
26
25
"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 ,
29
28
rustc_errors:: SuggestionStyle :: ShowAlways ,
30
29
) ;
31
30
} else {
@@ -37,8 +36,8 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
37
36
ident. span . parent ( ) ,
38
37
) ,
39
38
"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 ,
42
41
rustc_errors:: SuggestionStyle :: ShowAlways ,
43
42
) ;
44
43
}
@@ -49,26 +48,3 @@ pub(super) fn check_fn<'tcx>(cx: &LateContext<'_>, kind: &'tcx FnKind<'_>, body:
49
48
}
50
49
}
51
50
}
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