From 80929e17ae4806a1d2fb5cf282f430c5e34f7796 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Mon, 10 Aug 2020 09:04:37 +0200 Subject: [PATCH] add test for unused ill-formed constant also use better span in TopFrameInfo --- src/diagnostics.rs | 2 +- tests/compile-fail/erroneous_const.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/compile-fail/erroneous_const.rs diff --git a/src/diagnostics.rs b/src/diagnostics.rs index ca3dd4dd66f..eed60c2696e 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -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 index 00000000000..287e0735814 --- /dev/null +++ b/tests/compile-fail/erroneous_const.rs @@ -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); +impl PrintName { + const VOID: ! = panic!(); //~WARN any use of this value will cause an error +} + +fn no_codegen() { + if false { + let _ = PrintName::::VOID; //~ERROR referenced constant has errors + } +} +fn main() { + no_codegen::(); +} -- 2.44.0