]> git.lizzy.rs Git - rust.git/commitdiff
fix const_prop spans and re-bless tests
authorRalf Jung <post@ralfj.de>
Mon, 1 Jun 2020 09:17:38 +0000 (11:17 +0200)
committerRalf Jung <post@ralfj.de>
Fri, 12 Jun 2020 07:43:55 +0000 (09:43 +0200)
14 files changed:
src/librustc_mir/const_eval/error.rs
src/librustc_mir/const_eval/eval_queries.rs
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/place.rs
src/librustc_mir/transform/const_prop.rs
src/test/ui/consts/const-eval/infinite_loop.stderr
src/test/ui/consts/const_limit/const_eval_limit_reached.stderr
src/test/ui/consts/recursive-zst-static.default.stderr
src/test/ui/consts/recursive-zst-static.unleash.stderr
src/test/ui/consts/uninhabited-const-issue-61744.rs
src/test/ui/consts/uninhabited-const-issue-61744.stderr
src/test/ui/recursion/recursive-static-definition.stderr
src/test/ui/write-to-static-mut-in-static.stderr

index 2aafafd8205d1c9a8ab85fc1e82d871d79bf6eb0..5deae94fe0c8e785086b005f72b626051e1e9d43 100644 (file)
@@ -2,7 +2,7 @@
 use std::fmt;
 
 use rustc_middle::mir::AssertKind;
-use rustc_span::Symbol;
+use rustc_span::{Span, Symbol};
 
 use super::InterpCx;
 use crate::interpret::{ConstEvalErr, InterpErrorInfo, Machine};
@@ -53,8 +53,9 @@ impl Error for ConstEvalErrKind {}
 pub fn error_to_const_error<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>>(
     ecx: &InterpCx<'mir, 'tcx, M>,
     error: InterpErrorInfo<'tcx>,
+    span: Option<Span>,
 ) -> ConstEvalErr<'tcx> {
     error.print_backtrace();
     let stacktrace = ecx.generate_stacktrace();
-    ConstEvalErr { error: error.kind, stacktrace, span: ecx.cur_span() }
+    ConstEvalErr { error: error.kind, stacktrace, span: span.unwrap_or_else(|| ecx.cur_span()) }
 }
index 4101ea77c90808b08a079cff44eb3eece86cc75f..28e77bb57cd0c19905562a92dc444b42d8d71cfc 100644 (file)
@@ -213,7 +213,7 @@ fn validate_and_turn_into_const<'tcx>(
     })();
 
     val.map_err(|error| {
-        let err = error_to_const_error(&ecx, error);
+        let err = error_to_const_error(&ecx, error, None);
         err.struct_error(ecx.tcx_at(), "it is undefined behavior to use this value", |mut diag| {
             diag.note(note_on_undefined_behavior_error());
             diag.emit();
@@ -312,7 +312,7 @@ pub fn const_eval_raw_provider<'tcx>(
     res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, &body))
         .map(|place| RawConst { alloc_id: place.ptr.assert_ptr().alloc_id, ty: place.layout.ty })
         .map_err(|error| {
-            let err = error_to_const_error(&ecx, error);
+            let err = error_to_const_error(&ecx, error, None);
             // errors in statics are always emitted as fatal errors
             if is_static {
                 // Ensure that if the above error was either `TooGeneric` or `Reported`
index 287b43ac50f96614ec20e97f4c53a897fb8189a6..793a67d804cec5b5125065fa25c4ea2758be4b3a 100644 (file)
@@ -268,11 +268,8 @@ fn unsize_into_ptr(
             (&ty::Array(_, length), &ty::Slice(_)) => {
                 let ptr = self.read_immediate(src)?.to_scalar()?;
                 // u64 cast is from usize to u64, which is always good
-                let val = Immediate::new_slice(
-                    ptr,
-                    length.eval_usize(self.tcx, self.param_env),
-                    self,
-                );
+                let val =
+                    Immediate::new_slice(ptr, length.eval_usize(self.tcx, self.param_env), self);
                 self.write_immediate(val, dest)
             }
             (&ty::Dynamic(..), &ty::Dynamic(..)) => {
index 1715b6fede9629365fd2e922d28b2e0c4a5aad30..47e791854df4889cbeca5a577361e5fba76572f1 100644 (file)
@@ -314,8 +314,7 @@ pub fn new(
 
     #[inline(always)]
     pub fn cur_span(&self) -> Span {
-        self
-            .stack()
+        self.stack()
             .last()
             .and_then(|f| f.current_source_info())
             .map(|si| si.span)
@@ -419,7 +418,8 @@ pub fn load_mir(
         let did = instance.def_id();
         if let Some(did) = did.as_local() {
             if self.tcx_at().has_typeck_tables(did) {
-                if let Some(error_reported) = self.tcx_at().typeck_tables_of(did).tainted_by_errors {
+                if let Some(error_reported) = self.tcx_at().typeck_tables_of(did).tainted_by_errors
+                {
                     throw_inval!(TypeckError(error_reported))
                 }
             }
index 0b4e92574a0665ad5baad98958c3a9d7abc57763..2477100eb8ad87e2f840128ee464304795836b3a 100644 (file)
@@ -404,7 +404,10 @@ pub fn mplace_field(
                     // to get some code to work that probably ought to work.
                     field_layout.align.abi
                 }
-                None => span_bug!(self.cur_span(), "cannot compute offset for extern type field at non-0 offset"),
+                None => span_bug!(
+                    self.cur_span(),
+                    "cannot compute offset for extern type field at non-0 offset"
+                ),
             };
             (base.meta, offset.align_to(align))
         } else {
@@ -440,7 +443,11 @@ pub fn mplace_index(
                 assert!(!field_layout.is_unsized());
                 base.offset(offset, MemPlaceMeta::None, field_layout, self)
             }
-            _ => span_bug!(self.cur_span(), "`mplace_index` called on non-array type {:?}", base.layout.ty),
+            _ => span_bug!(
+                self.cur_span(),
+                "`mplace_index` called on non-array type {:?}",
+                base.layout.ty
+            ),
         }
     }
 
@@ -484,7 +491,9 @@ fn mplace_subslice(
         // (that have count 0 in their layout).
         let from_offset = match base.layout.fields {
             FieldsShape::Array { stride, .. } => stride * from, // `Size` multiplication is checked
-            _ => span_bug!(self.cur_span(), "unexpected layout of index access: {:#?}", base.layout),
+            _ => {
+                span_bug!(self.cur_span(), "unexpected layout of index access: {:#?}", base.layout)
+            }
         };
 
         // Compute meta and new layout
@@ -497,7 +506,9 @@ fn mplace_subslice(
                 let len = Scalar::from_machine_usize(inner_len, self);
                 (MemPlaceMeta::Meta(len), base.layout.ty)
             }
-            _ => span_bug!(self.cur_span(), "cannot subslice non-array type: `{:?}`", base.layout.ty),
+            _ => {
+                span_bug!(self.cur_span(), "cannot subslice non-array type: `{:?}`", base.layout.ty)
+            }
         };
         let layout = self.layout_of(ty)?;
         base.offset(from_offset, meta, layout, self)
@@ -776,9 +787,11 @@ fn write_immediate_to_mplace_no_validate(
             Immediate::Scalar(scalar) => {
                 match dest.layout.abi {
                     Abi::Scalar(_) => {} // fine
-                    _ => {
-                        span_bug!(self.cur_span(), "write_immediate_to_mplace: invalid Scalar layout: {:#?}", dest.layout)
-                    }
+                    _ => span_bug!(
+                        self.cur_span(),
+                        "write_immediate_to_mplace: invalid Scalar layout: {:#?}",
+                        dest.layout
+                    ),
                 }
                 self.memory.get_raw_mut(ptr.alloc_id)?.write_scalar(
                     &tcx,
index 133c05fc2f92bbb7f5baec4a8df89415ae548b31..d50f052d405bc78d8e4ddb1335ab645c995a7433 100644 (file)
@@ -405,7 +405,7 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti
             Ok(op) => Some(op),
             Err(error) => {
                 let tcx = self.ecx.tcx.at(c.span);
-                let err = error_to_const_error(&self.ecx, error);
+                let err = error_to_const_error(&self.ecx, error, Some(c.span));
                 if let Some(lint_root) = self.lint_root(source_info) {
                     let lint_only = match c.literal.val {
                         // Promoteds must lint and not error as the user didn't ask for them
@@ -417,12 +417,7 @@ fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Opti
                     if lint_only {
                         // Out of backwards compatibility we cannot report hard errors in unused
                         // generic functions using associated constants of the generic parameters.
-                        err.report_as_lint(
-                            tcx,
-                            "erroneous constant used",
-                            lint_root,
-                            Some(c.span),
-                        );
+                        err.report_as_lint(tcx, "erroneous constant used", lint_root, Some(c.span));
                     } else {
                         err.report_as_error(tcx, "erroneous constant used");
                     }
index ebdb73c44679150fd2299e20740fba318d9f62d8..3386e6e588e7120105e272edf2fb7131ec97c52e 100644 (file)
@@ -23,10 +23,10 @@ LL |             n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
    = help: add `#![feature(const_if_match)]` to the crate attributes to enable
 
 error[E0080]: evaluation of constant value failed
-  --> $DIR/infinite_loop.rs:8:20
+  --> $DIR/infinite_loop.rs:8:17
    |
 LL |             n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
-   |                    ^^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
+   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
 
 error: aborting due to 3 previous errors
 
index be522dd6d5d5a53d942222f468201939fa5e7c29..8c2190b4e591f87624bbed87cd95288ffe9bfba9 100644 (file)
@@ -1,15 +1,18 @@
 error: any use of this value will cause an error
-  --> $DIR/const_eval_limit_reached.rs:8:11
+  --> $DIR/const_eval_limit_reached.rs:8:5
    |
-LL | / const X: usize = {
-LL | |     let mut x = 0;
-LL | |     while x != 1000 {
-   | |           ^^^^^^^^^ exceeded interpreter step limit (see `#[const_eval_limit]`)
-LL | |
-...  |
-LL | |     x
-LL | | };
-   | |__-
+LL |  / const X: usize = {
+LL |  |     let mut x = 0;
+LL |  |     while x != 1000 {
+   |  |_____^
+LL | ||
+LL | ||         x += 1;
+LL | ||     }
+   | ||_____^ exceeded interpreter step limit (see `#[const_eval_limit]`)
+LL |  |
+LL |  |     x
+LL |  | };
+   |  |__-
    |
    = note: `#[deny(const_err)]` on by default
 
index d424b22f000bfa81b050b310a1e82055f49692b4..9042c6f6be1912c0d85a60db229eddbff965230f 100644 (file)
@@ -1,8 +1,8 @@
 error[E0391]: cycle detected when const-evaluating `FOO`
-  --> $DIR/recursive-zst-static.rs:10:18
+  --> $DIR/recursive-zst-static.rs:10:1
    |
 LL | static FOO: () = FOO;
-   |                  ^^^
+   | ^^^^^^^^^^^^^^^^^^^^^
    |
 note: ...which requires const-evaluating `FOO`...
   --> $DIR/recursive-zst-static.rs:10:1
index d424b22f000bfa81b050b310a1e82055f49692b4..9042c6f6be1912c0d85a60db229eddbff965230f 100644 (file)
@@ -1,8 +1,8 @@
 error[E0391]: cycle detected when const-evaluating `FOO`
-  --> $DIR/recursive-zst-static.rs:10:18
+  --> $DIR/recursive-zst-static.rs:10:1
    |
 LL | static FOO: () = FOO;
-   |                  ^^^
+   | ^^^^^^^^^^^^^^^^^^^^^
    |
 note: ...which requires const-evaluating `FOO`...
   --> $DIR/recursive-zst-static.rs:10:1
index 15436f9c1b2cfa0cd8ecf1e308396658cb14b984..55f42d84f9cb032ca28e49be253c6c0ecbae6a7a 100644 (file)
@@ -1,11 +1,11 @@
 // build-fail
 
 pub const unsafe fn fake_type<T>() -> T {
-    hint_unreachable()
+    hint_unreachable() //~ ERROR evaluation of constant value failed
 }
 
 pub const unsafe fn hint_unreachable() -> ! {
-    fake_type() //~ ERROR evaluation of constant value failed
+    fake_type()
 }
 
 trait Const {
index ca232380897e3baa9e3e4fe2393c2c70665ab566..fc908b2b2225f130de39aba07c194bc2f67b5443 100644 (file)
@@ -1,9 +1,10 @@
 error[E0080]: evaluation of constant value failed
-  --> $DIR/uninhabited-const-issue-61744.rs:8:5
+  --> $DIR/uninhabited-const-issue-61744.rs:4:5
    |
 LL |     hint_unreachable()
-   |     ------------------
+   |     ^^^^^^^^^^^^^^^^^^
    |     |
+   |     reached the configured maximum number of stack frames
    |     inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
    |     inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
    |     inside `fake_type::<!>` at $DIR/uninhabited-const-issue-61744.rs:4:5
@@ -71,9 +72,8 @@ LL |     hint_unreachable()
    |     inside `fake_type::<i32>` at $DIR/uninhabited-const-issue-61744.rs:4:5
 ...
 LL |     fake_type()
-   |     ^^^^^^^^^^^
+   |     -----------
    |     |
-   |     reached the configured maximum number of stack frames
    |     inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
    |     inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
    |     inside `hint_unreachable` at $DIR/uninhabited-const-issue-61744.rs:8:5
index b724c261a7c3c2ad49df4519124b8492aacb8219..093606e100cb3fa300003ba5799a603837ea05f9 100644 (file)
@@ -1,8 +1,8 @@
 error[E0391]: cycle detected when const-evaluating `FOO`
-  --> $DIR/recursive-static-definition.rs:1:23
+  --> $DIR/recursive-static-definition.rs:1:1
    |
 LL | pub static FOO: u32 = FOO;
-   |                       ^^^
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
 note: ...which requires const-evaluating `FOO`...
   --> $DIR/recursive-static-definition.rs:1:1
index 6c2bd13d433ad7f99ad93a8f72ca141130d79037..50dfce3448c341e7caee2515d367803ced13bdbd 100644 (file)
@@ -5,10 +5,10 @@ LL | pub static mut B: () = unsafe { A = 1; };
    |                                 ^^^^^ modifying a static's initial value from another static's initializer
 
 error[E0391]: cycle detected when const-evaluating `C`
-  --> $DIR/write-to-static-mut-in-static.rs:5:34
+  --> $DIR/write-to-static-mut-in-static.rs:5:1
    |
 LL | pub static mut C: u32 = unsafe { C = 1; 0 };
-   |                                  ^^^^^
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
 note: ...which requires const-evaluating `C`...
   --> $DIR/write-to-static-mut-in-static.rs:5:1