From 8fcebb528c7695a55d460fa756d720bc7f1810cb Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Tue, 23 Mar 2021 17:34:31 -0400 Subject: [PATCH] add tests related to erroneous consts in dead code with --emit=mir --- .../panic-assoc-never-type-unused.rs | 24 +++++++++++++++++ .../panic-assoc-never-type-unused.stderr | 26 +++++++++++++++++++ .../panic-assoc-unit-type-unused.rs | 23 ++++++++++++++++ .../panic-assoc-unit-type-unused.stderr | 26 +++++++++++++++++++ .../const-eval/panic-never-type-unused.rs | 20 ++++++++++++++ .../const-eval/panic-never-type-unused.stderr | 26 +++++++++++++++++++ .../const-eval/panic-unit-type-unused.rs | 19 ++++++++++++++ .../const-eval/panic-unit-type-unused.stderr | 26 +++++++++++++++++++ 8 files changed, 190 insertions(+) create mode 100644 src/test/ui/consts/const-eval/panic-assoc-never-type-unused.rs create mode 100644 src/test/ui/consts/const-eval/panic-assoc-never-type-unused.stderr create mode 100644 src/test/ui/consts/const-eval/panic-assoc-unit-type-unused.rs create mode 100644 src/test/ui/consts/const-eval/panic-assoc-unit-type-unused.stderr create mode 100644 src/test/ui/consts/const-eval/panic-never-type-unused.rs create mode 100644 src/test/ui/consts/const-eval/panic-never-type-unused.stderr create mode 100644 src/test/ui/consts/const-eval/panic-unit-type-unused.rs create mode 100644 src/test/ui/consts/const-eval/panic-unit-type-unused.stderr diff --git a/src/test/ui/consts/const-eval/panic-assoc-never-type-unused.rs b/src/test/ui/consts/const-eval/panic-assoc-never-type-unused.rs new file mode 100644 index 0000000000000..788b7b5ffc1ae --- /dev/null +++ b/src/test/ui/consts/const-eval/panic-assoc-never-type-unused.rs @@ -0,0 +1,24 @@ +// compile-flags: --emit=mir,link + +// Variant of panic-assoc-never-type.rs. +// Ensure that mir opts don't hide errors due to the usage of erroneous constants +// in unused code. + +#![warn(const_err)] +#![feature(const_panic)] +#![feature(never_type)] + +struct PrintName; + +impl PrintName { + const VOID: ! = panic!(); + //~^ WARN any use of this value will cause an error + //~| WARN this was previously accepted by the compiler but is being phased out +} + +fn foo() { + let _ = PrintName::VOID; + //~^ ERROR erroneous constant used +} + +fn main() {} diff --git a/src/test/ui/consts/const-eval/panic-assoc-never-type-unused.stderr b/src/test/ui/consts/const-eval/panic-assoc-never-type-unused.stderr new file mode 100644 index 0000000000000..fcb10a59b0d79 --- /dev/null +++ b/src/test/ui/consts/const-eval/panic-assoc-never-type-unused.stderr @@ -0,0 +1,26 @@ +warning: any use of this value will cause an error + --> $DIR/panic-assoc-never-type-unused.rs:14:21 + | +LL | const VOID: ! = panic!(); + | ----------------^^^^^^^^- + | | + | the evaluated program panicked at 'explicit panic', $DIR/panic-assoc-never-type-unused.rs:14:21 + | +note: the lint level is defined here + --> $DIR/panic-assoc-never-type-unused.rs:7:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #71800 + = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0080]: erroneous constant used + --> $DIR/panic-assoc-never-type-unused.rs:20:13 + | +LL | let _ = PrintName::VOID; + | ^^^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/panic-assoc-unit-type-unused.rs b/src/test/ui/consts/const-eval/panic-assoc-unit-type-unused.rs new file mode 100644 index 0000000000000..e64f421209676 --- /dev/null +++ b/src/test/ui/consts/const-eval/panic-assoc-unit-type-unused.rs @@ -0,0 +1,23 @@ +// compile-flags: --emit=mir,link + +// Variant of panic-assoc-never-type.rs. +// Ensure that mir opts don't hide errors due to the usage of erroneous constants +// in unused code, even for inhabited ZST constants. + +#![warn(const_err)] +#![feature(const_panic)] + +struct PrintName; + +impl PrintName { + const UNIT: () = panic!(); + //~^ WARN any use of this value will cause an error + //~| WARN this was previously accepted by the compiler but is being phased out +} + +fn foo() { + let _ = PrintName::UNIT; + //~^ ERROR erroneous constant used +} + +fn main() {} diff --git a/src/test/ui/consts/const-eval/panic-assoc-unit-type-unused.stderr b/src/test/ui/consts/const-eval/panic-assoc-unit-type-unused.stderr new file mode 100644 index 0000000000000..1edc8720c36ca --- /dev/null +++ b/src/test/ui/consts/const-eval/panic-assoc-unit-type-unused.stderr @@ -0,0 +1,26 @@ +warning: any use of this value will cause an error + --> $DIR/panic-assoc-unit-type-unused.rs:13:22 + | +LL | const UNIT: () = panic!(); + | -----------------^^^^^^^^- + | | + | the evaluated program panicked at 'explicit panic', $DIR/panic-assoc-unit-type-unused.rs:13:22 + | +note: the lint level is defined here + --> $DIR/panic-assoc-unit-type-unused.rs:7:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #71800 + = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0080]: erroneous constant used + --> $DIR/panic-assoc-unit-type-unused.rs:19:13 + | +LL | let _ = PrintName::UNIT; + | ^^^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/panic-never-type-unused.rs b/src/test/ui/consts/const-eval/panic-never-type-unused.rs new file mode 100644 index 0000000000000..a475435118802 --- /dev/null +++ b/src/test/ui/consts/const-eval/panic-never-type-unused.rs @@ -0,0 +1,20 @@ +// compile-flags: --emit=mir,link + +// Variant of panic-never-type.rs. +// Ensure that mir opts don't hide errors due to the usage of erroneous constants +// in unused code. + +#![warn(const_err)] +#![feature(const_panic)] +#![feature(never_type)] + +const VOID: ! = panic!(); +//~^ WARN any use of this value will cause an error +//~| WARN this was previously accepted by the compiler but is being phased out + +fn foo() { + let _ = VOID; + //~^ ERROR erroneous constant used +} + +fn main() {} diff --git a/src/test/ui/consts/const-eval/panic-never-type-unused.stderr b/src/test/ui/consts/const-eval/panic-never-type-unused.stderr new file mode 100644 index 0000000000000..e1e7457f81eaa --- /dev/null +++ b/src/test/ui/consts/const-eval/panic-never-type-unused.stderr @@ -0,0 +1,26 @@ +warning: any use of this value will cause an error + --> $DIR/panic-never-type-unused.rs:11:17 + | +LL | const VOID: ! = panic!(); + | ----------------^^^^^^^^- + | | + | the evaluated program panicked at 'explicit panic', $DIR/panic-never-type-unused.rs:11:17 + | +note: the lint level is defined here + --> $DIR/panic-never-type-unused.rs:7:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #71800 + = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0080]: erroneous constant used + --> $DIR/panic-never-type-unused.rs:16:13 + | +LL | let _ = VOID; + | ^^^^ referenced constant has errors + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-eval/panic-unit-type-unused.rs b/src/test/ui/consts/const-eval/panic-unit-type-unused.rs new file mode 100644 index 0000000000000..59f18ab8cf1e7 --- /dev/null +++ b/src/test/ui/consts/const-eval/panic-unit-type-unused.rs @@ -0,0 +1,19 @@ +// compile-flags: --emit=mir,link + +// Variant of panic-never-type.rs. +// Ensure that mir opts don't hide errors due to the usage of erroneous constants, +// in unused code, even for inhabited ZST constants. + +#![warn(const_err)] +#![feature(const_panic)] + +const UNIT: () = panic!(); +//~^ WARN any use of this value will cause an error +//~| WARN this was previously accepted by the compiler but is being phased out + +fn foo() { + let _ = UNIT; + //~^ ERROR erroneous constant used +} + +fn main() {} diff --git a/src/test/ui/consts/const-eval/panic-unit-type-unused.stderr b/src/test/ui/consts/const-eval/panic-unit-type-unused.stderr new file mode 100644 index 0000000000000..963c43aa80164 --- /dev/null +++ b/src/test/ui/consts/const-eval/panic-unit-type-unused.stderr @@ -0,0 +1,26 @@ +warning: any use of this value will cause an error + --> $DIR/panic-unit-type-unused.rs:10:18 + | +LL | const UNIT: () = panic!(); + | -----------------^^^^^^^^- + | | + | the evaluated program panicked at 'explicit panic', $DIR/panic-unit-type-unused.rs:10:18 + | +note: the lint level is defined here + --> $DIR/panic-unit-type-unused.rs:7:9 + | +LL | #![warn(const_err)] + | ^^^^^^^^^ + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #71800 + = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0080]: erroneous constant used + --> $DIR/panic-unit-type-unused.rs:15:13 + | +LL | let _ = UNIT; + | ^^^^ referenced constant has errors + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0080`.