@@ -13,8 +13,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
1313 /// For example consider `fn f<'a>(x: &'a i32) -> impl Sized + 'a { x }`.
1414 /// This is lowered to give HIR something like
1515 ///
16- /// type _Return<'_a> = impl Sized + '_a;
17- /// fn f<'a>(x: &'a i32) -> _Return<'a> { x }
16+ /// type f<'a>:: _Return<'_a> = impl Sized + '_a;
17+ /// fn f<'a>(x: &'a i32) -> f<'static>:: _Return<'a> { x }
1818 ///
1919 /// When checking the return type record the type from the return and the
2020 /// type used in the return value. In this case they might be `_Return<'1>`
@@ -34,9 +34,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
3434 /// `fn f<'a: 'b, 'b: 'a>(x: *mut &'b i32) -> impl Sized + 'a { x }`
3535 ///
3636 /// Then we map the regions in both the type and the subst to their
37- /// `external_name` giving `concrete_type = &'a i32, substs = ['a]`. This
38- /// will then allow `infer_opaque_definition_from_instantiation` to
39- /// determine that `_Return<'_a> = &'_a i32`.
37+ /// `external_name` giving `concrete_type = &'a i32`,
38+ /// `substs = ['static, 'a]`. This will then allow
39+ /// `infer_opaque_definition_from_instantiation` to determine that
40+ /// `_Return<'_a> = &'_a i32`.
4041 ///
4142 /// There's a slight complication around closures. Given
4243 /// `fn f<'a: 'a>() { || {} }` the closure's type is something like
@@ -72,6 +73,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7273 infcx. tcx . lifetimes . re_static
7374 } )
7475 }
76+ // We don't fold regions in the predicates of opaque
77+ // types to `ReVar`s. This means that in a case like
78+ //
79+ // fn f<'a: 'a>() -> impl Iterator<Item = impl Sized>
80+ //
81+ // The inner opaque type has `'static` in its substs.
82+ ty:: ReStatic => region,
7583 _ => {
7684 infcx. tcx . sess . delay_span_bug (
7785 span,
0 commit comments