@@ -75,38 +75,36 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
75
75
_ => return ,
76
76
} ;
77
77
// (Re)check that it implements the noop diagnostic.
78
- for s in [ sym:: noop_method_clone, sym:: noop_method_deref, sym:: noop_method_borrow] . iter ( ) {
79
- if cx. tcx . is_diagnostic_item ( * s, i. def_id ( ) ) {
80
- let method = & call. ident . name ;
81
- let receiver = & elements[ 0 ] ;
82
- let receiver_ty = cx. typeck_results ( ) . expr_ty ( receiver) ;
83
- let expr_ty = cx. typeck_results ( ) . expr_ty_adjusted ( expr) ;
84
- if receiver_ty != expr_ty {
85
- // This lint will only trigger if the receiver type and resulting expression \
86
- // type are the same, implying that the method call is unnecessary.
87
- return ;
88
- }
89
- let expr_span = expr. span ;
90
- let note = format ! (
91
- "the type `{:?}` which `{}` is being called on is the same as \
92
- the type returned from `{}`, so the method call does not do \
93
- anything and can be removed",
94
- receiver_ty, method, method,
95
- ) ;
96
-
97
- let span = expr_span. with_lo ( receiver. span . hi ( ) ) ;
98
- cx. struct_span_lint ( NOOP_METHOD_CALL , span, |lint| {
99
- let method = & call. ident . name ;
100
- let message = format ! (
101
- "call to `.{}()` on a reference in this situation does nothing" ,
102
- & method,
103
- ) ;
104
- lint. build ( & message)
105
- . span_label ( span, "unnecessary method call" )
106
- . note ( & note)
107
- . emit ( )
108
- } ) ;
109
- }
78
+ let Some ( name) = cx. tcx . get_diagnostic_name ( i. def_id ( ) ) else { return } ;
79
+ if !matches ! (
80
+ name,
81
+ sym:: noop_method_borrow | sym:: noop_method_clone | sym:: noop_method_deref
82
+ ) {
83
+ return ;
110
84
}
85
+ let method = & call. ident . name ;
86
+ let receiver = & elements[ 0 ] ;
87
+ let receiver_ty = cx. typeck_results ( ) . expr_ty ( receiver) ;
88
+ let expr_ty = cx. typeck_results ( ) . expr_ty_adjusted ( expr) ;
89
+ if receiver_ty != expr_ty {
90
+ // This lint will only trigger if the receiver type and resulting expression \
91
+ // type are the same, implying that the method call is unnecessary.
92
+ return ;
93
+ }
94
+ let expr_span = expr. span ;
95
+ let note = format ! (
96
+ "the type `{:?}` which `{}` is being called on is the same as \
97
+ the type returned from `{}`, so the method call does not do \
98
+ anything and can be removed",
99
+ receiver_ty, method, method,
100
+ ) ;
101
+
102
+ let span = expr_span. with_lo ( receiver. span . hi ( ) ) ;
103
+ cx. struct_span_lint ( NOOP_METHOD_CALL , span, |lint| {
104
+ let method = & call. ident . name ;
105
+ let message =
106
+ format ! ( "call to `.{}()` on a reference in this situation does nothing" , & method, ) ;
107
+ lint. build ( & message) . span_label ( span, "unnecessary method call" ) . note ( & note) . emit ( )
108
+ } ) ;
111
109
}
112
110
}
0 commit comments