forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#39202 - estebank:nested-unsafe, r=jonathand…
…turner Point to enclosing block/fn on nested unsafe When declaring nested unsafe blocks (`unsafe {unsafe {}}`) that trigger the "unnecessary `unsafe` block" error, point out the enclosing `unsafe block` or `unsafe fn` that makes it unnecessary. <img width="621" alt="" src="https://cloud.githubusercontent.com/assets/1606434/22139922/26ad468a-de9e-11e6-8884-2945be882ea8.png"> Fixes rust-lang#39144.
- Loading branch information
Showing
3 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
error: unnecessary `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:26:13 | ||
| | ||
26 | fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block | ||
| ^^^^^^^^^ unnecessary `unsafe` block | ||
| | ||
note: lint level defined here | ||
--> $DIR/lint-unused-unsafe.rs:14:9 | ||
| | ||
14 | #![deny(unused_unsafe)] | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: unnecessary `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:27:13 | ||
| | ||
27 | fn bad2() { unsafe { bad1() } } //~ ERROR: unnecessary `unsafe` block | ||
| ^^^^^^^^^^^^^^^^^ unnecessary `unsafe` block | ||
|
||
error: unnecessary `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:28:20 | ||
| | ||
28 | unsafe fn bad3() { unsafe {} } //~ ERROR: unnecessary `unsafe` block | ||
| ^^^^^^^^^ unnecessary `unsafe` block | ||
| | ||
note: because it's nested under this `unsafe` fn | ||
--> $DIR/lint-unused-unsafe.rs:28:1 | ||
| | ||
28 | unsafe fn bad3() { unsafe {} } //~ ERROR: unnecessary `unsafe` block | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: unnecessary `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:29:13 | ||
| | ||
29 | fn bad4() { unsafe { callback(||{}) } } //~ ERROR: unnecessary `unsafe` block | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unnecessary `unsafe` block | ||
|
||
error: unnecessary `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:30:20 | ||
| | ||
30 | unsafe fn bad5() { unsafe { unsf() } } //~ ERROR: unnecessary `unsafe` block | ||
| ^^^^^^^^^^^^^^^^^ unnecessary `unsafe` block | ||
| | ||
note: because it's nested under this `unsafe` fn | ||
--> $DIR/lint-unused-unsafe.rs:30:1 | ||
| | ||
30 | unsafe fn bad5() { unsafe { unsf() } } //~ ERROR: unnecessary `unsafe` block | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: unnecessary `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:33:9 | ||
| | ||
33 | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
| _________^ starting here... | ||
34 | | unsf() | ||
35 | | } | ||
| |_________^ ...ending here: unnecessary `unsafe` block | ||
| | ||
note: because it's nested under this `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:32:5 | ||
| | ||
32 | unsafe { // don't put the warning here | ||
| _____^ starting here... | ||
33 | | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
34 | | unsf() | ||
35 | | } | ||
36 | | } | ||
| |_____^ ...ending here | ||
|
||
error: unnecessary `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:39:5 | ||
| | ||
39 | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
| _____^ starting here... | ||
40 | | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
41 | | unsf() | ||
42 | | } | ||
43 | | } | ||
| |_____^ ...ending here: unnecessary `unsafe` block | ||
| | ||
note: because it's nested under this `unsafe` fn | ||
--> $DIR/lint-unused-unsafe.rs:38:1 | ||
| | ||
38 | unsafe fn bad7() { | ||
| _^ starting here... | ||
39 | | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
40 | | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
41 | | unsf() | ||
42 | | } | ||
43 | | } | ||
44 | | } | ||
| |_^ ...ending here | ||
|
||
error: unnecessary `unsafe` block | ||
--> $DIR/lint-unused-unsafe.rs:40:9 | ||
| | ||
40 | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
| _________^ starting here... | ||
41 | | unsf() | ||
42 | | } | ||
| |_________^ ...ending here: unnecessary `unsafe` block | ||
| | ||
note: because it's nested under this `unsafe` fn | ||
--> $DIR/lint-unused-unsafe.rs:38:1 | ||
| | ||
38 | unsafe fn bad7() { | ||
| _^ starting here... | ||
39 | | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
40 | | unsafe { //~ ERROR: unnecessary `unsafe` block | ||
41 | | unsf() | ||
42 | | } | ||
43 | | } | ||
44 | | } | ||
| |_^ ...ending here | ||
|
||
error: aborting due to 8 previous errors | ||
|