collect unused unsafe code
FIXME: de-uglify
This commit is contained in:
parent
cd279a5b98
commit
12aedc833c
10 changed files with 233 additions and 86 deletions
35
src/test/ui/issue-45107-unnecessary-unsafe-in-closure.rs
Normal file
35
src/test/ui/issue-45107-unnecessary-unsafe-in-closure.rs
Normal file
|
|
@ -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);
|
||||
} };
|
||||
}
|
||||
71
src/test/ui/issue-45107-unnecessary-unsafe-in-closure.stderr
Normal file
71
src/test/ui/issue-45107-unnecessary-unsafe-in-closure.stderr
Normal file
|
|
@ -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
|
||||
|
||||
|
|
@ -64,26 +64,6 @@ note: because it's nested under this `unsafe` block
|
|||
36 | | }
|
||||
| |_____^
|
||||
|
||||
error: unnecessary `unsafe` block
|
||||
--> $DIR/lint-unused-unsafe.rs:40:9
|
||||
|
|
||||
40 | / unsafe { //~ ERROR: unnecessary `unsafe` block
|
||||
41 | | unsf()
|
||||
42 | | }
|
||||
| |_________^ unnecessary `unsafe` block
|
||||
|
|
||||
note: because it's nested under this `unsafe` fn
|
||||
--> $DIR/lint-unused-unsafe.rs:38:1
|
||||
|
|
||||
38 | / unsafe fn bad7() {
|
||||
39 | | unsafe { //~ ERROR: unnecessary `unsafe` block
|
||||
40 | | unsafe { //~ ERROR: unnecessary `unsafe` block
|
||||
41 | | unsf()
|
||||
42 | | }
|
||||
43 | | }
|
||||
44 | | }
|
||||
| |_^
|
||||
|
||||
error: unnecessary `unsafe` block
|
||||
--> $DIR/lint-unused-unsafe.rs:39:5
|
||||
|
|
||||
|
|
@ -106,5 +86,25 @@ note: because it's nested under this `unsafe` fn
|
|||
44 | | }
|
||||
| |_^
|
||||
|
||||
error: unnecessary `unsafe` block
|
||||
--> $DIR/lint-unused-unsafe.rs:40:9
|
||||
|
|
||||
40 | / unsafe { //~ ERROR: unnecessary `unsafe` block
|
||||
41 | | unsf()
|
||||
42 | | }
|
||||
| |_________^ unnecessary `unsafe` block
|
||||
|
|
||||
note: because it's nested under this `unsafe` fn
|
||||
--> $DIR/lint-unused-unsafe.rs:38:1
|
||||
|
|
||||
38 | / unsafe fn bad7() {
|
||||
39 | | unsafe { //~ ERROR: unnecessary `unsafe` block
|
||||
40 | | unsafe { //~ ERROR: unnecessary `unsafe` block
|
||||
41 | | unsf()
|
||||
42 | | }
|
||||
43 | | }
|
||||
44 | | }
|
||||
| |_^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue