@@ -144,7 +144,10 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
144144 Self { cx, type_cache }
145145 }
146146
147- fn has_sig_drop_attr ( & mut self , ty : Ty < ' tcx > ) -> bool {
147+ fn has_sig_drop_attr ( & mut self , ty : Ty < ' tcx > , depth : usize ) -> bool {
148+ if !self . cx . tcx . recursion_limit ( ) . value_within_limit ( depth) {
149+ return false ;
150+ }
148151 let ty = self
149152 . cx
150153 . tcx
@@ -156,12 +159,15 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
156159 e. insert ( false ) ;
157160 } ,
158161 }
159- let value = self . has_sig_drop_attr_uncached ( ty) ;
162+ let value = self . has_sig_drop_attr_uncached ( ty, depth + 1 ) ;
160163 self . type_cache . insert ( ty, value) ;
161164 value
162165 }
163166
164- fn has_sig_drop_attr_uncached ( & mut self , ty : Ty < ' tcx > ) -> bool {
167+ fn has_sig_drop_attr_uncached ( & mut self , ty : Ty < ' tcx > , depth : usize ) -> bool {
168+ if !self . cx . tcx . recursion_limit ( ) . value_within_limit ( depth) {
169+ return false ;
170+ }
165171 if let Some ( adt) = ty. ty_adt_def ( ) {
166172 let mut iter = get_attr (
167173 self . cx . sess ( ) ,
@@ -176,13 +182,13 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
176182 rustc_middle:: ty:: Adt ( a, b) => {
177183 for f in a. all_fields ( ) {
178184 let ty = f. ty ( self . cx . tcx , b) ;
179- if self . has_sig_drop_attr ( ty) {
185+ if self . has_sig_drop_attr ( ty, depth ) {
180186 return true ;
181187 }
182188 }
183189 for generic_arg in * b {
184190 if let GenericArgKind :: Type ( ty) = generic_arg. unpack ( )
185- && self . has_sig_drop_attr ( ty)
191+ && self . has_sig_drop_attr ( ty, depth )
186192 {
187193 return true ;
188194 }
@@ -192,7 +198,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
192198 rustc_middle:: ty:: Array ( ty, _)
193199 | rustc_middle:: ty:: RawPtr ( ty, _)
194200 | rustc_middle:: ty:: Ref ( _, ty, _)
195- | rustc_middle:: ty:: Slice ( ty) => self . has_sig_drop_attr ( * ty) ,
201+ | rustc_middle:: ty:: Slice ( ty) => self . has_sig_drop_attr ( * ty, depth ) ,
196202 _ => false ,
197203 }
198204 }
@@ -268,7 +274,7 @@ impl<'tcx> Visitor<'tcx> for StmtsChecker<'_, '_, '_, '_, 'tcx> {
268274 apa. has_expensive_expr_after_last_attr = false ;
269275 } ;
270276 let mut ac = AttrChecker :: new ( self . cx , self . type_cache ) ;
271- if ac. has_sig_drop_attr ( self . cx . typeck_results ( ) . expr_ty ( expr) ) {
277+ if ac. has_sig_drop_attr ( self . cx . typeck_results ( ) . expr_ty ( expr) , 0 ) {
272278 if let hir:: StmtKind :: Let ( local) = self . ap . curr_stmt . kind
273279 && let hir:: PatKind :: Binding ( _, hir_id, ident, _) = local. pat . kind
274280 && !self . ap . apas . contains_key ( & hir_id)
0 commit comments