diff options
Diffstat (limited to 'tests/ui/const_prop')
-rw-r--r-- | tests/ui/const_prop/const-prop-ice.rs | 5 | ||||
-rw-r--r-- | tests/ui/const_prop/const-prop-ice.stderr | 10 | ||||
-rw-r--r-- | tests/ui/const_prop/const-prop-ice2.rs | 7 | ||||
-rw-r--r-- | tests/ui/const_prop/const-prop-ice2.stderr | 10 | ||||
-rw-r--r-- | tests/ui/const_prop/const-prop-ice3.rs | 7 | ||||
-rw-r--r-- | tests/ui/const_prop/const-prop-overflowing-casts.rs | 15 | ||||
-rw-r--r-- | tests/ui/const_prop/const-prop-read-static-in-const.rs | 10 | ||||
-rw-r--r-- | tests/ui/const_prop/const-prop-read-static-in-const.stderr | 17 | ||||
-rw-r--r-- | tests/ui/const_prop/unsized-local-ice.rs | 9 |
9 files changed, 90 insertions, 0 deletions
diff --git a/tests/ui/const_prop/const-prop-ice.rs b/tests/ui/const_prop/const-prop-ice.rs new file mode 100644 index 000000000..5bffe0206 --- /dev/null +++ b/tests/ui/const_prop/const-prop-ice.rs @@ -0,0 +1,5 @@ +// build-fail + +fn main() { + [0; 3][3u64 as usize]; //~ ERROR this operation will panic at runtime +} diff --git a/tests/ui/const_prop/const-prop-ice.stderr b/tests/ui/const_prop/const-prop-ice.stderr new file mode 100644 index 000000000..3bcf2b2de --- /dev/null +++ b/tests/ui/const_prop/const-prop-ice.stderr @@ -0,0 +1,10 @@ +error: this operation will panic at runtime + --> $DIR/const-prop-ice.rs:4:5 + | +LL | [0; 3][3u64 as usize]; + | ^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 3 but the index is 3 + | + = note: `#[deny(unconditional_panic)]` on by default + +error: aborting due to previous error + diff --git a/tests/ui/const_prop/const-prop-ice2.rs b/tests/ui/const_prop/const-prop-ice2.rs new file mode 100644 index 000000000..d533e394c --- /dev/null +++ b/tests/ui/const_prop/const-prop-ice2.rs @@ -0,0 +1,7 @@ +// build-fail + +fn main() { + enum Enum { One=1 } + let xs=[0;1 as usize]; + println!("{}", xs[Enum::One as usize]); //~ ERROR this operation will panic at runtime +} diff --git a/tests/ui/const_prop/const-prop-ice2.stderr b/tests/ui/const_prop/const-prop-ice2.stderr new file mode 100644 index 000000000..2b65ffc2d --- /dev/null +++ b/tests/ui/const_prop/const-prop-ice2.stderr @@ -0,0 +1,10 @@ +error: this operation will panic at runtime + --> $DIR/const-prop-ice2.rs:6:20 + | +LL | println!("{}", xs[Enum::One as usize]); + | ^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1 + | + = note: `#[deny(unconditional_panic)]` on by default + +error: aborting due to previous error + diff --git a/tests/ui/const_prop/const-prop-ice3.rs b/tests/ui/const_prop/const-prop-ice3.rs new file mode 100644 index 000000000..8ab011661 --- /dev/null +++ b/tests/ui/const_prop/const-prop-ice3.rs @@ -0,0 +1,7 @@ +// run-pass (ensure that const-prop is run) + +struct A<T: ?Sized>(T); + +fn main() { + let _x = &(&A([2, 3]) as &A<[i32]>).0 as *const [i32] as *const i32; +} diff --git a/tests/ui/const_prop/const-prop-overflowing-casts.rs b/tests/ui/const_prop/const-prop-overflowing-casts.rs new file mode 100644 index 000000000..8cc5b9825 --- /dev/null +++ b/tests/ui/const_prop/const-prop-overflowing-casts.rs @@ -0,0 +1,15 @@ +// check-pass + +enum Foo { + Bar = -42, + Baz = 42, +} + +fn main() { + let _ = 0u8 as u32; + let _ = (1u32 << 31) as u16; + let _ = (1u16 << 15) as u8; + let _ = (!0u16) as u8; + let _ = (-1i16) as i8; + let _ = (Foo::Bar) as i8; +} diff --git a/tests/ui/const_prop/const-prop-read-static-in-const.rs b/tests/ui/const_prop/const-prop-read-static-in-const.rs new file mode 100644 index 000000000..214262059 --- /dev/null +++ b/tests/ui/const_prop/const-prop-read-static-in-const.rs @@ -0,0 +1,10 @@ +// compile-flags: -Zunleash-the-miri-inside-of-you + +#![allow(dead_code)] + +const TEST: u8 = MY_STATIC; //~ ERROR constant + +static MY_STATIC: u8 = 4; + +fn main() { +} diff --git a/tests/ui/const_prop/const-prop-read-static-in-const.stderr b/tests/ui/const_prop/const-prop-read-static-in-const.stderr new file mode 100644 index 000000000..793da6285 --- /dev/null +++ b/tests/ui/const_prop/const-prop-read-static-in-const.stderr @@ -0,0 +1,17 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const-prop-read-static-in-const.rs:5:18 + | +LL | const TEST: u8 = MY_STATIC; + | ^^^^^^^^^ constant accesses static + +warning: skipping const checks + | +help: skipping check that does not even have a feature gate + --> $DIR/const-prop-read-static-in-const.rs:5:18 + | +LL | const TEST: u8 = MY_STATIC; + | ^^^^^^^^^ + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0080`. diff --git a/tests/ui/const_prop/unsized-local-ice.rs b/tests/ui/const_prop/unsized-local-ice.rs new file mode 100644 index 000000000..c725b3238 --- /dev/null +++ b/tests/ui/const_prop/unsized-local-ice.rs @@ -0,0 +1,9 @@ +// build-pass +//! Regression test for <https://github.com/rust-lang/rust/issues/68538>. +#![feature(unsized_fn_params)] + +pub fn take_unsized_slice(s: [u8]) { + s[0]; +} + +fn main() {} |