about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2022-08-13 08:22:19 -0400
committerRalf Jung <post@ralfj.de>2022-08-13 08:23:28 -0400
commit7df41a77b821946e2f187d938e4bc9ef49e03f79 (patch)
tree4cbab0c40b7cdff091418f4a8c17b4ba59820571
parent4e1bc7e695cb412fa77fe17b5380b0244e9a70b9 (diff)
downloadrust-7df41a77b821946e2f187d938e4bc9ef49e03f79.tar.gz
rust-7df41a77b821946e2f187d938e4bc9ef49e03f79.zip
rustup
-rw-r--r--rust-version2
-rw-r--r--src/lib.rs1
-rw-r--r--tests/fail/const-ub-checks.rs11
-rw-r--r--tests/fail/const-ub-checks.stderr9
4 files changed, 22 insertions, 1 deletions
diff --git a/rust-version b/rust-version
index 0bcadc0a366..fdd18704d18 100644
--- a/rust-version
+++ b/rust-version
@@ -1 +1 @@
-20ffea6938b5839c390252e07940b99e3b6a889a
+75b7e52e92c3b00fc891b47f5b2efdff0a2be55a
diff --git a/src/lib.rs b/src/lib.rs
index 94958b2ff5f..ba337f28311 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -116,4 +116,5 @@ pub const MIRI_DEFAULT_ARGS: &[&str] = &[
     "-Zmir-opt-level=0",
     "--cfg=miri",
     "-Cdebug-assertions=on",
+    "-Zextra-const-ub-checks",
 ];
diff --git a/tests/fail/const-ub-checks.rs b/tests/fail/const-ub-checks.rs
new file mode 100644
index 00000000000..fa522c30cbd
--- /dev/null
+++ b/tests/fail/const-ub-checks.rs
@@ -0,0 +1,11 @@
+#![feature(const_ptr_read)]
+
+const UNALIGNED_READ: () = unsafe {
+    let x = &[0u8; 4];
+    let ptr = x.as_ptr().cast::<u32>();
+    ptr.read(); //~ERROR: evaluation of constant value failed
+};
+
+fn main() {
+    let _x = UNALIGNED_READ;
+}
diff --git a/tests/fail/const-ub-checks.stderr b/tests/fail/const-ub-checks.stderr
new file mode 100644
index 00000000000..a8b7ea242b9
--- /dev/null
+++ b/tests/fail/const-ub-checks.stderr
@@ -0,0 +1,9 @@
+error[E0080]: evaluation of constant value failed
+  --> $DIR/const-ub-checks.rs:LL:CC
+   |
+LL |     ptr.read();
+   |     ^^^^^^^^^^ accessing memory with alignment ALIGN, but alignment ALIGN is required
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.