Skip to content

Commit 0ef2b4a

Browse files
committedJun 17, 2021
Auto merge of #85755 - b-naber:unexpected_concrete_region, r=nikomatsakis
Replace parent substs of associated types with inference vars in borrow checker Fixes #83190 Fixes #78450 When we normalize an associated type that refers to an opaque type, it can happen that the substs of the associated type do not occur in the projection (they are parent substs). We previously didn't replace those substs with inference vars, which left a concrete region after all regions should have already been replaced with inference vars and triggered a `delay_span_bug`. After we normalize the opaque type, we now try to replace any remaining concrete regions with inference vars.
2 parents b17d9c1 + 09eed28 commit 0ef2b4a

File tree

5 files changed

+49
-73
lines changed

5 files changed

+49
-73
lines changed
 

‎compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs

+11-27
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6060
debug!(?concrete_type, ?substs);
6161

6262
let mut subst_regions = vec![self.universal_regions.fr_static];
63-
let universal_substs =
64-
infcx.tcx.fold_regions(substs, &mut false, |region, _| match *region {
65-
ty::ReVar(vid) => {
66-
subst_regions.push(vid);
67-
self.definitions[vid].external_name.unwrap_or_else(|| {
68-
infcx.tcx.sess.delay_span_bug(
69-
span,
70-
"opaque type with non-universal region substs",
71-
);
72-
infcx.tcx.lifetimes.re_static
73-
})
74-
}
75-
// We don't fold regions in the predicates of opaque
76-
// types to `ReVar`s. This means that in a case like
77-
//
78-
// fn f<'a: 'a>() -> impl Iterator<Item = impl Sized>
79-
//
80-
// The inner opaque type has `'static` in its substs.
81-
ty::ReStatic => region,
82-
_ => {
83-
infcx.tcx.sess.delay_span_bug(
84-
span,
85-
&format!("unexpected concrete region in borrowck: {:?}", region),
86-
);
87-
region
88-
}
89-
});
63+
let universal_substs = infcx.tcx.fold_regions(substs, &mut false, |region, _| {
64+
let vid = self.universal_regions.to_region_vid(region);
65+
subst_regions.push(vid);
66+
self.definitions[vid].external_name.unwrap_or_else(|| {
67+
infcx
68+
.tcx
69+
.sess
70+
.delay_span_bug(span, "opaque type with non-universal region substs");
71+
infcx.tcx.lifetimes.re_static
72+
})
73+
});
9074

9175
subst_regions.sort();
9276
subst_regions.dedup();

‎src/test/ui/type-alias-impl-trait/associated-type-lifetime-ice.rs

-33
This file was deleted.

‎src/test/ui/type-alias-impl-trait/associated-type-lifetime-ice.stderr

-13
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// check-pass
2+
3+
#![feature(min_type_alias_impl_trait)]
4+
#![feature(type_alias_impl_trait)]
5+
//~^ WARNING: the feature `type_alias_impl_trait` is incomplete
6+
7+
pub trait AssociatedImpl {
8+
type ImplTrait;
9+
10+
fn f() -> Self::ImplTrait;
11+
}
12+
13+
struct S<T>(T);
14+
15+
trait Associated {
16+
type A;
17+
}
18+
19+
impl<'a, T: Associated<A = &'a ()>> AssociatedImpl for S<T> {
20+
type ImplTrait = impl core::fmt::Debug;
21+
22+
fn f() -> Self::ImplTrait {
23+
()
24+
}
25+
}
26+
27+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/issue-78450.rs:4:12
3+
|
4+
LL | #![feature(type_alias_impl_trait)]
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)
Please sign in to comment.