Skip to content

Commit a5cfc40

Browse files
committed
Avoid ICE on ReFree region from malformed code
1 parent f2023ac commit a5cfc40

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/librustc_typeck/outlives/utils.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc::ty::outlives::Component;
22
use rustc::ty::subst::{GenericArg, GenericArgKind};
33
use rustc::ty::{self, Region, RegionKind, Ty, TyCtxt};
4+
use syntax_pos::DUMMY_SP;
45
use smallvec::smallvec;
56
use std::collections::BTreeSet;
67

@@ -161,9 +162,21 @@ fn is_free_region(tcx: TyCtxt<'_>, region: Region<'_>) -> bool {
161162
// ignore it. We can't put it on the struct header anyway.
162163
RegionKind::ReLateBound(..) => false,
163164

165+
// This can appear with malformed code (#64855):
166+
//
167+
// struct Bar<T>(<Self as Foo>::Type) where Self: ;
168+
//
169+
// We accept it only to avoid an ICE.
170+
RegionKind::ReEmpty => {
171+
tcx.sess.delay_span_bug(
172+
DUMMY_SP,
173+
&format!("unexpected region in outlives inference: {:?}", region),
174+
);
175+
false
176+
}
177+
164178
// These regions don't appear in types from type declarations:
165-
RegionKind::ReEmpty
166-
| RegionKind::ReErased
179+
RegionKind::ReErased
167180
| RegionKind::ReClosureBound(..)
168181
| RegionKind::ReScope(..)
169182
| RegionKind::ReVar(..)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub trait Foo {
2+
type Type;
3+
}
4+
5+
pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
6+
//~^ ERROR the trait bound `Bar<T>: Foo` is not satisfied
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied
2+
--> $DIR/issue-64855.rs:5:19
3+
|
4+
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
5+
| ^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar<T>`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)