diff options
Diffstat (limited to 'src/test/ui/const_prop')
-rw-r--r-- | src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs | 14 | ||||
-rw-r--r-- | src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr | 14 | ||||
-rw-r--r-- | src/test/ui/const_prop/inline_spans.rs | 15 | ||||
-rw-r--r-- | src/test/ui/const_prop/inline_spans_lint_attribute.rs | 15 |
4 files changed, 58 insertions, 0 deletions
diff --git a/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs new file mode 100644 index 000000000..2afbf3432 --- /dev/null +++ b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.rs @@ -0,0 +1,14 @@ +// check-pass + +// need to emit MIR, because const prop (which emits `unconditional_panic`) only runs if +// the `optimized_mir` query is run, which it isn't in check-only mode. +// compile-flags: --crate-type lib --emit=mir,link + +#![warn(unconditional_panic)] + +pub struct Fixed64(i64); + +// HACK: this test passes only because this is a const fn that is written to metadata +pub const fn div(f: Fixed64) { + f.0 / 0; //~ WARN will panic at runtime +} diff --git a/src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr new file mode 100644 index 000000000..865c69c3c --- /dev/null +++ b/src/test/ui/const_prop/ice-assert-fail-div-by-zero.stderr @@ -0,0 +1,14 @@ +warning: this operation will panic at runtime + --> $DIR/ice-assert-fail-div-by-zero.rs:13:5 + | +LL | f.0 / 0; + | ^^^^^^^ attempt to divide `_` by zero + | +note: the lint level is defined here + --> $DIR/ice-assert-fail-div-by-zero.rs:7:9 + | +LL | #![warn(unconditional_panic)] + | ^^^^^^^^^^^^^^^^^^^ + +warning: 1 warning emitted + diff --git a/src/test/ui/const_prop/inline_spans.rs b/src/test/ui/const_prop/inline_spans.rs new file mode 100644 index 000000000..504f27811 --- /dev/null +++ b/src/test/ui/const_prop/inline_spans.rs @@ -0,0 +1,15 @@ +// build-pass +// compile-flags: -Zmir-opt-level=3 +// Overflow can't be detected by const prop +// could only be detected after optimizations + +#![deny(warnings)] + +fn main() { + let _ = add(u8::MAX, 1); +} + +#[inline(always)] +fn add(x: u8, y: u8) -> u8 { + x + y +} diff --git a/src/test/ui/const_prop/inline_spans_lint_attribute.rs b/src/test/ui/const_prop/inline_spans_lint_attribute.rs new file mode 100644 index 000000000..1db53d771 --- /dev/null +++ b/src/test/ui/const_prop/inline_spans_lint_attribute.rs @@ -0,0 +1,15 @@ +// Must be build-pass, because check-pass will not run const prop and thus not emit the lint anyway. +// build-pass +// compile-flags: -Zmir-opt-level=3 + +#![deny(warnings)] + +fn main() { + #[allow(arithmetic_overflow)] + let _ = add(u8::MAX, 1); +} + +#[inline(always)] +fn add(x: u8, y: u8) -> u8 { + x + y +} |