diff options
| author | Ralf Jung <post@ralfj.de> | 2024-06-11 13:28:36 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-06-11 13:28:36 +0200 |
| commit | de4ac0c465facfdfd56ce08dc6bb5cfee901561c (patch) | |
| tree | 95aa60221b2b89addf80765e439d9b0181b1f8bb /tests | |
| parent | db44cae343fa306b6b2263355dc3f9a5f5db82b4 (diff) | |
| download | rust-de4ac0c465facfdfd56ce08dc6bb5cfee901561c.tar.gz rust-de4ac0c465facfdfd56ce08dc6bb5cfee901561c.zip | |
add const eval bool-to-int cast test
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/consts/const-eval/ub-invalid-values.rs | 11 | ||||
| -rw-r--r-- | tests/ui/consts/const-eval/ub-invalid-values.stderr | 20 |
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/consts/const-eval/ub-invalid-values.rs b/tests/ui/consts/const-eval/ub-invalid-values.rs new file mode 100644 index 00000000000..1724a88dd3d --- /dev/null +++ b/tests/ui/consts/const-eval/ub-invalid-values.rs @@ -0,0 +1,11 @@ +const fn bool_cast(ptr: *const bool) { unsafe { + let _val = *ptr as u32; //~ERROR: evaluation of constant value failed + //~^ interpreting an invalid 8-bit value as a bool +}} + +const _: () = { + let v = 3_u8; + bool_cast(&v as *const u8 as *const bool); +}; + +fn main() {} diff --git a/tests/ui/consts/const-eval/ub-invalid-values.stderr b/tests/ui/consts/const-eval/ub-invalid-values.stderr new file mode 100644 index 00000000000..edf72f731e5 --- /dev/null +++ b/tests/ui/consts/const-eval/ub-invalid-values.stderr @@ -0,0 +1,20 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/ub-invalid-values.rs:2:16 + | +LL | let _val = *ptr as u32; + | ^^^^^^^^^^^ interpreting an invalid 8-bit value as a bool: 0x03 + | +note: inside `bool_cast` + --> $DIR/ub-invalid-values.rs:2:16 + | +LL | let _val = *ptr as u32; + | ^^^^^^^^^^^ +note: inside `_` + --> $DIR/ub-invalid-values.rs:8:5 + | +LL | bool_cast(&v as *const u8 as *const bool); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0080`. |
