From dc9dfb27a469942398c4e8abeaaade4ab588c5cc Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 7 Jan 2020 23:19:55 +0900 Subject: [PATCH] Revive delay_span_bug to prevent ICE in const_generics --- src/librustc/ty/subst.rs | 3 +- .../impl-const-generic-struct-with-str.rs | 22 ++++++++++++ .../impl-const-generic-struct-with-str.stderr | 34 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/const-generics/impl-const-generic-struct-with-str.rs create mode 100644 src/test/ui/const-generics/impl-const-generic-struct-with-str.stderr diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index a005581283550..39f0fc1529209 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -493,7 +493,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { (index={})", data.name, self.root_ty, data.index ); - span_bug!(span, "{}", msg); + self.tcx.sess.delay_span_bug(span, &msg); + r } } } diff --git a/src/test/ui/const-generics/impl-const-generic-struct-with-str.rs b/src/test/ui/const-generics/impl-const-generic-struct-with-str.rs new file mode 100644 index 0000000000000..48d4c7cde91e4 --- /dev/null +++ b/src/test/ui/const-generics/impl-const-generic-struct-with-str.rs @@ -0,0 +1,22 @@ +// regression test for rust-lang/rust#67883 + +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash + +struct Caca { + s: String +} + +impl Default for Caca { + //~^ ERROR: lifetime of reference outlives + fn default() -> Self { + let a = Self::A; //~ ERROR: no associated item named `A` found + Self { + s: A.to_string() + } + } +} + +fn main() { + println!("Hello, world!"); +} diff --git a/src/test/ui/const-generics/impl-const-generic-struct-with-str.stderr b/src/test/ui/const-generics/impl-const-generic-struct-with-str.stderr new file mode 100644 index 0000000000000..d60e7b0eefd1a --- /dev/null +++ b/src/test/ui/const-generics/impl-const-generic-struct-with-str.stderr @@ -0,0 +1,34 @@ +warning: the feature `const_generics` is incomplete and may cause the compiler to crash + --> $DIR/impl-const-generic-struct-with-str.rs:3:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + +error[E0312]: lifetime of reference outlives lifetime of borrowed content... + --> $DIR/impl-const-generic-struct-with-str.rs:10:38 + | +LL | impl Default for Caca { + | ^ + | + = note: ...the reference is valid for the static lifetime... +note: ...but the borrowed content is only valid for the lifetime `'_` as defined on the impl at 10:15 + --> $DIR/impl-const-generic-struct-with-str.rs:10:15 + | +LL | impl Default for Caca { + | ^ + +error[E0599]: no associated item named `A` found for type `Caca` in the current scope + --> $DIR/impl-const-generic-struct-with-str.rs:13:23 + | +LL | struct Caca { + | ---------------------------------- associated item `A` not found for this +... +LL | let a = Self::A; + | ^ associated item not found in `Caca` + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0312, E0599. +For more information about an error, try `rustc --explain E0312`.