@@ -121,6 +121,12 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
121121 self . collector . opaques . extend ( items) ;
122122 }
123123 }
124+ #[ instrument( level = "trace" , skip( self ) ) ]
125+ // Recurse into these, as they are type checked with their parent
126+ fn visit_nested_body ( & mut self , id : rustc_hir:: BodyId ) {
127+ let body = self . collector . tcx . hir ( ) . body ( id) ;
128+ self . visit_body ( body) ;
129+ }
124130 }
125131 TaitInBodyFinder { collector : self } . visit_expr ( body) ;
126132 }
@@ -280,11 +286,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
280286 collector. collect_body_and_predicate_taits ( ) ;
281287 }
282288 // Walk over the type of the item to find opaques.
283- DefKind :: Static ( _)
284- | DefKind :: Const
285- | DefKind :: AssocConst
286- | DefKind :: AnonConst
287- | DefKind :: InlineConst => {
289+ DefKind :: Static ( _) | DefKind :: Const | DefKind :: AssocConst | DefKind :: AnonConst => {
288290 let span = match tcx. hir ( ) . get_by_def_id ( item) . ty ( ) {
289291 Some ( ty) => ty. span ,
290292 _ => tcx. def_span ( item) ,
@@ -321,11 +323,9 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [
321323 | DefKind :: LifetimeParam
322324 | DefKind :: GlobalAsm
323325 | DefKind :: Impl { .. } => { }
324- DefKind :: Closure | DefKind :: Generator => {
325- // All items in the signature of the parent are ok
326- collector. opaques . extend ( tcx. opaque_types_defined_by ( tcx. local_parent ( item) ) ) ;
327- // And items in the body of the closure itself
328- collector. collect_taits_declared_in_body ( ) ;
326+ // Closures and generators are type checked with their parent, so there is no difference here.
327+ DefKind :: Closure | DefKind :: Generator | DefKind :: InlineConst => {
328+ return tcx. opaque_types_defined_by ( tcx. local_parent ( item) ) ;
329329 }
330330 }
331331 tcx. arena . alloc_from_iter ( collector. opaques )
0 commit comments