From a5cfc4011d6981437ea65ec5adc346b114e29a52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Mon, 30 Sep 2019 18:34:48 -0700 Subject: [PATCH 1/2] Avoid ICE on ReFree region from malformed code --- src/librustc_typeck/outlives/utils.rs | 17 +++++++++++++++-- src/test/ui/associated-types/issue-64855.rs | 8 ++++++++ src/test/ui/associated-types/issue-64855.stderr | 9 +++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/associated-types/issue-64855.rs create mode 100644 src/test/ui/associated-types/issue-64855.stderr diff --git a/src/librustc_typeck/outlives/utils.rs b/src/librustc_typeck/outlives/utils.rs index d83c97b522c67..cd92189176eff 100644 --- a/src/librustc_typeck/outlives/utils.rs +++ b/src/librustc_typeck/outlives/utils.rs @@ -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; @@ -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(::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(..) diff --git a/src/test/ui/associated-types/issue-64855.rs b/src/test/ui/associated-types/issue-64855.rs new file mode 100644 index 0000000000000..81cf3ae6e83b6 --- /dev/null +++ b/src/test/ui/associated-types/issue-64855.rs @@ -0,0 +1,8 @@ +pub trait Foo { + type Type; +} + +pub struct Bar(::Type) where Self: ; +//~^ ERROR the trait bound `Bar: Foo` is not satisfied + +fn main() {} diff --git a/src/test/ui/associated-types/issue-64855.stderr b/src/test/ui/associated-types/issue-64855.stderr new file mode 100644 index 0000000000000..6ad795c11176d --- /dev/null +++ b/src/test/ui/associated-types/issue-64855.stderr @@ -0,0 +1,9 @@ +error[E0277]: the trait bound `Bar: Foo` is not satisfied + --> $DIR/issue-64855.rs:5:19 + | +LL | pub struct Bar(::Type) where Self: ; + | ^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From de815653eda51093d31a41ada7041f48d7417866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 2 Oct 2019 15:53:36 -0700 Subject: [PATCH 2/2] review comments --- src/librustc_typeck/outlives/utils.rs | 14 +++----------- src/test/ui/associated-types/issue-64855-2.rs | 5 +++++ 2 files changed, 8 insertions(+), 11 deletions(-) create mode 100644 src/test/ui/associated-types/issue-64855-2.rs diff --git a/src/librustc_typeck/outlives/utils.rs b/src/librustc_typeck/outlives/utils.rs index cd92189176eff..d34605dc482a3 100644 --- a/src/librustc_typeck/outlives/utils.rs +++ b/src/librustc_typeck/outlives/utils.rs @@ -1,7 +1,6 @@ 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; @@ -162,18 +161,11 @@ 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): + // This can appear in `where Self: ` bounds (#64855): // // struct Bar(::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 - } + // struct Baz<'a>(&'a Self) where Self: ; + RegionKind::ReEmpty => false, // These regions don't appear in types from type declarations: RegionKind::ReErased diff --git a/src/test/ui/associated-types/issue-64855-2.rs b/src/test/ui/associated-types/issue-64855-2.rs new file mode 100644 index 0000000000000..1d53bd5703165 --- /dev/null +++ b/src/test/ui/associated-types/issue-64855-2.rs @@ -0,0 +1,5 @@ +// check-pass + +pub struct Bar<'a>(&'a Self) where Self: ; + +fn main() {}