summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/extra-const-ub
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:42 +0000
commitcec1877e180393eba0f6ddb0cf97bf3a791631c7 (patch)
tree47b4dac2a9dd9a40c30c251b4d4a72d7ccf77e9f /tests/ui/consts/extra-const-ub
parentAdding debian version 1.74.1+dfsg1-1. (diff)
downloadrustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.tar.xz
rustc-cec1877e180393eba0f6ddb0cf97bf3a791631c7.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/consts/extra-const-ub')
-rw-r--r--tests/ui/consts/extra-const-ub/detect-extra-ub.rs13
-rw-r--r--tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr8
2 files changed, 19 insertions, 2 deletions
diff --git a/tests/ui/consts/extra-const-ub/detect-extra-ub.rs b/tests/ui/consts/extra-const-ub/detect-extra-ub.rs
index 37b37e965..39f918379 100644
--- a/tests/ui/consts/extra-const-ub/detect-extra-ub.rs
+++ b/tests/ui/consts/extra-const-ub/detect-extra-ub.rs
@@ -1,7 +1,7 @@
// revisions: no_flag with_flag
// [no_flag] check-pass
// [with_flag] compile-flags: -Zextra-const-ub-checks
-#![feature(never_type, pointer_byte_offsets)]
+#![feature(never_type)]
use std::mem::transmute;
use std::ptr::addr_of;
@@ -88,4 +88,15 @@ const PARTIAL_POINTER: () = unsafe {
const VALID_ENUM1: E = { let e = E::A; e };
const VALID_ENUM2: Result<&'static [u8], ()> = { let e = Err(()); e };
+// Htting the (non-integer) array code in validation with an immediate local.
+const VALID_ARRAY: [Option<i32>; 0] = { let e = [None; 0]; e };
+
+// Detecting oversized references.
+const OVERSIZED_REF: () = { unsafe {
+ let slice: *const [u8] = transmute((1usize, usize::MAX));
+ let _val = &*slice;
+ //[with_flag]~^ ERROR: evaluation of constant value failed
+ //[with_flag]~| slice is bigger than largest supported object
+} };
+
fn main() {}
diff --git a/tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr b/tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
index 4ee12d501..0100aafb6 100644
--- a/tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
+++ b/tests/ui/consts/extra-const-ub/detect-extra-ub.with_flag.stderr
@@ -52,6 +52,12 @@ LL | let _val = *(&mem as *const Align as *const [*const u8; 2]);
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
-error: aborting due to 7 previous errors
+error[E0080]: evaluation of constant value failed
+ --> $DIR/detect-extra-ub.rs:97:16
+ |
+LL | let _val = &*slice;
+ | ^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
+
+error: aborting due to 8 previous errors
For more information about this error, try `rustc --explain E0080`.