about summary refs log tree commit diff
path: root/src/test/ui/consts
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-30 14:18:22 +0000
committerbors <bors@rust-lang.org>2018-08-30 14:18:22 +0000
commit685fb543174f8f2cadc38ec0b2c6df635eb1c087 (patch)
tree14b56d05da6f414bde31e349077c0a1114db16a9 /src/test/ui/consts
parent0e98621e69890d67d906a436a68436d03a3edb89 (diff)
parentc5cae7935b2ca1c482cd1c8542bd33e5fc3d888c (diff)
downloadrust-685fb543174f8f2cadc38ec0b2c6df635eb1c087.tar.gz
rust-685fb543174f8f2cadc38ec0b2c6df635eb1c087.zip
Auto merge of #53535 - TheDarkula:master, r=oli-obk
Made std::intrinsics::transmute() const fn.

r? @oli-obk

tracking issue: #53605
Diffstat (limited to 'src/test/ui/consts')
-rw-r--r--src/test/ui/consts/const-eval/transmute-const-promotion.rs18
-rw-r--r--src/test/ui/consts/const-eval/transmute-const-promotion.stderr14
-rw-r--r--src/test/ui/consts/const-eval/transmute-const.rs19
-rw-r--r--src/test/ui/consts/const-eval/transmute-const.stderr11
-rw-r--r--src/test/ui/consts/const-fn-not-safe-for-const.rs4
-rw-r--r--src/test/ui/consts/const-fn-not-safe-for-const.stderr8
6 files changed, 65 insertions, 9 deletions
diff --git a/src/test/ui/consts/const-eval/transmute-const-promotion.rs b/src/test/ui/consts/const-eval/transmute-const-promotion.rs
new file mode 100644
index 00000000000..ea55584f240
--- /dev/null
+++ b/src/test/ui/consts/const-eval/transmute-const-promotion.rs
@@ -0,0 +1,18 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(const_transmute)]
+
+use std::mem;
+
+fn main() {
+    let x: &'static u32 = unsafe { &mem::transmute(3.0f32) };
+    //~^ ERROR value does not live long enough
+}
diff --git a/src/test/ui/consts/const-eval/transmute-const-promotion.stderr b/src/test/ui/consts/const-eval/transmute-const-promotion.stderr
new file mode 100644
index 00000000000..2f46684b446
--- /dev/null
+++ b/src/test/ui/consts/const-eval/transmute-const-promotion.stderr
@@ -0,0 +1,14 @@
+error[E0597]: borrowed value does not live long enough
+  --> $DIR/transmute-const-promotion.rs:16:37
+   |
+LL |     let x: &'static u32 = unsafe { &mem::transmute(3.0f32) };
+   |                                     ^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
+LL |     //~^ ERROR value does not live long enough
+LL | }
+   | - temporary value only lives until here
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0597`.
diff --git a/src/test/ui/consts/const-eval/transmute-const.rs b/src/test/ui/consts/const-eval/transmute-const.rs
new file mode 100644
index 00000000000..a585a4404ad
--- /dev/null
+++ b/src/test/ui/consts/const-eval/transmute-const.rs
@@ -0,0 +1,19 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(const_transmute)]
+
+use std::mem;
+
+static FOO: bool = unsafe { mem::transmute(3u8) };
+//~^ ERROR this static likely exhibits undefined behavior
+//~^^ type validation failed: encountered 3, but expected something in the range 0..=1
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/transmute-const.stderr b/src/test/ui/consts/const-eval/transmute-const.stderr
new file mode 100644
index 00000000000..c9beca7aa30
--- /dev/null
+++ b/src/test/ui/consts/const-eval/transmute-const.stderr
@@ -0,0 +1,11 @@
+error[E0080]: this static likely exhibits undefined behavior
+  --> $DIR/transmute-const.rs:15:1
+   |
+LL | static FOO: bool = unsafe { mem::transmute(3u8) };
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3, but expected something in the range 0..=1
+   |
+   = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler 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`.
diff --git a/src/test/ui/consts/const-fn-not-safe-for-const.rs b/src/test/ui/consts/const-fn-not-safe-for-const.rs
index 341cc7bb491..30a738a83a3 100644
--- a/src/test/ui/consts/const-fn-not-safe-for-const.rs
+++ b/src/test/ui/consts/const-fn-not-safe-for-const.rs
@@ -10,14 +10,14 @@
 
 // Test that we can't call random fns in a const fn or do other bad things.
 
-#![feature(const_fn)]
+#![feature(const_fn, const_transmute)]
 
 use std::mem::transmute;
 
 fn random() -> u32 { 0 }
 
 const fn sub(x: &u32) -> usize {
-    unsafe { transmute(x) } //~ ERROR E0015
+    unsafe { transmute(x) }
 }
 
 const fn sub1() -> u32 {
diff --git a/src/test/ui/consts/const-fn-not-safe-for-const.stderr b/src/test/ui/consts/const-fn-not-safe-for-const.stderr
index 1e99a4378fa..613670acc93 100644
--- a/src/test/ui/consts/const-fn-not-safe-for-const.stderr
+++ b/src/test/ui/consts/const-fn-not-safe-for-const.stderr
@@ -1,10 +1,4 @@
 error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-  --> $DIR/const-fn-not-safe-for-const.rs:20:14
-   |
-LL |     unsafe { transmute(x) } //~ ERROR E0015
-   |              ^^^^^^^^^^^^
-
-error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
   --> $DIR/const-fn-not-safe-for-const.rs:24:5
    |
 LL |     random() //~ ERROR E0015
@@ -70,7 +64,7 @@ LL |     x + y
    |
    = help: add #![feature(const_let)] to the crate attributes to enable
 
-error: aborting due to 10 previous errors
+error: aborting due to 9 previous errors
 
 Some errors occurred: E0013, E0015, E0658.
 For more information about an error, try `rustc --explain E0013`.