@@ -18,6 +18,11 @@ declare_clippy_lint! {
18
18
/// Naming type parameters inconsistently may cause you to refer to the
19
19
/// wrong type parameter.
20
20
///
21
+ /// ### Limitations
22
+ /// This lint only applies to impl blocks with simple generic params, e.g.
23
+ /// `A`. If there is anything more complicated, such as a tuple, it will be
24
+ /// ignored.
25
+ ///
21
26
/// ### Example
22
27
/// ```rust
23
28
/// struct Foo<A, B> {
@@ -53,14 +58,15 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch {
53
58
if !generic_args. args. is_empty( ) ;
54
59
then {
55
60
// get the name and span of the generic parameters in the Impl
56
- let impl_params = generic_args . args . iter ( )
57
- . filter_map ( |p|
61
+ let mut impl_params = Vec :: new ( ) ;
62
+ for p in generic_args . args . iter ( ) {
58
63
match p {
59
64
GenericArg :: Type ( Ty { kind: TyKind :: Path ( QPath :: Resolved ( _, path) ) , ..} ) =>
60
- Some ( ( path. segments[ 0 ] . ident. to_string( ) , path. span) ) ,
61
- _ => None ,
62
- }
63
- ) ;
65
+ impl_params. push( ( path. segments[ 0 ] . ident. to_string( ) , path. span) ) ,
66
+ GenericArg :: Type ( _) => return ,
67
+ _ => ( ) ,
68
+ } ;
69
+ }
64
70
65
71
// find the type that the Impl is for
66
72
// only lint on struct/enum/union for now
@@ -83,16 +89,16 @@ impl<'tcx> LateLintPass<'tcx> for TypeParamMismatch {
83
89
type_param_names. iter( ) . enumerate( ) . map( |( i, param) | ( param, i) ) . collect( ) ;
84
90
85
91
let type_name = segment. ident;
86
- for ( i, ( impl_param_name, impl_param_span) ) in impl_params. enumerate( ) {
87
- if mismatch_param_name( i, & impl_param_name, & type_param_names_hashmap) {
92
+ for ( i, ( impl_param_name, impl_param_span) ) in impl_params. iter ( ) . enumerate( ) {
93
+ if mismatch_param_name( i, impl_param_name, & type_param_names_hashmap) {
88
94
let msg = format!( "`{}` has a similarly named generic type parameter `{}` in its declaration, but in a different order" ,
89
95
type_name, impl_param_name) ;
90
96
let help = format!( "try `{}`, or a name that does not conflict with `{}`'s generic params" ,
91
97
type_param_names[ i] , type_name) ;
92
98
span_lint_and_help(
93
99
cx,
94
100
MISMATCHING_TYPE_PARAM_ORDER ,
95
- impl_param_span,
101
+ * impl_param_span,
96
102
& msg,
97
103
None ,
98
104
& help
0 commit comments