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