about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-04-29 10:47:16 +0200
committerRalf Jung <post@ralfj.de>2020-04-29 10:47:16 +0200
commit979bbf2ce1568f305fb52c2e10dc9db2375ce5bd (patch)
tree42472c314a6e5d26846f71b314046d4dbd4a37a8 /src/test
parenta0898019485fd0920957444b7b387eec5f2b112d (diff)
downloadrust-979bbf2ce1568f305fb52c2e10dc9db2375ce5bd.tar.gz
rust-979bbf2ce1568f305fb52c2e10dc9db2375ce5bd.zip
also test reference into static field
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs19
-rw-r--r--src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr36
2 files changed, 40 insertions, 15 deletions
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
index cf277308c08..dd498253917 100644
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.rs
@@ -1,4 +1,4 @@
-// compile-flags: -Zunleash-the-miri-inside-of-you
+// compile-flags: -Zunleash-the-miri-inside-of-you -Zdeduplicate-diagnostics
 // aux-build:static_cross_crate.rs
 #![allow(const_err)]
 
@@ -14,18 +14,31 @@ const SLICE_MUT: &[u8; 1] = { //~ ERROR undefined behavior to use this value
 //~| NOTE
     unsafe { &static_cross_crate::ZERO }
     //~^ WARN skipping const checks
-    //~| WARN skipping const checks
+};
+
+const SLICE_MUT2: &u8 = { //~ ERROR undefined behavior to use this value
+//~| NOTE encountered a reference pointing to a static variable
+//~| NOTE
+    unsafe { &static_cross_crate::ZERO[0] }
+    //~^ WARN skipping const checks
 };
 
 pub fn test(x: &[u8; 1]) -> bool {
     match x {
         SLICE_MUT => true,
         //~^ ERROR could not evaluate constant pattern
-        //~| ERROR could not evaluate constant pattern
         &[1..] => false,
     }
 }
 
+pub fn test2(x: &u8) -> bool {
+    match x {
+        SLICE_MUT2 => true,
+        //~^ ERROR could not evaluate constant pattern
+        &(1..) => false,
+    }
+}
+
 fn main() {
     unsafe {
         static_cross_crate::ZERO[0] = 1;
diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr
index dfee007c740..b176dbd2e4d 100644
--- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr
+++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.stderr
@@ -4,12 +4,6 @@ warning: skipping const checks
 LL |     unsafe { &static_cross_crate::ZERO }
    |               ^^^^^^^^^^^^^^^^^^^^^^^^
 
-warning: skipping const checks
-  --> $DIR/const_refers_to_static_cross_crate.rs:15:15
-   |
-LL |     unsafe { &static_cross_crate::ZERO }
-   |               ^^^^^^^^^^^^^^^^^^^^^^^^
-
 error[E0080]: it is undefined behavior to use this value
   --> $DIR/const_refers_to_static_cross_crate.rs:12:1
    |
@@ -18,24 +12,42 @@ LL | |
 LL | |
 LL | |     unsafe { &static_cross_crate::ZERO }
 LL | |
-LL | |
 LL | | };
    | |__^ type validation failed: encountered a reference pointing to a static variable
    |
    = 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: could not evaluate constant pattern
-  --> $DIR/const_refers_to_static_cross_crate.rs:22:9
+  --> $DIR/const_refers_to_static_cross_crate.rs:28:9
    |
 LL |         SLICE_MUT => true,
    |         ^^^^^^^^^
 
+warning: skipping const checks
+  --> $DIR/const_refers_to_static_cross_crate.rs:22:15
+   |
+LL |     unsafe { &static_cross_crate::ZERO[0] }
+   |               ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0080]: it is undefined behavior to use this value
+  --> $DIR/const_refers_to_static_cross_crate.rs:19:1
+   |
+LL | / const SLICE_MUT2: &u8 = {
+LL | |
+LL | |
+LL | |     unsafe { &static_cross_crate::ZERO[0] }
+LL | |
+LL | | };
+   | |__^ type validation failed: encountered a reference pointing to a static variable
+   |
+   = 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: could not evaluate constant pattern
-  --> $DIR/const_refers_to_static_cross_crate.rs:22:9
+  --> $DIR/const_refers_to_static_cross_crate.rs:36:9
    |
-LL |         SLICE_MUT => true,
-   |         ^^^^^^^^^
+LL |         SLICE_MUT2 => true,
+   |         ^^^^^^^^^^
 
-error: aborting due to 3 previous errors; 2 warnings emitted
+error: aborting due to 4 previous errors; 2 warnings emitted
 
 For more information about this error, try `rustc --explain E0080`.