]> git.lizzy.rs Git - rust.git/commitdiff
Turn the use of erroneous constants into errors again
authorOliver Schneider <github35764891676564198441@oli-obk.de>
Wed, 27 Jun 2018 12:55:06 +0000 (14:55 +0200)
committerOliver Schneider <github35764891676564198441@oli-obk.de>
Thu, 28 Jun 2018 09:04:26 +0000 (11:04 +0200)
13 files changed:
src/librustc/mir/interpret/error.rs
src/librustc_mir/transform/const_prop.rs
src/test/compile-fail/const-err.rs
src/test/ui/const-eval/conditional_array_execution.nll.stderr
src/test/ui/const-eval/conditional_array_execution.stderr
src/test/ui/const-eval/issue-43197.nll.stderr
src/test/ui/const-eval/issue-43197.stderr
src/test/ui/const-eval/issue-44578.nll.stderr
src/test/ui/const-eval/issue-44578.stderr
src/test/ui/const-eval/issue-50814-2.stderr
src/test/ui/const-eval/issue-50814.stderr
src/test/ui/const-len-underflow-separate-spans.rs
src/test/ui/const-len-underflow-separate-spans.stderr

index 3291d6bf1521f43b6a81bde9701be78a022effb4..86427bb2382cb5bc7004ec8bd01b10818e289f81 100644 (file)
@@ -80,7 +80,7 @@ fn struct_generic(
             ::mir::interpret::EvalErrorKind::CheckMatchError |
             ::mir::interpret::EvalErrorKind::Layout(_) => return None,
             ::mir::interpret::EvalErrorKind::ReferencedConstant(ref inner) => {
-                inner.struct_generic(tcx, "referenced constant", lint_root)?.emit();
+                inner.struct_generic(tcx, "referenced constant has errors", lint_root)?.emit();
             },
             _ => {},
         }
index 95bac24a77bd5413f31dd4c861e03004219148a2..3b3c28f6ae2655c2dbd9df61e247ad1be3e33b81 100644 (file)
@@ -170,10 +170,23 @@ fn eval_constant(
     ) -> Option<Const<'tcx>> {
         match c.literal {
             Literal::Value { value } => {
-                let v = self.use_ecx(source_info, |this| {
-                    this.ecx.const_to_value(value.val)
-                })?;
-                Some((v, value.ty, c.span))
+                self.ecx.tcx.span = source_info.span;
+                match self.ecx.const_to_value(value.val) {
+                    Ok(val) => Some((val, value.ty, c.span)),
+                    Err(error) => {
+                        let (stacktrace, span) = self.ecx.generate_stacktrace(None);
+                        let err = ConstEvalErr {
+                            span,
+                            error,
+                            stacktrace,
+                        };
+                        err.report_as_error(
+                            self.tcx.at(source_info.span),
+                            "could not evaluate constant",
+                        );
+                        None
+                    },
+                }
             },
             // evaluate the promoted and replace the constant with the evaluated result
             Literal::Promoted { index } => {
index f6a64bcba21c3a6b15f0ce0eeafa3dacc49350d0..8683f6a0231921c0e89d84a9dc36fe68edfc6e58 100644 (file)
@@ -27,4 +27,6 @@ fn black_box<T>(_: T) {
 
 fn main() {
     black_box((FOO, FOO));
+    //~^ ERROR referenced constant has errors
+    //~| ERROR could not evaluate constant
 }
index 7be9202a2f5654ce4a0f88486065f99ca608d152..8bc302a2befa4fca221547969703380a6e194c38 100644 (file)
@@ -12,7 +12,7 @@ note: lint level defined here
 LL | #![warn(const_err)]
    |         ^^^^^^^^^
 
-warning: referenced constant
+warning: referenced constant has errors
   --> $DIR/conditional_array_execution.rs:19:20
    |
 LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
@@ -27,7 +27,7 @@ warning: this expression will panic at runtime
 LL |     println!("{}", FOO);
    |                    ^^^ referenced constant has errors
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/conditional_array_execution.rs:19:5
    |
 LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
@@ -48,7 +48,7 @@ LL |     println!("{}", FOO);
    |
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/conditional_array_execution.rs:19:20
    |
 LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
index 8a1b75721798f90394b2f83502bacb3be1ccb3fe..649da03a5e7fae60d713e0f1eb96805432233e56 100644 (file)
@@ -12,7 +12,7 @@ note: lint level defined here
 LL | #![warn(const_err)]
    |         ^^^^^^^^^
 
-warning: referenced constant
+warning: referenced constant has errors
   --> $DIR/conditional_array_execution.rs:19:20
    |
 LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
@@ -27,7 +27,7 @@ warning: this expression will panic at runtime
 LL |     println!("{}", FOO);
    |                    ^^^ referenced constant has errors
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/conditional_array_execution.rs:19:20
    |
 LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
index 6437369214b3fdfd87f75b47b8ea69243f093ffc..5819e6a9254a759bcb63a8c2d0cdf89740824b02 100644 (file)
@@ -20,7 +20,7 @@ LL |     const Y: u32 = foo(0-1);
    |                        |
    |                        attempt to subtract with overflow
 
-warning: referenced constant
+warning: referenced constant has errors
   --> $DIR/issue-43197.rs:24:23
    |
 LL |     const X: u32 = 0-1;
@@ -35,7 +35,7 @@ warning: this expression will panic at runtime
 LL |     println!("{} {}", X, Y);
    |                       ^ referenced constant has errors
 
-warning: referenced constant
+warning: referenced constant has errors
   --> $DIR/issue-43197.rs:24:26
    |
 LL |     const Y: u32 = foo(0-1);
@@ -50,7 +50,7 @@ warning: this expression will panic at runtime
 LL |     println!("{} {}", X, Y);
    |                          ^ referenced constant has errors
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-43197.rs:24:5
    |
 LL |     const X: u32 = 0-1;
@@ -71,7 +71,7 @@ LL |     println!("{} {}", X, Y);
    |
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-43197.rs:24:26
    |
 LL |     const Y: u32 = foo(0-1);
@@ -86,7 +86,7 @@ error[E0080]: erroneous constant used
 LL |     println!("{} {}", X, Y);
    |                          ^ referenced constant has errors
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-43197.rs:24:23
    |
 LL |     const X: u32 = 0-1;
index 3cb8b345c673ce51c808982bd3be869c38fb55dc..bf864d81ea3ca179f34825c5b01ab59f13daf2de 100644 (file)
@@ -20,7 +20,7 @@ LL |     const Y: u32 = foo(0-1);
    |                        |
    |                        attempt to subtract with overflow
 
-warning: referenced constant
+warning: referenced constant has errors
   --> $DIR/issue-43197.rs:24:23
    |
 LL |     const X: u32 = 0-1;
@@ -35,7 +35,7 @@ warning: this expression will panic at runtime
 LL |     println!("{} {}", X, Y);
    |                       ^ referenced constant has errors
 
-warning: referenced constant
+warning: referenced constant has errors
   --> $DIR/issue-43197.rs:24:26
    |
 LL |     const Y: u32 = foo(0-1);
@@ -50,7 +50,7 @@ warning: this expression will panic at runtime
 LL |     println!("{} {}", X, Y);
    |                          ^ referenced constant has errors
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-43197.rs:24:26
    |
 LL |     const Y: u32 = foo(0-1);
@@ -65,7 +65,7 @@ error[E0080]: erroneous constant used
 LL |     println!("{} {}", X, Y);
    |                          ^ referenced constant has errors
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-43197.rs:24:23
    |
 LL |     const X: u32 = 0-1;
index ad4f08966c01220560ac2b8cbdcac60a82d9436f..eeb152e00ea477d2c5d5ea7095acfe69648e824a 100644 (file)
@@ -1,4 +1,4 @@
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-44578.rs:35:5
    |
 LL |     const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize];
@@ -19,7 +19,7 @@ LL |     println!("{}", <Bar<u16, u8> as Foo>::AMT);
    |
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
 
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-44578.rs:35:20
    |
 LL |     const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize];
index 28a723a069edf5eda39331c0c3c14158d6198571..06174f37dcad1145896f92a9d2fa78e3e68a5c7f 100644 (file)
@@ -1,4 +1,4 @@
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-44578.rs:35:20
    |
 LL |     const AMT: usize = [A::AMT][(A::AMT > B::AMT) as usize];
index 3c59cb0e2bc727c03145f5f639a2755fc189f7fd..1e37e9498120fb64da6ba57d8feb4f03c1381103 100644 (file)
@@ -1,4 +1,4 @@
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-50814-2.rs:26:5
    |
 LL |     const BAR: usize = [5, 6, 7][T::BOO];
index 145279ccc033d71d77f70f9513d9ca8eb0a57b5f..16160207c573ba20d39f923db33cf0d30d687d6d 100644 (file)
@@ -1,4 +1,4 @@
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/issue-50814.rs:27:5
    |
 LL |     const MAX: u8 = A::MAX + B::MAX;
index 242561da9d54cb1eb720d1101a71eb81e631ab26..8db1411005e5772daa8548a395adc18fd16205f2 100644 (file)
@@ -20,7 +20,6 @@ fn main() {
     let a: [i8; LEN] = unimplemented!();
 //~^ ERROR E0080
 //~| ERROR E0080
-//~| ERROR const_err
-//~| ERROR const_err
-//~| ERROR const_err
+//~| ERROR E0080
+//~| ERROR E0080
 }
index a941b0c703fe87e8a5af92f265e386bac19f9786..cf97a0dc5557866a674705f84fffc56b41ce1dac 100644 (file)
@@ -1,4 +1,4 @@
-error: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/const-len-underflow-separate-spans.rs:20:17
    |
 LL | const LEN: usize = ONE - TWO;
@@ -6,25 +6,14 @@ LL | const LEN: usize = ONE - TWO;
 ...
 LL |     let a: [i8; LEN] = unimplemented!();
    |                 ^^^
-   |
-   = note: #[deny(const_err)] on by default
 
-error: this expression will panic at runtime
+error[E0080]: could not evaluate constant
   --> $DIR/const-len-underflow-separate-spans.rs:20:17
    |
 LL |     let a: [i8; LEN] = unimplemented!();
    |                 ^^^ referenced constant has errors
 
-error: referenced constant
-  --> $DIR/const-len-underflow-separate-spans.rs:20:17
-   |
-LL | const LEN: usize = ONE - TWO;
-   |                    --------- attempt to subtract with overflow
-...
-LL |     let a: [i8; LEN] = unimplemented!();
-   |                 ^^^
-
-error[E0080]: referenced constant
+error[E0080]: referenced constant has errors
   --> $DIR/const-len-underflow-separate-spans.rs:20:12
    |
 LL | const LEN: usize = ONE - TWO;
@@ -41,6 +30,6 @@ LL |     let a: [i8; LEN] = unimplemented!();
    |                 |
    |                 referenced constant has errors
 
-error: aborting due to 5 previous errors
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0080`.