about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-11-10 11:37:32 +0000
committerbors <bors@rust-lang.org>2017-11-10 11:37:32 +0000
commit968b6206cb140a51f2e3cc3d7841aed51b0d64d9 (patch)
tree47a5075a6e0ba4009a03063fa0db41324a4cee69 /src/test
parentc0d326f06d562c3aedf0727a665e9f2c34ba9d0c (diff)
parent12aedc833ccec26e6a883ec52e98acfc6d41263b (diff)
downloadrust-968b6206cb140a51f2e3cc3d7841aed51b0d64d9.tar.gz
rust-968b6206cb140a51f2e3cc3d7841aed51b0d64d9.zip
Auto merge of #45785 - arielb1:unsafe-fixes, r=eddyb
fixes to MIR effectck

r? @eddyb

beta-nominating because regression (MIR effectck is new)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/issue-45087-unreachable-unsafe.rs15
-rw-r--r--src/test/compile-fail/issue-45729-unsafe-in-generator.rs19
-rw-r--r--src/test/ui/issue-45107-unnecessary-unsafe-in-closure.rs35
-rw-r--r--src/test/ui/issue-45107-unnecessary-unsafe-in-closure.stderr71
-rw-r--r--src/test/ui/span/lint-unused-unsafe.stderr16
5 files changed, 148 insertions, 8 deletions
diff --git a/src/test/compile-fail/issue-45087-unreachable-unsafe.rs b/src/test/compile-fail/issue-45087-unreachable-unsafe.rs
new file mode 100644
index 00000000000..eeb66fa0e2c
--- /dev/null
+++ b/src/test/compile-fail/issue-45087-unreachable-unsafe.rs
@@ -0,0 +1,15 @@
+// Copyright 2017 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.
+
+fn main() {
+    return;
+    *(1 as *mut u32) = 42;
+    //~^ ERROR dereference of raw pointer requires unsafe
+}
diff --git a/src/test/compile-fail/issue-45729-unsafe-in-generator.rs b/src/test/compile-fail/issue-45729-unsafe-in-generator.rs
new file mode 100644
index 00000000000..489e91797f3
--- /dev/null
+++ b/src/test/compile-fail/issue-45729-unsafe-in-generator.rs
@@ -0,0 +1,19 @@
+// Copyright 2017 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(generators)]
+
+fn main() {
+    let _ = || {
+        *(1 as *mut u32) = 42;
+        //~^ ERROR dereference of raw pointer requires unsafe
+        yield;
+    };
+}
diff --git a/src/test/ui/issue-45107-unnecessary-unsafe-in-closure.rs b/src/test/ui/issue-45107-unnecessary-unsafe-in-closure.rs
new file mode 100644
index 00000000000..833fc2802a3
--- /dev/null
+++ b/src/test/ui/issue-45107-unnecessary-unsafe-in-closure.rs
@@ -0,0 +1,35 @@
+// Copyright 2017 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.
+
+#[deny(unused_unsafe)]
+fn main() {
+    let mut v = Vec::<i32>::with_capacity(24);
+
+    unsafe {
+        let f = |v: &mut Vec<_>| {
+            unsafe {
+                v.set_len(24);
+                |w: &mut Vec<u32>| { unsafe {
+                    w.set_len(32);
+                } };
+            }
+            |x: &mut Vec<u32>| { unsafe {
+                x.set_len(40);
+            } };
+        };
+
+        v.set_len(0);
+        f(&mut v);
+    }
+
+    |y: &mut Vec<u32>| { unsafe {
+        y.set_len(48);
+    } };
+}
diff --git a/src/test/ui/issue-45107-unnecessary-unsafe-in-closure.stderr b/src/test/ui/issue-45107-unnecessary-unsafe-in-closure.stderr
new file mode 100644
index 00000000000..5c58b19c7fb
--- /dev/null
+++ b/src/test/ui/issue-45107-unnecessary-unsafe-in-closure.stderr
@@ -0,0 +1,71 @@
+error: unnecessary `unsafe` block
+  --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:17:13
+   |
+17 | /             unsafe {
+18 | |                 v.set_len(24);
+19 | |                 |w: &mut Vec<u32>| { unsafe {
+20 | |                     w.set_len(32);
+21 | |                 } };
+22 | |             }
+   | |_____________^ unnecessary `unsafe` block
+   |
+note: lint level defined here
+  --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:11:8
+   |
+11 | #[deny(unused_unsafe)]
+   |        ^^^^^^^^^^^^^
+note: because it's nested under this `unsafe` block
+  --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:15:5
+   |
+15 | /     unsafe {
+16 | |         let f = |v: &mut Vec<_>| {
+17 | |             unsafe {
+18 | |                 v.set_len(24);
+...  |
+29 | |         f(&mut v);
+30 | |     }
+   | |_____^
+
+error: unnecessary `unsafe` block
+  --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:19:38
+   |
+19 |                   |w: &mut Vec<u32>| { unsafe {
+   |  ______________________________________^
+20 | |                     w.set_len(32);
+21 | |                 } };
+   | |_________________^ unnecessary `unsafe` block
+   |
+note: because it's nested under this `unsafe` block
+  --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:17:13
+   |
+17 | /             unsafe {
+18 | |                 v.set_len(24);
+19 | |                 |w: &mut Vec<u32>| { unsafe {
+20 | |                     w.set_len(32);
+21 | |                 } };
+22 | |             }
+   | |_____________^
+
+error: unnecessary `unsafe` block
+  --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:23:34
+   |
+23 |               |x: &mut Vec<u32>| { unsafe {
+   |  __________________________________^
+24 | |                 x.set_len(40);
+25 | |             } };
+   | |_____________^ unnecessary `unsafe` block
+   |
+note: because it's nested under this `unsafe` block
+  --> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:15:5
+   |
+15 | /     unsafe {
+16 | |         let f = |v: &mut Vec<_>| {
+17 | |             unsafe {
+18 | |                 v.set_len(24);
+...  |
+29 | |         f(&mut v);
+30 | |     }
+   | |_____^
+
+error: aborting due to 6 previous errors
+
diff --git a/src/test/ui/span/lint-unused-unsafe.stderr b/src/test/ui/span/lint-unused-unsafe.stderr
index 1fa5f94aa4c..f4998e08907 100644
--- a/src/test/ui/span/lint-unused-unsafe.stderr
+++ b/src/test/ui/span/lint-unused-unsafe.stderr
@@ -65,12 +65,14 @@ note: because it's nested under this `unsafe` block
    | |_____^
 
 error: unnecessary `unsafe` block
-  --> $DIR/lint-unused-unsafe.rs:40:9
+  --> $DIR/lint-unused-unsafe.rs:39:5
    |
-40 | /         unsafe {                         //~ ERROR: unnecessary `unsafe` block
+39 | /     unsafe {                             //~ ERROR: unnecessary `unsafe` block
+40 | |         unsafe {                         //~ ERROR: unnecessary `unsafe` block
 41 | |             unsf()
 42 | |         }
-   | |_________^ unnecessary `unsafe` block
+43 | |     }
+   | |_____^ unnecessary `unsafe` block
    |
 note: because it's nested under this `unsafe` fn
   --> $DIR/lint-unused-unsafe.rs:38:1
@@ -85,14 +87,12 @@ note: because it's nested under this `unsafe` fn
    | |_^
 
 error: unnecessary `unsafe` block
-  --> $DIR/lint-unused-unsafe.rs:39:5
+  --> $DIR/lint-unused-unsafe.rs:40:9
    |
-39 | /     unsafe {                             //~ ERROR: unnecessary `unsafe` block
-40 | |         unsafe {                         //~ ERROR: unnecessary `unsafe` block
+40 | /         unsafe {                         //~ ERROR: unnecessary `unsafe` block
 41 | |             unsf()
 42 | |         }
-43 | |     }
-   | |_____^ unnecessary `unsafe` block
+   | |_________^ unnecessary `unsafe` block
    |
 note: because it's nested under this `unsafe` fn
   --> $DIR/lint-unused-unsafe.rs:38:1