about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2021-01-27 04:43:16 +0900
committerGitHub <noreply@github.com>2021-01-27 04:43:16 +0900
commitc2c90bf5489a50c6cfc808fba5d587009eea4bff (patch)
treec8a9b9cab9051fd049264457d63980025002e1b5 /src/test/ui
parentfe6b3a97921eb59502dfca13505e3ef68f5289bb (diff)
parent2be19932335f76cb4a97c275038a019751fbba6a (diff)
downloadrust-c2c90bf5489a50c6cfc808fba5d587009eea4bff.tar.gz
rust-c2c90bf5489a50c6cfc808fba5d587009eea4bff.zip
Rollup merge of #80900 - camelid:readpointerasbytes-ice, r=oli-obk
Fix ICE with `ReadPointerAsBytes` validation error

Fixes #79690.

r? ``````@oli-obk``````
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/consts/issue-79690.rs32
-rw-r--r--src/test/ui/consts/issue-79690.stderr11
2 files changed, 43 insertions, 0 deletions
diff --git a/src/test/ui/consts/issue-79690.rs b/src/test/ui/consts/issue-79690.rs
new file mode 100644
index 00000000000..a2e7b97b318
--- /dev/null
+++ b/src/test/ui/consts/issue-79690.rs
@@ -0,0 +1,32 @@
+// ignore-32bit
+// This test gives a different error on 32-bit architectures.
+
+union Transmute<T: Copy, U: Copy> {
+    t: T,
+    u: U,
+}
+trait Bar {
+    fn bar(&self) -> u32;
+}
+struct Foo {
+    foo: u32,
+    bar: bool,
+}
+impl Bar for Foo {
+    fn bar(&self) -> u32 {
+        self.foo
+    }
+}
+#[derive(Copy, Clone)]
+struct Fat<'a>(&'a Foo, &'static VTable);
+struct VTable {
+    size: Foo,
+}
+const FOO: &dyn Bar = &Foo {
+    foo: 128,
+    bar: false,
+};
+const G: Fat = unsafe { Transmute { t: FOO }.u };
+//~^ ERROR it is undefined behavior to use this value
+
+fn main() {}
diff --git a/src/test/ui/consts/issue-79690.stderr b/src/test/ui/consts/issue-79690.stderr
new file mode 100644
index 00000000000..918dd4c20f9
--- /dev/null
+++ b/src/test/ui/consts/issue-79690.stderr
@@ -0,0 +1,11 @@
+error[E0080]: it is undefined behavior to use this value
+  --> $DIR/issue-79690.rs:29:1
+   |
+LL | const G: Fat = unsafe { Transmute { t: FOO }.u };
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered read of part of a pointer at .1.<deref>.size.foo
+   |
+   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.