Skip to content

Commit

Permalink
replace parent substs of associated types with inference vars in borr…
Browse files Browse the repository at this point in the history
…ow check
  • Loading branch information
b-naber committed May 27, 2021
1 parent 8d1e3d3 commit f30ee65
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 48 deletions.
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
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
@@ -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
@@ -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

0 comments on commit f30ee65

Please sign in to comment.