@@ -732,8 +732,6 @@ fn check_opaque_meets_bounds<'tcx>(
732
732
span : Span ,
733
733
origin : & hir:: OpaqueTyOrigin ,
734
734
) {
735
- let hidden_type = tcx. bound_type_of ( def_id. to_def_id ( ) ) . subst ( tcx, substs) ;
736
-
737
735
let hir_id = tcx. hir ( ) . local_def_id_to_hir_id ( def_id) ;
738
736
let defining_use_anchor = match * origin {
739
737
hir:: OpaqueTyOrigin :: FnReturn ( did) | hir:: OpaqueTyOrigin :: AsyncFn ( did) => did,
@@ -748,14 +746,26 @@ fn check_opaque_meets_bounds<'tcx>(
748
746
let ocx = ObligationCtxt :: new ( & infcx) ;
749
747
let opaque_ty = tcx. mk_opaque ( def_id. to_def_id ( ) , substs) ;
750
748
749
+ // `ReErased` regions appear in the "parent_substs" of closures/generators.
750
+ // We're ignoring them here and replacing them with fresh region variables.
751
+ // See tests in ui/type-alias-impl-trait/closure_{parent_substs,wf_outlives}.rs.
752
+ //
753
+ // FIXME: Consider wrapping the hidden type in an existential `Binder` and instantiating it
754
+ // here rather than using ReErased.
755
+ let hidden_ty = tcx. bound_type_of ( def_id. to_def_id ( ) ) . subst ( tcx, substs) ;
756
+ let hidden_ty = tcx. fold_regions ( hidden_ty, |re, _dbi| match re. kind ( ) {
757
+ ty:: ReErased => infcx. next_region_var ( RegionVariableOrigin :: MiscVariable ( span) ) ,
758
+ _ => re,
759
+ } ) ;
760
+
751
761
let misc_cause = traits:: ObligationCause :: misc ( span, hir_id) ;
752
762
753
- match infcx. at ( & misc_cause, param_env) . eq ( opaque_ty, hidden_type ) {
763
+ match infcx. at ( & misc_cause, param_env) . eq ( opaque_ty, hidden_ty ) {
754
764
Ok ( infer_ok) => ocx. register_infer_ok_obligations ( infer_ok) ,
755
765
Err ( ty_err) => {
756
766
tcx. sess . delay_span_bug (
757
767
span,
758
- & format ! ( "could not unify `{hidden_type }` with revealed type:\n {ty_err}" ) ,
768
+ & format ! ( "could not unify `{hidden_ty }` with revealed type:\n {ty_err}" ) ,
759
769
) ;
760
770
}
761
771
}
@@ -764,7 +774,7 @@ fn check_opaque_meets_bounds<'tcx>(
764
774
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
765
775
// hidden type is well formed even without those bounds.
766
776
let predicate =
767
- ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( hidden_type . into ( ) ) ) . to_predicate ( tcx) ;
777
+ ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( hidden_ty . into ( ) ) ) . to_predicate ( tcx) ;
768
778
ocx. register_obligation ( Obligation :: new ( misc_cause, param_env, predicate) ) ;
769
779
770
780
// Check that all obligations are satisfied by the implementation's
0 commit comments