Skip to content

Commit

Permalink
Avoid ICE on ReFree region from malformed code
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 2, 2019
1 parent f2023ac commit a5cfc40
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/librustc_typeck/outlives/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use rustc::ty::outlives::Component;
use rustc::ty::subst::{GenericArg, GenericArgKind};
use rustc::ty::{self, Region, RegionKind, Ty, TyCtxt};
use syntax_pos::DUMMY_SP;
use smallvec::smallvec;
use std::collections::BTreeSet;

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

// This can appear with malformed code (#64855):
//
// struct Bar<T>(<Self as Foo>::Type) where Self: ;
//
// We accept it only to avoid an ICE.
RegionKind::ReEmpty => {
tcx.sess.delay_span_bug(
DUMMY_SP,
&format!("unexpected region in outlives inference: {:?}", region),
);
false
}

// These regions don't appear in types from type declarations:
RegionKind::ReEmpty
| RegionKind::ReErased
RegionKind::ReErased
| RegionKind::ReClosureBound(..)
| RegionKind::ReScope(..)
| RegionKind::ReVar(..)
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/associated-types/issue-64855.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub trait Foo {
type Type;
}

pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
//~^ ERROR the trait bound `Bar<T>: Foo` is not satisfied

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/associated-types/issue-64855.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied
--> $DIR/issue-64855.rs:5:19
|
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
| ^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar<T>`

error: aborting due to previous error

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

0 comments on commit a5cfc40

Please sign in to comment.