@@ -115,18 +115,21 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
115
115
}
116
116
}
117
117
118
- fn get_type ( & self , ex : & ' tcx Expr < ' _ > ) -> Ty < ' tcx > {
119
- self . cx . typeck_results ( ) . expr_ty ( ex)
120
- }
121
-
122
- fn has_sig_drop_attr ( & mut self , cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> bool {
118
+ fn is_sig_drop_expr ( & mut self , ex : & ' tcx Expr < ' _ > ) -> bool {
123
119
self . seen_types . clear ( ) ;
124
- self . has_sig_drop_attr_impl ( cx , ty )
120
+ self . has_sig_drop_attr ( self . cx . typeck_results ( ) . expr_ty ( ex ) )
125
121
}
126
122
127
- fn has_sig_drop_attr_impl ( & mut self , cx : & LateContext < ' tcx > , ty : Ty < ' tcx > ) -> bool {
123
+ fn has_sig_drop_attr ( & mut self , ty : Ty < ' tcx > ) -> bool {
128
124
if let Some ( adt) = ty. ty_adt_def ( ) {
129
- if get_attr ( cx. sess ( ) , cx. tcx . get_attrs_unchecked ( adt. did ( ) ) , "has_significant_drop" ) . count ( ) > 0 {
125
+ if get_attr (
126
+ self . cx . sess ( ) ,
127
+ self . cx . tcx . get_attrs_unchecked ( adt. did ( ) ) ,
128
+ "has_significant_drop" ,
129
+ )
130
+ . count ( )
131
+ > 0
132
+ {
130
133
return true ;
131
134
}
132
135
}
@@ -139,8 +142,8 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
139
142
rustc_middle:: ty:: Adt ( adt, args) => {
140
143
// if some field has significant drop,
141
144
adt. all_fields ( )
142
- . map ( |field| field. ty ( cx. tcx , args) )
143
- . any ( |ty| self . has_sig_drop_attr ( cx , ty) )
145
+ . map ( |field| field. ty ( self . cx . tcx , args) )
146
+ . any ( |ty| self . has_sig_drop_attr ( ty) )
144
147
// or if there is no generic lifetime and..
145
148
// (to avoid false positive on `Ref<'a, MutexGuard<Foo>>`)
146
149
|| ( args
@@ -154,10 +157,10 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> {
154
157
GenericArgKind :: Type ( ty) => Some ( ty) ,
155
158
_ => None ,
156
159
} )
157
- . any ( |ty| self . has_sig_drop_attr ( cx , ty) ) )
160
+ . any ( |ty| self . has_sig_drop_attr ( ty) ) )
158
161
} ,
159
- rustc_middle:: ty:: Tuple ( tys) => tys. iter ( ) . any ( |ty| self . has_sig_drop_attr ( cx , ty) ) ,
160
- rustc_middle:: ty:: Array ( ty, _) | rustc_middle:: ty:: Slice ( ty) => self . has_sig_drop_attr ( cx , * ty) ,
162
+ rustc_middle:: ty:: Tuple ( tys) => tys. iter ( ) . any ( |ty| self . has_sig_drop_attr ( ty) ) ,
163
+ rustc_middle:: ty:: Array ( ty, _) | rustc_middle:: ty:: Slice ( ty) => self . has_sig_drop_attr ( * ty) ,
161
164
_ => false ,
162
165
} ;
163
166
@@ -240,7 +243,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> {
240
243
if self . current_sig_drop . is_some ( ) {
241
244
return ;
242
245
}
243
- let ty = self . sig_drop_checker . get_type ( expr) ;
246
+ let ty = self . cx . typeck_results ( ) . expr_ty ( expr) ;
244
247
if ty. is_ref ( ) {
245
248
// We checked that the type was ref, so builtin_deref will return Some TypeAndMut,
246
249
// but let's avoid any chance of an ICE
@@ -287,11 +290,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> {
287
290
288
291
impl < ' a , ' tcx > Visitor < ' tcx > for SigDropHelper < ' a , ' tcx > {
289
292
fn visit_expr ( & mut self , ex : & ' tcx Expr < ' _ > ) {
290
- if !self . is_chain_end
291
- && self
292
- . sig_drop_checker
293
- . has_sig_drop_attr ( self . cx , self . sig_drop_checker . get_type ( ex) )
294
- {
293
+ if !self . is_chain_end && self . sig_drop_checker . is_sig_drop_expr ( ex) {
295
294
self . has_significant_drop = true ;
296
295
return ;
297
296
}
@@ -395,10 +394,7 @@ fn has_significant_drop_in_arms<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'
395
394
396
395
impl < ' a , ' tcx > Visitor < ' tcx > for ArmSigDropHelper < ' a , ' tcx > {
397
396
fn visit_expr ( & mut self , ex : & ' tcx Expr < ' tcx > ) {
398
- if self
399
- . sig_drop_checker
400
- . has_sig_drop_attr ( self . sig_drop_checker . cx , self . sig_drop_checker . get_type ( ex) )
401
- {
397
+ if self . sig_drop_checker . is_sig_drop_expr ( ex) {
402
398
self . found_sig_drop_spans . insert ( ex. span ) ;
403
399
return ;
404
400
}
0 commit comments