Skip to content

Replace parent substs of associated types with inference vars in borrow checker #85755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ struct UniversalRegionRelationsBuilder<'this, 'tcx> {

impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
crate fn create(mut self) -> CreateResult<'tcx> {
let tcx = self.infcx.tcx;
let unnormalized_input_output_tys = self
.universal_regions
.unnormalized_input_tys
Expand Down Expand Up @@ -266,6 +267,9 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
.delay_span_bug(DUMMY_SP, &format!("failed to normalize {:?}", ty));
(self.infcx.tcx.ty_error(), None)
});
// We need to replace bound regions in the substs of associated types (parent substs, not GATs)
// with inference vars, see issue #78450
let ty = self.universal_regions.indices.fold_to_region_vids(tcx, ty);
let constraints2 = self.add_implied_bounds(ty);
normalized_inputs_and_output.push(ty);
constraints1.into_iter().chain(constraints2)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir/src/borrow_check/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::borrow_check::nll::ToRegionVid;

#[derive(Debug)]
pub struct UniversalRegions<'tcx> {
indices: UniversalRegionIndices<'tcx>,
pub(crate) indices: UniversalRegionIndices<'tcx>,

/// The vid assigned to `'static`
pub fr_static: RegionVid,
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'tcx> DefiningTy<'tcx> {
}

#[derive(Debug)]
struct UniversalRegionIndices<'tcx> {
pub(crate) struct UniversalRegionIndices<'tcx> {
/// For those regions that may appear in the parameter environment
/// ('static and early-bound regions), we maintain a map from the
/// `ty::Region` to the internal `RegionVid` we are using. This is
Expand Down
33 changes: 0 additions & 33 deletions src/test/ui/type-alias-impl-trait/associated-type-lifetime-ice.rs

This file was deleted.

This file was deleted.

27 changes: 27 additions & 0 deletions src/test/ui/type-alias-impl-trait/issue-78450.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// check-pass

#![feature(min_type_alias_impl_trait)]
#![feature(type_alias_impl_trait)]
//~^ WARNING: the feature `type_alias_impl_trait` is incomplete

pub trait AssociatedImpl {
type ImplTrait;

fn f() -> Self::ImplTrait;
}

struct S<T>(T);

trait Associated {
type A;
}

impl<'a, T: Associated<A = &'a ()>> AssociatedImpl for S<T> {
type ImplTrait = impl core::fmt::Debug;

fn f() -> Self::ImplTrait {
()
}
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/type-alias-impl-trait/issue-78450.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `type_alias_impl_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/issue-78450.rs:4:12
|
LL | #![feature(type_alias_impl_trait)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information

warning: 1 warning emitted