Skip to content
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

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

Merged
merged 2 commits into from
Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
38 changes: 11 additions & 27 deletions compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,33 +60,17 @@ impl<'tcx> RegionInferenceContext<'tcx> {
debug!(?concrete_type, ?substs);

let mut subst_regions = vec![self.universal_regions.fr_static];
let universal_substs =
infcx.tcx.fold_regions(substs, &mut false, |region, _| match *region {
ty::ReVar(vid) => {
subst_regions.push(vid);
self.definitions[vid].external_name.unwrap_or_else(|| {
infcx.tcx.sess.delay_span_bug(
span,
"opaque type with non-universal region substs",
);
infcx.tcx.lifetimes.re_static
})
}
// We don't fold regions in the predicates of opaque
// types to `ReVar`s. This means that in a case like
//
// fn f<'a: 'a>() -> impl Iterator<Item = impl Sized>
//
// The inner opaque type has `'static` in its substs.
ty::ReStatic => region,
_ => {
infcx.tcx.sess.delay_span_bug(
span,
&format!("unexpected concrete region in borrowck: {:?}", region),
);
region
}
});
let universal_substs = infcx.tcx.fold_regions(substs, &mut false, |region, _| {
let vid = self.universal_regions.to_region_vid(region);
subst_regions.push(vid);
self.definitions[vid].external_name.unwrap_or_else(|| {
infcx
.tcx
.sess
.delay_span_bug(span, "opaque type with non-universal region substs");
infcx.tcx.lifetimes.re_static
})
});

subst_regions.sort();
subst_regions.dedup();
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