Rollup merge of #46805 - estebank:unnecessary-unsafe-spans, r=arielb1

Tweak "unecessary unsafe block" error spans
This commit is contained in:
Guillaume Gomez 2017-12-18 23:08:38 +01:00 committed by GitHub
commit 325d9fb8f6
3 changed files with 43 additions and 122 deletions

View File

@ -388,12 +388,13 @@ fn is_enclosed(tcx: TyCtxt,
}
fn report_unused_unsafe(tcx: TyCtxt, used_unsafe: &FxHashSet<ast::NodeId>, id: ast::NodeId) {
let span = tcx.hir.span(id);
let mut db = tcx.struct_span_lint_node(UNUSED_UNSAFE, id, span, "unnecessary `unsafe` block");
db.span_label(span, "unnecessary `unsafe` block");
let span = tcx.sess.codemap().def_span(tcx.hir.span(id));
let msg = "unnecessary `unsafe` block";
let mut db = tcx.struct_span_lint_node(UNUSED_UNSAFE, id, span, msg);
db.span_label(span, msg);
if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) {
db.span_note(tcx.hir.span(id),
&format!("because it's nested under this `unsafe` {}", kind));
db.span_label(tcx.sess.codemap().def_span(tcx.hir.span(id)),
format!("because it's nested under this `unsafe` {}", kind));
}
db.emit();
}

View File

@ -1,72 +1,35 @@
error: unnecessary `unsafe` block
--> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:17:13
|
17 | / unsafe { //~ ERROR unnecessary `unsafe`
18 | | v.set_len(24);
19 | | |w: &mut Vec<u32>| { unsafe { //~ ERROR unnecessary `unsafe`
20 | | w.set_len(32);
21 | | } };
22 | | }
| |_____________^ unnecessary `unsafe` block
15 | unsafe {
| ------ because it's nested under this `unsafe` block
16 | let f = |v: &mut Vec<_>| {
17 | unsafe { //~ ERROR unnecessary `unsafe`
| ^^^^^^ 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 { //~ ERROR unnecessary `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 { //~ ERROR unnecessary `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:15:5
|
15 | / unsafe {
16 | | let f = |v: &mut Vec<_>| {
17 | | unsafe { //~ ERROR unnecessary `unsafe`
18 | | v.set_len(24);
... |
29 | | f(&mut v);
30 | | }
| |_____^
15 | unsafe {
| ------ because it's nested under this `unsafe` block
...
19 | |w: &mut Vec<u32>| { unsafe { //~ ERROR unnecessary `unsafe`
| ^^^^^^ unnecessary `unsafe` block
error: unnecessary `unsafe` block
--> $DIR/issue-45107-unnecessary-unsafe-in-closure.rs:23:34
|
23 | |x: &mut Vec<u32>| { unsafe { //~ ERROR unnecessary `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 { //~ ERROR unnecessary `unsafe`
18 | | v.set_len(24);
... |
29 | | f(&mut v);
30 | | }
| |_____^
15 | unsafe {
| ------ because it's nested under this `unsafe` block
...
23 | |x: &mut Vec<u32>| { unsafe { //~ ERROR unnecessary `unsafe`
| ^^^^^^ unnecessary `unsafe` block
error: aborting due to 3 previous errors

View File

@ -2,7 +2,7 @@ error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:26:13
|
26 | fn bad1() { unsafe {} } //~ ERROR: unnecessary `unsafe` block
| ^^^^^^^^^ unnecessary `unsafe` block
| ^^^^^^ unnecessary `unsafe` block
|
note: lint level defined here
--> $DIR/lint-unused-unsafe.rs:14:9
@ -14,97 +14,54 @@ error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:27:13
|
27 | fn bad2() { unsafe { bad1() } } //~ ERROR: unnecessary `unsafe` block
| ^^^^^^^^^^^^^^^^^ 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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ---------------- ^^^^^^ unnecessary `unsafe` block
| |
| because it's nested under this `unsafe` fn
error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:29:13
|
29 | fn bad4() { unsafe { callback(||{}) } } //~ ERROR: unnecessary `unsafe` block
| ^^^^^^^^^^^^^^^^^^^^^^^^^ 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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ---------------- ^^^^^^ unnecessary `unsafe` block
| |
| because it's nested under this `unsafe` fn
error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:33:9
|
33 | / unsafe { //~ ERROR: unnecessary `unsafe` block
34 | | unsf()
35 | | }
| |_________^ 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
33 | | unsafe { //~ ERROR: unnecessary `unsafe` block
34 | | unsf()
35 | | }
36 | | }
| |_____^
32 | unsafe { // don't put the warning here
| ------ because it's nested under this `unsafe` block
33 | unsafe { //~ ERROR: unnecessary `unsafe` block
| ^^^^^^ unnecessary `unsafe` block
error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:39:5
|
39 | / unsafe { //~ ERROR: unnecessary `unsafe` block
40 | | unsafe { //~ ERROR: unnecessary `unsafe` block
41 | | unsf()
42 | | }
43 | | }
| |_____^ 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 | | }
| |_^
38 | unsafe fn bad7() {
| ---------------- because it's nested under this `unsafe` fn
39 | unsafe { //~ ERROR: unnecessary `unsafe` block
| ^^^^^^ unnecessary `unsafe` block
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 | | }
| |_^
38 | unsafe fn bad7() {
| ---------------- because it's nested under this `unsafe` fn
39 | unsafe { //~ ERROR: unnecessary `unsafe` block
40 | unsafe { //~ ERROR: unnecessary `unsafe` block
| ^^^^^^ unnecessary `unsafe` block
error: aborting due to 8 previous errors