@@ -72,30 +72,22 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
72
72
Self { limit }
73
73
}
74
74
75
- fn check_trait_method ( & mut self , cx : & LateContext < ' _ , ' tcx > , item : & TraitItemRef ) {
76
- let method_def_id = cx. tcx . hir ( ) . local_def_id_from_hir_id ( item. id . hir_id ) ;
77
- let method_sig = cx. tcx . fn_sig ( method_def_id) ;
78
- let method_sig = cx. tcx . erase_late_bound_regions ( & method_sig) ;
79
-
80
- let decl = match cx. tcx . hir ( ) . fn_decl_by_hir_id ( item. id . hir_id ) {
81
- Some ( b) => b,
82
- None => return ,
83
- } ;
75
+ fn check_poly_fn ( & mut self , cx : & LateContext < ' _ , ' tcx > , hir_id : HirId , decl : & FnDecl , span : Option < Span > ) {
76
+ let fn_def_id = cx. tcx . hir ( ) . local_def_id_from_hir_id ( hir_id) ;
84
77
85
- self . check_poly_fn ( cx , & decl , & method_sig , None ) ;
86
- }
78
+ let fn_sig = cx . tcx . fn_sig ( fn_def_id ) ;
79
+ let fn_sig = cx . tcx . erase_late_bound_regions ( & fn_sig ) ;
87
80
88
- fn check_poly_fn ( & mut self , cx : & LateContext < ' _ , ' tcx > , decl : & FnDecl , sig : & FnSig < ' tcx > , span : Option < Span > ) {
89
81
// Use lifetimes to determine if we're returning a reference to the
90
82
// argument. In that case we can't switch to pass-by-value as the
91
83
// argument will not live long enough.
92
- let output_lts = match sig . output ( ) . sty {
84
+ let output_lts = match fn_sig . output ( ) . sty {
93
85
ty:: Ref ( output_lt, _, _) => vec ! [ output_lt] ,
94
86
ty:: Adt ( _, substs) => substs. regions ( ) . collect ( ) ,
95
87
_ => vec ! [ ] ,
96
88
} ;
97
89
98
- for ( input, & ty) in decl. inputs . iter ( ) . zip ( sig . inputs ( ) ) {
90
+ for ( input, & ty) in decl. inputs . iter ( ) . zip ( fn_sig . inputs ( ) ) {
99
91
// All spans generated from a proc-macro invocation are the same...
100
92
match span {
101
93
Some ( s) if s == input. span => return ,
@@ -128,25 +120,18 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
128
120
}
129
121
}
130
122
}
131
-
132
- fn check_trait_items ( & mut self , cx : & LateContext < ' _ , ' _ > , trait_items : & [ TraitItemRef ] ) {
133
- for item in trait_items {
134
- if let AssocItemKind :: Method { .. } = item. kind {
135
- self . check_trait_method ( cx, item) ;
136
- }
137
- }
138
- }
139
123
}
140
124
141
125
impl_lint_pass ! ( TriviallyCopyPassByRef => [ TRIVIALLY_COPY_PASS_BY_REF ] ) ;
142
126
143
127
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for TriviallyCopyPassByRef {
144
- fn check_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx Item ) {
128
+ fn check_trait_item ( & mut self , cx : & LateContext < ' a , ' tcx > , item : & ' tcx hir :: TraitItem ) {
145
129
if in_macro_or_desugar ( item. span ) {
146
130
return ;
147
131
}
148
- if let ItemKind :: Trait ( _, _, _, _, ref trait_items) = item. node {
149
- self . check_trait_items ( cx, trait_items) ;
132
+
133
+ if let hir:: TraitItemKind :: Method ( method_sig, _) = & item. node {
134
+ self . check_poly_fn ( cx, item. hir_id , & * method_sig. decl , None ) ;
150
135
}
151
136
}
152
137
@@ -187,11 +172,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
187
172
}
188
173
}
189
174
190
- let fn_def_id = cx. tcx . hir ( ) . local_def_id_from_hir_id ( hir_id) ;
191
-
192
- let fn_sig = cx. tcx . fn_sig ( fn_def_id) ;
193
- let fn_sig = cx. tcx . erase_late_bound_regions ( & fn_sig) ;
194
-
195
- self . check_poly_fn ( cx, decl, & fn_sig, Some ( span) ) ;
175
+ self . check_poly_fn ( cx, hir_id, decl, Some ( span) ) ;
196
176
}
197
177
}
0 commit comments