diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-11-21 10:54:46 +0100 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2019-01-31 14:03:01 +0100 |
| commit | d0129a613c3bd4581826bb838eea1ab96c2cd5c7 (patch) | |
| tree | ffa2c04e3a1e89bdaea9d91976d87232cffc8e17 /src/test/ui/consts | |
| parent | f40aaa68278ef0879af5fe7ce077c64c6515ea05 (diff) | |
| download | rust-d0129a613c3bd4581826bb838eea1ab96c2cd5c7.tar.gz rust-d0129a613c3bd4581826bb838eea1ab96c2cd5c7.zip | |
Add a forever unstable opt-out of const qualification checks
Diffstat (limited to 'src/test/ui/consts')
6 files changed, 126 insertions, 0 deletions
diff --git a/src/test/ui/consts/miri_unleashed/assoc_const.rs b/src/test/ui/consts/miri_unleashed/assoc_const.rs new file mode 100644 index 00000000000..b8959667cc2 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/assoc_const.rs @@ -0,0 +1,30 @@ +// compile-flags: -Zunleash-the-miri-inside-of-you +#![allow(const_err)] + +// a test demonstrating why we do need to run static const qualification on associated constants +// instead of just checking the final constant + +trait Foo<T> { + const X: T; +} + +trait Bar<T, U: Foo<T>> { + const F: u32 = (U::X, 42).1; //~ WARN skipping const checks +} + +impl Foo<u32> for () { + const X: u32 = 42; +} +impl Foo<Vec<u32>> for String { + const X: Vec<u32> = Vec::new(); +} + +impl Bar<u32, ()> for () {} +impl Bar<Vec<u32>, String> for String {} + +fn main() { + // this is fine, but would have been forbidden by the static checks on `F` + let x = <() as Bar<u32, ()>>::F; + // this test only causes errors due to the line below, so post-monomorphization + let y = <String as Bar<Vec<u32>, String>>::F; //~ ERROR erroneous constant +} diff --git a/src/test/ui/consts/miri_unleashed/assoc_const.stderr b/src/test/ui/consts/miri_unleashed/assoc_const.stderr new file mode 100644 index 00000000000..a40f8d46d0a --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/assoc_const.stderr @@ -0,0 +1,15 @@ +warning: skipping const checks + --> $DIR/assoc_const.rs:12:31 + | +LL | const F: u32 = (U::X, 42).1; //~ WARN skipping const checks + | ^ + +error[E0080]: erroneous constant used + --> $DIR/assoc_const.rs:29:13 + | +LL | let y = <String as Bar<Vec<u32>, String>>::F; //~ ERROR erroneous constant + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/miri_unleashed/assoc_const_2.rs b/src/test/ui/consts/miri_unleashed/assoc_const_2.rs new file mode 100644 index 00000000000..c87b6389848 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/assoc_const_2.rs @@ -0,0 +1,28 @@ +#![allow(const_err)] + +// a test demonstrating that const qualification cannot prevent monomorphization time errors + +trait Foo { + const X: u32; +} + +trait Bar<U: Foo> { + const F: u32 = 100 / U::X; +} + +impl Foo for () { + const X: u32 = 42; +} + +impl Foo for String { + const X: u32 = 0; +} + +impl Bar<()> for () {} +impl Bar<String> for String {} + +fn main() { + let x = <() as Bar<()>>::F; + // this test only causes errors due to the line below, so post-monomorphization + let y = <String as Bar<String>>::F; //~ ERROR erroneous constant +} diff --git a/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr b/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr new file mode 100644 index 00000000000..77aab31d26e --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/assoc_const_2.stderr @@ -0,0 +1,9 @@ +error[E0080]: erroneous constant used + --> $DIR/assoc_const_2.rs:27:13 + | +LL | let y = <String as Bar<String>>::F; //~ ERROR erroneous constant + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs new file mode 100644 index 00000000000..5fb92535502 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.rs @@ -0,0 +1,27 @@ +#![allow(const_err)] + +// a test demonstrating why we do need to run static const qualification on associated constants +// instead of just checking the final constant + +trait Foo<T> { + const X: T; +} + +trait Bar<T, U: Foo<T>> { + const F: u32 = (U::X, 42).1; //~ ERROR destructors cannot be evaluated at compile-time +} + +impl Foo<u32> for () { + const X: u32 = 42; +} +impl Foo<Vec<u32>> for String { + const X: Vec<u32> = Vec::new(); //~ ERROR not yet stable as a const fn +} + +impl Bar<u32, ()> for () {} +impl Bar<Vec<u32>, String> for String {} + +fn main() { + let x = <() as Bar<u32, ()>>::F; + let y = <String as Bar<Vec<u32>, String>>::F; +} diff --git a/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr new file mode 100644 index 00000000000..e23ed1c6206 --- /dev/null +++ b/src/test/ui/consts/miri_unleashed/feature-gate-unleash_the_miri_inside_of_you.stderr @@ -0,0 +1,17 @@ +error[E0493]: destructors cannot be evaluated at compile-time + --> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:11:20 + | +LL | const F: u32 = (U::X, 42).1; //~ ERROR destructors cannot be evaluated at compile-time + | ^^^^^^^^^^ constants cannot evaluate destructors + +error: `<std::vec::Vec<T>>::new` is not yet stable as a const fn + --> $DIR/feature-gate-unleash_the_miri_inside_of_you.rs:18:25 + | +LL | const X: Vec<u32> = Vec::new(); //~ ERROR not yet stable as a const fn + | ^^^^^^^^^^ + | + = help: add `#![feature(const_vec_new)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0493`. |
