Skip to content

Commit 4ff32c0

Browse files
committed
Auto merge of #64669 - estebank:unreachable, r=Centril
Use span label instead of note in unreachable lint Fix #64636.
2 parents ef906d0 + 9991d54 commit 4ff32c0

35 files changed

+191
-334
lines changed

src/librustc_typeck/check/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2340,16 +2340,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23402340
// If span arose from a desugaring of `if` or `while`, then it is the condition itself,
23412341
// which diverges, that we are about to lint on. This gives suboptimal diagnostics.
23422342
// Instead, stop here so that the `if`- or `while`-expression's block is linted instead.
2343-
if !span.is_desugaring(DesugaringKind::CondTemporary) {
2343+
if !span.is_desugaring(DesugaringKind::CondTemporary) &&
2344+
!span.is_desugaring(DesugaringKind::Async)
2345+
{
23442346
self.diverges.set(Diverges::WarnedAlways);
23452347

23462348
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
23472349

23482350
let msg = format!("unreachable {}", kind);
23492351
self.tcx().struct_span_lint_hir(lint::builtin::UNREACHABLE_CODE, id, span, &msg)
2350-
.span_note(
2352+
.span_label(span, &msg)
2353+
.span_label(
23512354
orig_span,
2352-
custom_note.unwrap_or("any code following this expression is unreachable")
2355+
custom_note.unwrap_or("any code following this expression is unreachable"),
23532356
)
23542357
.emit();
23552358
}

src/test/ui/dead-code-ret.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
error: unreachable statement
22
--> $DIR/dead-code-ret.rs:7:5
33
|
4+
LL | return;
5+
| ------ any code following this expression is unreachable
46
LL | println!("Paul is dead");
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/dead-code-ret.rs:3:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/dead-code-ret.rs:6:5
14-
|
15-
LL | return;
16-
| ^^^^^^
1714
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1815

1916
error: aborting due to previous error

src/test/ui/if-ret.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ warning: unreachable block in `if` expression
22
--> $DIR/if-ret.rs:6:24
33
|
44
LL | fn foo() { if (return) { } }
5-
| ^^^
5+
| -------- ^^^ unreachable block in `if` expression
6+
| |
7+
| any code following this expression is unreachable
68
|
79
= note: `#[warn(unreachable_code)]` on by default
8-
note: any code following this expression is unreachable
9-
--> $DIR/if-ret.rs:6:15
10-
|
11-
LL | fn foo() { if (return) { } }
12-
| ^^^^^^^^
1310

src/test/ui/issues/issue-2150.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
error: unreachable statement
22
--> $DIR/issue-2150.rs:8:5
33
|
4+
LL | panic!();
5+
| --------- any code following this expression is unreachable
46
LL | for x in &v { i += 1; }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/issue-2150.rs:1:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/issue-2150.rs:7:5
14-
|
15-
LL | panic!();
16-
| ^^^^^^^^^
1714
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1815

1916
error: aborting due to previous error

src/test/ui/issues/issue-7246.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
error: unreachable statement
22
--> $DIR/issue-7246.rs:7:5
33
|
4+
LL | return;
5+
| ------ any code following this expression is unreachable
46
LL | if *ptr::null() {};
5-
| ^^^^^^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/issue-7246.rs:1:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/issue-7246.rs:6:5
14-
|
15-
LL | return;
16-
| ^^^^^^
1714

1815
error: aborting due to previous error
1916

Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
error: unreachable statement
22
--> $DIR/lint-attr-non-item-node.rs:7:9
33
|
4+
LL | break;
5+
| ----- any code following this expression is unreachable
46
LL | "unreachable";
5-
| ^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/lint-attr-non-item-node.rs:4:12
911
|
1012
LL | #[deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/lint-attr-non-item-node.rs:6:9
14-
|
15-
LL | break;
16-
| ^^^^^
1714

1815
error: aborting due to previous error
1916

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// check-pass
2+
// edition:2018
3+
4+
#[allow(dead_code)]
5+
async fn foo () { // unreachable lint doesn't trigger
6+
unimplemented!()
7+
}
8+
9+
fn main() {}

src/test/ui/liveness/liveness-unused.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
warning: unreachable statement
22
--> $DIR/liveness-unused.rs:92:9
33
|
4+
LL | continue;
5+
| -------- any code following this expression is unreachable
46
LL | drop(*x as i32);
5-
| ^^^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/liveness-unused.rs:1:9
911
|
1012
LL | #![warn(unused)]
1113
| ^^^^^^
1214
= note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`
13-
note: any code following this expression is unreachable
14-
--> $DIR/liveness-unused.rs:91:9
15-
|
16-
LL | continue;
17-
| ^^^^^^^^
1815

1916
error: unused variable: `x`
2017
--> $DIR/liveness-unused.rs:8:7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
error: unreachable statement
22
--> $DIR/match-no-arms-unreachable-after.rs:8:5
33
|
4+
LL | match v { }
5+
| ----------- any code following this expression is unreachable
46
LL | let x = 2;
5-
| ^^^^^^^^^^
7+
| ^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/match-no-arms-unreachable-after.rs:2:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/match-no-arms-unreachable-after.rs:7:5
14-
|
15-
LL | match v { }
16-
| ^^^^^^^^^^^
1714

1815
error: aborting due to previous error
1916

src/test/ui/never-assign-dead-code.stderr

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
warning: unreachable statement
22
--> $DIR/never-assign-dead-code.rs:10:5
33
|
4+
LL | let x: ! = panic!("aah");
5+
| ------------- any code following this expression is unreachable
46
LL | drop(x);
5-
| ^^^^^^^^
7+
| ^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/never-assign-dead-code.rs:5:9
911
|
1012
LL | #![warn(unused)]
1113
| ^^^^^^
1214
= note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`
13-
note: any code following this expression is unreachable
14-
--> $DIR/never-assign-dead-code.rs:9:16
15-
|
16-
LL | let x: ! = panic!("aah");
17-
| ^^^^^^^^^^^^^
1815
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1916

2017
warning: unreachable call
2118
--> $DIR/never-assign-dead-code.rs:10:5
2219
|
2320
LL | drop(x);
24-
| ^^^^
25-
|
26-
note: any code following this expression is unreachable
27-
--> $DIR/never-assign-dead-code.rs:10:10
28-
|
29-
LL | drop(x);
30-
| ^
21+
| ^^^^ - any code following this expression is unreachable
22+
| |
23+
| unreachable call
3124

3225
warning: unused variable: `x`
3326
--> $DIR/never-assign-dead-code.rs:9:9

src/test/ui/reachable/expr_add.stderr

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ error: unreachable expression
22
--> $DIR/expr_add.rs:17:13
33
|
44
LL | let x = Foo + return;
5-
| ^^^^^^^^^^^^
5+
| ^^^^^^------
6+
| | |
7+
| | any code following this expression is unreachable
8+
| unreachable expression
69
|
710
note: lint level defined here
811
--> $DIR/expr_add.rs:3:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_add.rs:17:19
14-
|
15-
LL | let x = Foo + return;
16-
| ^^^^^^
1715

1816
error: aborting due to previous error
1917

src/test/ui/reachable/expr_again.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
error: unreachable statement
22
--> $DIR/expr_again.rs:8:9
33
|
4+
LL | continue;
5+
| -------- any code following this expression is unreachable
46
LL | println!("hi");
5-
| ^^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/expr_again.rs:3:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_again.rs:7:9
14-
|
15-
LL | continue;
16-
| ^^^^^^^^
1714
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1815

1916
error: aborting due to previous error

src/test/ui/reachable/expr_array.stderr

+7-13
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,24 @@ error: unreachable expression
22
--> $DIR/expr_array.rs:9:34
33
|
44
LL | let x: [usize; 2] = [return, 22];
5-
| ^^
5+
| ------ ^^ unreachable expression
6+
| |
7+
| any code following this expression is unreachable
68
|
79
note: lint level defined here
810
--> $DIR/expr_array.rs:4:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_array.rs:9:26
14-
|
15-
LL | let x: [usize; 2] = [return, 22];
16-
| ^^^^^^
1714

1815
error: unreachable expression
1916
--> $DIR/expr_array.rs:14:25
2017
|
2118
LL | let x: [usize; 2] = [22, return];
22-
| ^^^^^^^^^^^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/expr_array.rs:14:30
26-
|
27-
LL | let x: [usize; 2] = [22, return];
28-
| ^^^^^^
19+
| ^^^^^------^
20+
| | |
21+
| | any code following this expression is unreachable
22+
| unreachable expression
2923

3024
error: aborting due to 2 previous errors
3125

src/test/ui/reachable/expr_assign.stderr

+10-20
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,32 @@ error: unreachable expression
22
--> $DIR/expr_assign.rs:10:5
33
|
44
LL | x = return;
5-
| ^^^^^^^^^^
5+
| ^^^^------
6+
| | |
7+
| | any code following this expression is unreachable
8+
| unreachable expression
69
|
710
note: lint level defined here
811
--> $DIR/expr_assign.rs:5:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_assign.rs:10:9
14-
|
15-
LL | x = return;
16-
| ^^^^^^
1715

1816
error: unreachable expression
1917
--> $DIR/expr_assign.rs:20:14
2018
|
2119
LL | *p = return;
22-
| ^^^^^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/expr_assign.rs:20:9
26-
|
27-
LL | *p = return;
28-
| ^^
20+
| -- ^^^^^^ unreachable expression
21+
| |
22+
| any code following this expression is unreachable
2923

3024
error: unreachable expression
3125
--> $DIR/expr_assign.rs:26:15
3226
|
3327
LL | *{return; &mut i} = 22;
34-
| ^^^^^^
35-
|
36-
note: any code following this expression is unreachable
37-
--> $DIR/expr_assign.rs:26:7
38-
|
39-
LL | *{return; &mut i} = 22;
40-
| ^^^^^^
28+
| ------ ^^^^^^ unreachable expression
29+
| |
30+
| any code following this expression is unreachable
4131

4232
error: aborting due to 3 previous errors
4333

0 commit comments

Comments
 (0)