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

Dont ICE on an attempt to use GAT without feature gate #61118

Merged
merged 3 commits into from
May 25, 2019
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
15 changes: 9 additions & 6 deletions src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,12 +658,15 @@ impl<'tcx> ScopeTree {
// The lifetime was defined on node that doesn't own a body,
// which in practice can only mean a trait or an impl, that
// is the parent of a method, and that is enforced below.
assert_eq!(Some(param_owner_id), self.root_parent,
"free_scope: {:?} not recognized by the \
region scope tree for {:?} / {:?}",
param_owner,
self.root_parent.map(|id| tcx.hir().local_def_id_from_hir_id(id)),
self.root_body.map(|hir_id| DefId::local(hir_id.owner)));
if Some(param_owner_id) != self.root_parent {
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!("free_scope: {:?} not recognized by the \
region scope tree for {:?} / {:?}",
param_owner,
self.root_parent.map(|id| tcx.hir().local_def_id_from_hir_id(id)),
self.root_body.map(|hir_id| DefId::local(hir_id.owner))));
}

// The trait/impl lifetime is in scope for the method's body.
self.root_body.unwrap().local_id
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/ty/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,21 +479,22 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> {
// the specialized routine `ty::replace_late_regions()`.
match *r {
ty::ReEarlyBound(data) => {
let r = self.substs.get(data.index as usize).map(|k| k.unpack());
match r {
let rk = self.substs.get(data.index as usize).map(|k| k.unpack());
match rk {
Some(UnpackedKind::Lifetime(lt)) => {
self.shift_region_through_binders(lt)
}
_ => {
let span = self.span.unwrap_or(DUMMY_SP);
span_bug!(
span,
let msg = format!(
"Region parameter out of range \
when substituting in region {} (root type={:?}) \
(index={})",
data.name,
self.root_ty,
data.index);
self.tcx.sess.delay_span_bug(span, &msg);
r
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// rust-lang/rust#60654: Do not ICE on an attempt to use GATs that is
// missing the feature gate.

struct Foo;

impl Iterator for Foo {
type Item<'b> = &'b Foo; //~ ERROR generic associated types are unstable [E0658]

fn next(&mut self) -> Option<Self::Item> {
None
}
}

fn main() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0658]: generic associated types are unstable
--> $DIR/gat-dont-ice-on-absent-feature.rs:7:5
|
LL | type Item<'b> = &'b Foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
= help: add #![feature(generic_associated_types)] to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.