about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-12-02 08:35:24 +0000
committerbors <bors@rust-lang.org>2019-12-02 08:35:24 +0000
commit4af3ee8ee2a2bc1286b021db7600ba990359cf3f (patch)
tree8631bfc4d4f6746bdc573f206f8f5edf4bbdfc74 /src/test
parentf5c81e0a986e4285d3d0fd781a1bd475753eb12c (diff)
parent910e83eab2f65dd922f8d980c71840a68b3d7c6a (diff)
downloadrust-4af3ee8ee2a2bc1286b021db7600ba990359cf3f.tar.gz
rust-4af3ee8ee2a2bc1286b021db7600ba990359cf3f.zip
Auto merge of #66950 - RalfJung:rollup-12d0zx8, r=RalfJung
Rollup of 5 pull requests

Successful merges:

 - #66245 (Conditional compilation for sanitizers)
 - #66654 (Handle const-checks for `&mut` outside of `HasMutInterior`)
 - #66822 (libunwind_panic: adjust miri panic hack)
 - #66827 (handle diverging functions forwarding their return place)
 - #66834 (rustbuild fixes)

Failed merges:

r? @ghost
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/const-multi-ref.rs19
-rw-r--r--src/test/ui/consts/const-multi-ref.stderr13
-rw-r--r--src/test/ui/error-codes/E0017.rs3
-rw-r--r--src/test/ui/error-codes/E0017.stderr24
-rw-r--r--src/test/ui/error-codes/E0388.rs9
-rw-r--r--src/test/ui/error-codes/E0388.stderr28
-rw-r--r--src/test/ui/feature-gates/feature-gate-cfg_sanitize.rs3
-rw-r--r--src/test/ui/feature-gates/feature-gate-cfg_sanitize.stderr12
-rw-r--r--src/test/ui/sanitize-cfg.rs26
9 files changed, 85 insertions, 52 deletions
diff --git a/src/test/ui/consts/const-multi-ref.rs b/src/test/ui/consts/const-multi-ref.rs
index 498e99e668b..5e2be0d4f3f 100644
--- a/src/test/ui/consts/const-multi-ref.rs
+++ b/src/test/ui/consts/const-multi-ref.rs
@@ -1,11 +1,24 @@
-const _X: i32 = {
+// Ensure that we point the user to the erroneous borrow but not to any subsequent borrows of that
+// initial one.
+
+const _: i32 = {
     let mut a = 5;
-    let p = &mut a;      //~ ERROR references in constants may only refer to immutable values
+    let p = &mut a; //~ ERROR references in constants may only refer to immutable values
 
-    let reborrow = {p};  //~ ERROR references in constants may only refer to immutable values
+    let reborrow = {p};
     let pp = &reborrow;
     let ppp = &pp;
     ***ppp
 };
 
+const _: std::cell::Cell<i32> = {
+    let mut a = std::cell::Cell::new(5);
+    let p = &a; //~ ERROR cannot borrow a constant which may contain interior mutability
+
+    let reborrow = {p};
+    let pp = &reborrow;
+    let ppp = &pp;
+    a
+};
+
 fn main() {}
diff --git a/src/test/ui/consts/const-multi-ref.stderr b/src/test/ui/consts/const-multi-ref.stderr
index 9e525ef9aac..ed3837e9c9e 100644
--- a/src/test/ui/consts/const-multi-ref.stderr
+++ b/src/test/ui/consts/const-multi-ref.stderr
@@ -1,15 +1,16 @@
 error[E0017]: references in constants may only refer to immutable values
-  --> $DIR/const-multi-ref.rs:3:13
+  --> $DIR/const-multi-ref.rs:6:13
    |
 LL |     let p = &mut a;
    |             ^^^^^^ constants require immutable values
 
-error[E0017]: references in constants may only refer to immutable values
-  --> $DIR/const-multi-ref.rs:5:21
+error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
+  --> $DIR/const-multi-ref.rs:16:13
    |
-LL |     let reborrow = {p};
-   |                     ^ constants require immutable values
+LL |     let p = &a;
+   |             ^^
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0017`.
+Some errors have detailed explanations: E0017, E0492.
+For more information about an error, try `rustc --explain E0017`.
diff --git a/src/test/ui/error-codes/E0017.rs b/src/test/ui/error-codes/E0017.rs
index 94b6587eb81..3bc518c2c2b 100644
--- a/src/test/ui/error-codes/E0017.rs
+++ b/src/test/ui/error-codes/E0017.rs
@@ -1,8 +1,11 @@
 static X: i32 = 1;
 const C: i32 = 2;
+static mut M: i32 = 3;
 
 const CR: &'static mut i32 = &mut C; //~ ERROR E0017
 static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
+                                              //~| ERROR E0019
                                               //~| ERROR cannot borrow
 static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
+static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR E0017
 fn main() {}
diff --git a/src/test/ui/error-codes/E0017.stderr b/src/test/ui/error-codes/E0017.stderr
index 47863f02214..8c8660adceb 100644
--- a/src/test/ui/error-codes/E0017.stderr
+++ b/src/test/ui/error-codes/E0017.stderr
@@ -1,28 +1,40 @@
 error[E0017]: references in constants may only refer to immutable values
-  --> $DIR/E0017.rs:4:30
+  --> $DIR/E0017.rs:5:30
    |
 LL | const CR: &'static mut i32 = &mut C;
    |                              ^^^^^^ constants require immutable values
 
+error[E0019]: static contains unimplemented expression type
+  --> $DIR/E0017.rs:6:39
+   |
+LL | static STATIC_REF: &'static mut i32 = &mut X;
+   |                                       ^^^^^^
+
 error[E0017]: references in statics may only refer to immutable values
-  --> $DIR/E0017.rs:5:39
+  --> $DIR/E0017.rs:6:39
    |
 LL | static STATIC_REF: &'static mut i32 = &mut X;
    |                                       ^^^^^^ statics require immutable values
 
 error[E0596]: cannot borrow immutable static item `X` as mutable
-  --> $DIR/E0017.rs:5:39
+  --> $DIR/E0017.rs:6:39
    |
 LL | static STATIC_REF: &'static mut i32 = &mut X;
    |                                       ^^^^^^ cannot borrow as mutable
 
 error[E0017]: references in statics may only refer to immutable values
-  --> $DIR/E0017.rs:7:38
+  --> $DIR/E0017.rs:9:38
    |
 LL | static CONST_REF: &'static mut i32 = &mut C;
    |                                      ^^^^^^ statics require immutable values
 
-error: aborting due to 4 previous errors
+error[E0017]: references in statics may only refer to immutable values
+  --> $DIR/E0017.rs:10:52
+   |
+LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
+   |                                                    ^^^^^^ statics require immutable values
+
+error: aborting due to 6 previous errors
 
-Some errors have detailed explanations: E0017, E0596.
+Some errors have detailed explanations: E0017, E0019, E0596.
 For more information about an error, try `rustc --explain E0017`.
diff --git a/src/test/ui/error-codes/E0388.rs b/src/test/ui/error-codes/E0388.rs
deleted file mode 100644
index 3aa4ac9655c..00000000000
--- a/src/test/ui/error-codes/E0388.rs
+++ /dev/null
@@ -1,9 +0,0 @@
-static X: i32 = 1;
-const C: i32 = 2;
-
-const CR: &'static mut i32 = &mut C; //~ ERROR E0017
-static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
-                                              //~| ERROR cannot borrow
-static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
-
-fn main() {}
diff --git a/src/test/ui/error-codes/E0388.stderr b/src/test/ui/error-codes/E0388.stderr
deleted file mode 100644
index b52d5260b13..00000000000
--- a/src/test/ui/error-codes/E0388.stderr
+++ /dev/null
@@ -1,28 +0,0 @@
-error[E0017]: references in constants may only refer to immutable values
-  --> $DIR/E0388.rs:4:30
-   |
-LL | const CR: &'static mut i32 = &mut C;
-   |                              ^^^^^^ constants require immutable values
-
-error[E0017]: references in statics may only refer to immutable values
-  --> $DIR/E0388.rs:5:39
-   |
-LL | static STATIC_REF: &'static mut i32 = &mut X;
-   |                                       ^^^^^^ statics require immutable values
-
-error[E0596]: cannot borrow immutable static item `X` as mutable
-  --> $DIR/E0388.rs:5:39
-   |
-LL | static STATIC_REF: &'static mut i32 = &mut X;
-   |                                       ^^^^^^ cannot borrow as mutable
-
-error[E0017]: references in statics may only refer to immutable values
-  --> $DIR/E0388.rs:7:38
-   |
-LL | static CONST_REF: &'static mut i32 = &mut C;
-   |                                      ^^^^^^ statics require immutable values
-
-error: aborting due to 4 previous errors
-
-Some errors have detailed explanations: E0017, E0596.
-For more information about an error, try `rustc --explain E0017`.
diff --git a/src/test/ui/feature-gates/feature-gate-cfg_sanitize.rs b/src/test/ui/feature-gates/feature-gate-cfg_sanitize.rs
new file mode 100644
index 00000000000..c3e7cc9ed8a
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-cfg_sanitize.rs
@@ -0,0 +1,3 @@
+#[cfg(not(sanitize = "thread"))]
+//~^ `cfg(sanitize)` is experimental
+fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-cfg_sanitize.stderr b/src/test/ui/feature-gates/feature-gate-cfg_sanitize.stderr
new file mode 100644
index 00000000000..f67a0d83bdd
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-cfg_sanitize.stderr
@@ -0,0 +1,12 @@
+error[E0658]: `cfg(sanitize)` is experimental and subject to change
+  --> $DIR/feature-gate-cfg_sanitize.rs:1:11
+   |
+LL | #[cfg(not(sanitize = "thread"))]
+   |           ^^^^^^^^^^^^^^^^^^^
+   |
+   = note: for more information, see https://github.com/rust-lang/rust/issues/39699
+   = help: add `#![feature(cfg_sanitize)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/sanitize-cfg.rs b/src/test/ui/sanitize-cfg.rs
new file mode 100644
index 00000000000..9c198543a86
--- /dev/null
+++ b/src/test/ui/sanitize-cfg.rs
@@ -0,0 +1,26 @@
+// Verifies that when compiling with -Zsanitizer=option,
+// the `#[cfg(sanitize = "option")]` attribute is configured.
+
+// needs-sanitizer-support
+// only-linux
+// only-x86_64
+// check-pass
+// revisions: address leak memory thread
+//[address]compile-flags: -Zsanitizer=address --cfg address
+//[leak]compile-flags:    -Zsanitizer=leak    --cfg leak
+//[memory]compile-flags:  -Zsanitizer=memory  --cfg memory
+//[thread]compile-flags:  -Zsanitizer=thread  --cfg thread
+
+#![feature(cfg_sanitize)]
+
+#[cfg(all(sanitize = "address", address))]
+fn main() {}
+
+#[cfg(all(sanitize = "leak", leak))]
+fn main() {}
+
+#[cfg(all(sanitize = "memory", memory))]
+fn main() {}
+
+#[cfg(all(sanitize = "thread", thread))]
+fn main() {}