@@ -72,30 +72,22 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
7272 Self { limit }
7373 }
7474
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) ;
8477
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 ) ;
8780
88- fn check_poly_fn ( & mut self , cx : & LateContext < ' _ , ' tcx > , decl : & FnDecl , sig : & FnSig < ' tcx > , span : Option < Span > ) {
8981 // Use lifetimes to determine if we're returning a reference to the
9082 // argument. In that case we can't switch to pass-by-value as the
9183 // argument will not live long enough.
92- let output_lts = match sig . output ( ) . sty {
84+ let output_lts = match fn_sig . output ( ) . sty {
9385 ty:: Ref ( output_lt, _, _) => vec ! [ output_lt] ,
9486 ty:: Adt ( _, substs) => substs. regions ( ) . collect ( ) ,
9587 _ => vec ! [ ] ,
9688 } ;
9789
98- for ( input, & ty) in decl. inputs . iter ( ) . zip ( sig . inputs ( ) ) {
90+ for ( input, & ty) in decl. inputs . iter ( ) . zip ( fn_sig . inputs ( ) ) {
9991 // All spans generated from a proc-macro invocation are the same...
10092 match span {
10193 Some ( s) if s == input. span => return ,
@@ -128,25 +120,18 @@ impl<'a, 'tcx> TriviallyCopyPassByRef {
128120 }
129121 }
130122 }
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- }
139123}
140124
141125impl_lint_pass ! ( TriviallyCopyPassByRef => [ TRIVIALLY_COPY_PASS_BY_REF ] ) ;
142126
143127impl < ' 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 ) {
145129 if in_macro_or_desugar ( item. span ) {
146130 return ;
147131 }
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 ) ;
150135 }
151136 }
152137
@@ -187,11 +172,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TriviallyCopyPassByRef {
187172 }
188173 }
189174
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) ) ;
196176 }
197177}
0 commit comments