]> git.lizzy.rs Git - rust.git/commitdiff
add test for unused ill-formed constant
authorRalf Jung <post@ralfj.de>
Mon, 10 Aug 2020 07:04:37 +0000 (09:04 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 13 Aug 2020 06:33:36 +0000 (08:33 +0200)
also use better span in TopFrameInfo

src/diagnostics.rs
tests/compile-fail/erroneous_const.rs [new file with mode: 0644]

index ca3dd4dd66f23d08f2cebe3c4bcd6e985c008ba0..eed60c2696e1218846385949b0bb243beda67399 100644 (file)
@@ -227,7 +227,7 @@ fn preprocess_diagnostics(&self) -> TopFrameInfo<'tcx> {
         TopFrameInfo {
             stack_size: this.active_thread_stack().len(),
             instance: Some(frame.instance),
-            span: frame.current_source_info().map_or(DUMMY_SP, |si| si.span),
+            span: frame.current_span(),
         }
     }
 
diff --git a/tests/compile-fail/erroneous_const.rs b/tests/compile-fail/erroneous_const.rs
new file mode 100644 (file)
index 0000000..287e073
--- /dev/null
@@ -0,0 +1,19 @@
+//! Make sure we detect erroneous constants post-monomorphization even when they are unused.
+//! (https://github.com/rust-lang/miri/issues/1382)
+#![feature(const_panic)]
+#![feature(never_type)]
+#![warn(warnings, const_err)]
+
+struct PrintName<T>(T);
+impl<T> PrintName<T> {
+    const VOID: ! = panic!(); //~WARN any use of this value will cause an error
+}
+
+fn no_codegen<T>() {
+    if false {
+        let _ = PrintName::<T>::VOID; //~ERROR referenced constant has errors
+    }
+}
+fn main() {
+    no_codegen::<i32>();
+}