@@ -441,6 +441,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
441441
442442 for required_region in required_region_bounds {
443443 concrete_ty. visit_with ( & mut ConstrainOpaqueTypeRegionVisitor {
444+ infcx : self ,
444445 op : |r| self . sub_regions ( infer:: CallReturn ( span) , required_region, r) ,
445446 } ) ;
446447 }
@@ -509,6 +510,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
509510 }
510511 }
511512 concrete_ty. visit_with ( & mut ConstrainOpaqueTypeRegionVisitor {
513+ infcx : self ,
512514 op : |r| self . sub_regions ( infer:: CallReturn ( span) , least_region, r) ,
513515 } ) ;
514516 }
@@ -543,6 +545,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
543545 ) ;
544546
545547 concrete_ty. visit_with ( & mut ConstrainOpaqueTypeRegionVisitor {
548+ infcx : self ,
546549 op : |r| {
547550 self . member_constraint (
548551 opaque_type_def_id,
@@ -683,11 +686,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
683686//
684687// We ignore any type parameters because impl trait values are assumed to
685688// capture all the in-scope type parameters.
686- struct ConstrainOpaqueTypeRegionVisitor < OP > {
689+ struct ConstrainOpaqueTypeRegionVisitor < ' cx , ' tcx , OP > {
690+ infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
687691 op : OP ,
688692}
689693
690- impl < ' tcx , OP > TypeVisitor < ' tcx > for ConstrainOpaqueTypeRegionVisitor < OP >
694+ impl < ' cx , ' tcx , OP > TypeVisitor < ' tcx > for ConstrainOpaqueTypeRegionVisitor < ' cx , ' tcx , OP >
691695where
692696 OP : FnMut ( ty:: Region < ' tcx > ) ,
693697{
@@ -717,24 +721,36 @@ where
717721 ty:: Closure ( _, ref substs) => {
718722 // Skip lifetime parameters of the enclosing item(s)
719723
720- for upvar_ty in substs. as_closure ( ) . upvar_tys ( ) {
721- upvar_ty. visit_with ( self ) ;
722- }
724+ let ty = self . infcx . shallow_resolve ( substs. as_closure ( ) . tupled_upvars_ty ( ) ) ;
725+ if let ty:: Infer ( ty:: TyVar ( _) ) = ty. kind ( ) {
726+ // Not yet resolved.
727+ ty. super_visit_with ( self ) ;
728+ } else {
729+ for upvar_ty in substs. as_closure ( ) . upvar_tys ( ) {
730+ upvar_ty. visit_with ( self ) ;
731+ }
723732
724- substs. as_closure ( ) . sig_as_fn_ptr_ty ( ) . visit_with ( self ) ;
733+ substs. as_closure ( ) . sig_as_fn_ptr_ty ( ) . visit_with ( self ) ;
734+ }
725735 }
726736
727737 ty:: Generator ( _, ref substs, _) => {
728738 // Skip lifetime parameters of the enclosing item(s)
729739 // Also skip the witness type, because that has no free regions.
730740
731- for upvar_ty in substs. as_generator ( ) . upvar_tys ( ) {
732- upvar_ty. visit_with ( self ) ;
733- }
741+ let ty = self . infcx . shallow_resolve ( substs. as_generator ( ) . tupled_upvars_ty ( ) ) ;
742+ if let ty:: Infer ( ty:: TyVar ( _) ) = ty. kind ( ) {
743+ // Not yet resolved.
744+ ty. super_visit_with ( self ) ;
745+ } else {
746+ for upvar_ty in substs. as_generator ( ) . upvar_tys ( ) {
747+ upvar_ty. visit_with ( self ) ;
748+ }
734749
735- substs. as_generator ( ) . return_ty ( ) . visit_with ( self ) ;
736- substs. as_generator ( ) . yield_ty ( ) . visit_with ( self ) ;
737- substs. as_generator ( ) . resume_ty ( ) . visit_with ( self ) ;
750+ substs. as_generator ( ) . return_ty ( ) . visit_with ( self ) ;
751+ substs. as_generator ( ) . yield_ty ( ) . visit_with ( self ) ;
752+ substs. as_generator ( ) . resume_ty ( ) . visit_with ( self ) ;
753+ }
738754 }
739755 _ => {
740756 ty. super_visit_with ( self ) ;
0 commit comments