@@ -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,12 @@ 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 {
165168 if let Some ( adt) = ty. ty_adt_def ( ) {
166169 let mut iter = get_attr (
167170 self . cx . sess ( ) ,
@@ -176,13 +179,13 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
176179 rustc_middle:: ty:: Adt ( a, b) => {
177180 for f in a. all_fields ( ) {
178181 let ty = f. ty ( self . cx . tcx , b) ;
179- if self . has_sig_drop_attr ( ty) {
182+ if self . has_sig_drop_attr ( ty, depth ) {
180183 return true ;
181184 }
182185 }
183186 for generic_arg in * b {
184187 if let GenericArgKind :: Type ( ty) = generic_arg. unpack ( )
185- && self . has_sig_drop_attr ( ty)
188+ && self . has_sig_drop_attr ( ty, depth )
186189 {
187190 return true ;
188191 }
@@ -192,7 +195,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> {
192195 rustc_middle:: ty:: Array ( ty, _)
193196 | rustc_middle:: ty:: RawPtr ( ty, _)
194197 | rustc_middle:: ty:: Ref ( _, ty, _)
195- | rustc_middle:: ty:: Slice ( ty) => self . has_sig_drop_attr ( * ty) ,
198+ | rustc_middle:: ty:: Slice ( ty) => self . has_sig_drop_attr ( * ty, depth ) ,
196199 _ => false ,
197200 }
198201 }
@@ -268,7 +271,7 @@ impl<'tcx> Visitor<'tcx> for StmtsChecker<'_, '_, '_, '_, 'tcx> {
268271 apa. has_expensive_expr_after_last_attr = false ;
269272 } ;
270273 let mut ac = AttrChecker :: new ( self . cx , self . type_cache ) ;
271- if ac. has_sig_drop_attr ( self . cx . typeck_results ( ) . expr_ty ( expr) ) {
274+ if ac. has_sig_drop_attr ( self . cx . typeck_results ( ) . expr_ty ( expr) , 0 ) {
272275 if let hir:: StmtKind :: Let ( local) = self . ap . curr_stmt . kind
273276 && let hir:: PatKind :: Binding ( _, hir_id, ident, _) = local. pat . kind
274277 && !self . ap . apas . contains_key ( & hir_id)
0 commit comments