Skip to content

Commit f30ee65

Browse files
committed
replace parent substs of associated types with inference vars in borrow check
1 parent 8d1e3d3 commit f30ee65

File tree

6 files changed

+44
-48
lines changed

6 files changed

+44
-48
lines changed

compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs

+4
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ struct UniversalRegionRelationsBuilder<'this, 'tcx> {
235235

236236
impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
237237
crate fn create(mut self) -> CreateResult<'tcx> {
238+
let tcx = self.infcx.tcx;
238239
let unnormalized_input_output_tys = self
239240
.universal_regions
240241
.unnormalized_input_tys
@@ -266,6 +267,9 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
266267
.delay_span_bug(DUMMY_SP, &format!("failed to normalize {:?}", ty));
267268
(self.infcx.tcx.ty_error(), None)
268269
});
270+
// We need to replace bound regions in the substs of associated types (parent substs, not GATs)
271+
// with inference vars, see issue #78450
272+
let ty = self.universal_regions.indices.fold_to_region_vids(tcx, ty);
269273
let constraints2 = self.add_implied_bounds(ty);
270274
normalized_inputs_and_output.push(ty);
271275
constraints1.into_iter().chain(constraints2)

compiler/rustc_mir/src/borrow_check/universal_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use crate::borrow_check::nll::ToRegionVid;
3030

3131
#[derive(Debug)]
3232
pub struct UniversalRegions<'tcx> {
33-
indices: UniversalRegionIndices<'tcx>,
33+
pub(crate) indices: UniversalRegionIndices<'tcx>,
3434

3535
/// The vid assigned to `'static`
3636
pub fr_static: RegionVid,
@@ -162,7 +162,7 @@ impl<'tcx> DefiningTy<'tcx> {
162162
}
163163

164164
#[derive(Debug)]
165-
struct UniversalRegionIndices<'tcx> {
165+
pub(crate) struct UniversalRegionIndices<'tcx> {
166166
/// For those regions that may appear in the parameter environment
167167
/// ('static and early-bound regions), we maintain a map from the
168168
/// `ty::Region` to the internal `RegionVid` we are using. This is

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)