summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/const-eval/unused-broken-const-late.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/ui/consts/const-eval/unused-broken-const-late.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/ui/consts/const-eval/unused-broken-const-late.rs b/tests/ui/consts/const-eval/unused-broken-const-late.rs
new file mode 100644
index 000000000..a6528ec5f
--- /dev/null
+++ b/tests/ui/consts/const-eval/unused-broken-const-late.rs
@@ -0,0 +1,20 @@
+// build-fail
+// compile-flags: -O
+//! Make sure we detect erroneous constants post-monomorphization even when they are unused. This is
+//! crucial, people rely on it for soundness. (https://github.com/rust-lang/rust/issues/112090)
+
+struct PrintName<T>(T);
+impl<T> PrintName<T> {
+ const VOID: () = panic!(); //~ERROR evaluation of `PrintName::<i32>::VOID` failed
+}
+
+fn no_codegen<T>() {
+ // Any function that is called is guaranteed to have all consts that syntactically
+ // appear in its body evaluated, even if they only appear in dead code.
+ if false {
+ let _ = PrintName::<T>::VOID;
+ }
+}
+pub fn main() {
+ no_codegen::<i32>();
+}