Skip to content

Commit 35ccfc1

Browse files
authored
Rollup merge of rust-lang#61118 - pnkfelix:issue-60654-dont-ice-on-gat, r=varkor
Dont ICE on an attempt to use GAT without feature gate Fix rust-lang#60654
2 parents 9262748 + c235ba4 commit 35ccfc1

File tree

4 files changed

+40
-10
lines changed

4 files changed

+40
-10
lines changed

src/librustc/middle/region.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -658,12 +658,15 @@ impl<'tcx> ScopeTree {
658658
// The lifetime was defined on node that doesn't own a body,
659659
// which in practice can only mean a trait or an impl, that
660660
// is the parent of a method, and that is enforced below.
661-
assert_eq!(Some(param_owner_id), self.root_parent,
662-
"free_scope: {:?} not recognized by the \
663-
region scope tree for {:?} / {:?}",
664-
param_owner,
665-
self.root_parent.map(|id| tcx.hir().local_def_id_from_hir_id(id)),
666-
self.root_body.map(|hir_id| DefId::local(hir_id.owner)));
661+
if Some(param_owner_id) != self.root_parent {
662+
tcx.sess.delay_span_bug(
663+
DUMMY_SP,
664+
&format!("free_scope: {:?} not recognized by the \
665+
region scope tree for {:?} / {:?}",
666+
param_owner,
667+
self.root_parent.map(|id| tcx.hir().local_def_id_from_hir_id(id)),
668+
self.root_body.map(|hir_id| DefId::local(hir_id.owner))));
669+
}
667670

668671
// The trait/impl lifetime is in scope for the method's body.
669672
self.root_body.unwrap().local_id

src/librustc/ty/subst.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -479,21 +479,22 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> {
479479
// the specialized routine `ty::replace_late_regions()`.
480480
match *r {
481481
ty::ReEarlyBound(data) => {
482-
let r = self.substs.get(data.index as usize).map(|k| k.unpack());
483-
match r {
482+
let rk = self.substs.get(data.index as usize).map(|k| k.unpack());
483+
match rk {
484484
Some(UnpackedKind::Lifetime(lt)) => {
485485
self.shift_region_through_binders(lt)
486486
}
487487
_ => {
488488
let span = self.span.unwrap_or(DUMMY_SP);
489-
span_bug!(
490-
span,
489+
let msg = format!(
491490
"Region parameter out of range \
492491
when substituting in region {} (root type={:?}) \
493492
(index={})",
494493
data.name,
495494
self.root_ty,
496495
data.index);
496+
self.tcx.sess.delay_span_bug(span, &msg);
497+
r
497498
}
498499
}
499500
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// rust-lang/rust#60654: Do not ICE on an attempt to use GATs that is
2+
// missing the feature gate.
3+
4+
struct Foo;
5+
6+
impl Iterator for Foo {
7+
type Item<'b> = &'b Foo; //~ ERROR generic associated types are unstable [E0658]
8+
9+
fn next(&mut self) -> Option<Self::Item> {
10+
None
11+
}
12+
}
13+
14+
fn main() { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: generic associated types are unstable
2+
--> $DIR/gat-dont-ice-on-absent-feature.rs:7:5
3+
|
4+
LL | type Item<'b> = &'b Foo;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: for more information, see https://github.com/rust-lang/rust/issues/44265
8+
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)