Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4ff32c0

Browse files
committedSep 22, 2019
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 3 additions & 6 deletions
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
Lines changed: 3 additions & 6 deletions
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

Lines changed: 6 additions & 13 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 3 additions & 6 deletions
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

Lines changed: 7 additions & 13 deletions
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

Lines changed: 10 additions & 20 deletions
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

‎src/test/ui/reachable/expr_block.stderr

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
error: unreachable expression
22
--> $DIR/expr_block.rs:10:9
33
|
4+
LL | return;
5+
| ------ any code following this expression is unreachable
46
LL | 22
5-
| ^^
7+
| ^^ unreachable expression
68
|
79
note: lint level defined here
810
--> $DIR/expr_block.rs:4:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_block.rs:9:9
14-
|
15-
LL | return;
16-
| ^^^^^^
1714

1815
error: unreachable statement
1916
--> $DIR/expr_block.rs:25:9
2017
|
18+
LL | return;
19+
| ------ any code following this expression is unreachable
2120
LL | println!("foo");
22-
| ^^^^^^^^^^^^^^^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/expr_block.rs:24:9
21+
| ^^^^^^^^^^^^^^^^ unreachable statement
2622
|
27-
LL | return;
28-
| ^^^^^^
2923
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3024

3125
error: aborting due to 2 previous errors

‎src/test/ui/reachable/expr_box.stderr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ error: unreachable expression
22
--> $DIR/expr_box.rs:6:13
33
|
44
LL | let x = box 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_box.rs:3:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_box.rs:6:17
14-
|
15-
LL | let x = box return;
16-
| ^^^^^^
1715

1816
error: aborting due to previous error
1917

‎src/test/ui/reachable/expr_call.stderr

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,23 @@ error: unreachable expression
22
--> $DIR/expr_call.rs:13:17
33
|
44
LL | foo(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_call.rs:5:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_call.rs:13:9
14-
|
15-
LL | foo(return, 22);
16-
| ^^^^^^
1714

1815
error: unreachable call
1916
--> $DIR/expr_call.rs:18:5
2017
|
2118
LL | bar(return);
22-
| ^^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/expr_call.rs:18:9
26-
|
27-
LL | bar(return);
28-
| ^^^^^^
19+
| ^^^ ------ any code following this expression is unreachable
20+
| |
21+
| unreachable call
2922

3023
error: aborting due to 2 previous errors
3124

‎src/test/ui/reachable/expr_cast.stderr

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

1816
error: aborting due to previous error
1917

‎src/test/ui/reachable/expr_if.stderr

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,28 @@ error: unreachable block in `if` expression
22
--> $DIR/expr_if.rs:7:17
33
|
44
LL | if {return} {
5-
| _________________^
5+
| _________------__^
6+
| | |
7+
| | any code following this expression is unreachable
68
LL | | println!("Hello, world!");
79
LL | | }
8-
| |_____^
10+
| |_____^ unreachable block in `if` expression
911
|
1012
note: lint level defined here
1113
--> $DIR/expr_if.rs:4:9
1214
|
1315
LL | #![deny(unreachable_code)]
1416
| ^^^^^^^^^^^^^^^^
15-
note: any code following this expression is unreachable
16-
--> $DIR/expr_if.rs:7:9
17-
|
18-
LL | if {return} {
19-
| ^^^^^^
2017

2118
error: unreachable statement
2219
--> $DIR/expr_if.rs:27:5
2320
|
21+
LL | return;
22+
| ------ any code following this expression is unreachable
23+
...
2424
LL | println!("But I am.");
25-
| ^^^^^^^^^^^^^^^^^^^^^^
25+
| ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
2626
|
27-
note: any code following this expression is unreachable
28-
--> $DIR/expr_if.rs:21:9
29-
|
30-
LL | return;
31-
| ^^^^^^
3227
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3328

3429
error: aborting due to 2 previous errors

‎src/test/ui/reachable/expr_loop.stderr

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,36 @@
11
error: unreachable statement
22
--> $DIR/expr_loop.rs:8:5
33
|
4+
LL | loop { return; }
5+
| ------ any code following this expression is unreachable
46
LL | println!("I am dead.");
5-
| ^^^^^^^^^^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/expr_loop.rs:4:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_loop.rs:7:12
14-
|
15-
LL | loop { 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: unreachable statement
2017
--> $DIR/expr_loop.rs:21:5
2118
|
19+
LL | loop { return; }
20+
| ------ any code following this expression is unreachable
2221
LL | println!("I am dead.");
23-
| ^^^^^^^^^^^^^^^^^^^^^^^
24-
|
25-
note: any code following this expression is unreachable
26-
--> $DIR/expr_loop.rs:20:12
22+
| ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
2723
|
28-
LL | loop { return; }
29-
| ^^^^^^
3024
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3125

3226
error: unreachable statement
3327
--> $DIR/expr_loop.rs:32:5
3428
|
29+
LL | loop { 'middle: loop { loop { break 'middle; } } }
30+
| -------------------------------------------------- any code following this expression is unreachable
3531
LL | println!("I am dead.");
36-
| ^^^^^^^^^^^^^^^^^^^^^^^
32+
| ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
3733
|
38-
note: any code following this expression is unreachable
39-
--> $DIR/expr_loop.rs:31:5
40-
|
41-
LL | loop { 'middle: loop { loop { break 'middle; } } }
42-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4334
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
4435

4536
error: aborting due to 3 previous errors

‎src/test/ui/reachable/expr_match.stderr

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
error: unreachable statement
22
--> $DIR/expr_match.rs:8:5
33
|
4+
LL | match () { () => return }
5+
| ------------------------- any code following this `match` expression is unreachable, as all arms diverge
46
LL | println!("I am dead");
5-
| ^^^^^^^^^^^^^^^^^^^^^^
7+
| ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
68
|
79
note: lint level defined here
810
--> $DIR/expr_match.rs:4:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this `match` expression is unreachable, as all arms diverge
13-
--> $DIR/expr_match.rs:7:5
14-
|
15-
LL | match () { () => 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: unreachable statement
2017
--> $DIR/expr_match.rs:19:5
2118
|
19+
LL | match () { () if false => return, () => return }
20+
| ------------------------------------------------ any code following this `match` expression is unreachable, as all arms diverge
2221
LL | println!("I am dead");
23-
| ^^^^^^^^^^^^^^^^^^^^^^
24-
|
25-
note: any code following this `match` expression is unreachable, as all arms diverge
26-
--> $DIR/expr_match.rs:18:5
22+
| ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
2723
|
28-
LL | match () { () if false => return, () => return }
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3024
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3125

3226
error: aborting due to 2 previous errors

‎src/test/ui/reachable/expr_method.stderr

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,23 @@ error: unreachable expression
22
--> $DIR/expr_method.rs:16:21
33
|
44
LL | Foo.foo(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_method.rs:5:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_method.rs:16:13
14-
|
15-
LL | Foo.foo(return, 22);
16-
| ^^^^^^
1714

1815
error: unreachable call
1916
--> $DIR/expr_method.rs:21:9
2017
|
2118
LL | Foo.bar(return);
22-
| ^^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/expr_method.rs:21:13
26-
|
27-
LL | Foo.bar(return);
28-
| ^^^^^^
19+
| ^^^ ------ any code following this expression is unreachable
20+
| |
21+
| unreachable call
2922

3023
error: aborting due to 2 previous errors
3124

‎src/test/ui/reachable/expr_repeat.stderr

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

1816
error: aborting due to previous error
1917

‎src/test/ui/reachable/expr_return.stderr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ error: unreachable expression
22
--> $DIR/expr_return.rs:10:22
33
|
44
LL | let x = {return {return {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_return.rs:4:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_return.rs:10:30
14-
|
15-
LL | let x = {return {return {return;}}};
16-
| ^^^^^^
1715

1816
error: aborting due to previous error
1917

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
error: unreachable expression
22
--> $DIR/expr_return_in_macro.rs:13:5
33
|
4+
LL | return ()
5+
| --------- any code following this expression is unreachable
6+
...
47
LL | return early_return!();
5-
| ^^^^^^^^^^^^^^^^^^^^^^
8+
| ^^^^^^^^^^^^^^^^^^^^^^ unreachable expression
69
|
710
note: lint level defined here
811
--> $DIR/expr_return_in_macro.rs:4:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_return_in_macro.rs:8:9
14-
|
15-
LL | return ()
16-
| ^^^^^^^^^
17-
...
18-
LL | return early_return!();
19-
| --------------- in this macro invocation
2015

2116
error: aborting due to previous error
2217

‎src/test/ui/reachable/expr_struct.stderr

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,41 @@ error: unreachable expression
22
--> $DIR/expr_struct.rs:14:13
33
|
44
LL | let x = Foo { a: 22, b: 33, ..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_struct.rs:4:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_struct.rs:14:35
14-
|
15-
LL | let x = Foo { a: 22, b: 33, ..return };
16-
| ^^^^^^
1715

1816
error: unreachable expression
1917
--> $DIR/expr_struct.rs:19:33
2018
|
2119
LL | let x = Foo { a: return, b: 33, ..return };
22-
| ^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/expr_struct.rs:19:22
26-
|
27-
LL | let x = Foo { a: return, b: 33, ..return };
28-
| ^^^^^^
20+
| ------ ^^ unreachable expression
21+
| |
22+
| any code following this expression is unreachable
2923

3024
error: unreachable expression
3125
--> $DIR/expr_struct.rs:24:39
3226
|
3327
LL | let x = Foo { a: 22, b: return, ..return };
34-
| ^^^^^^
35-
|
36-
note: any code following this expression is unreachable
37-
--> $DIR/expr_struct.rs:24:29
38-
|
39-
LL | let x = Foo { a: 22, b: return, ..return };
40-
| ^^^^^^
28+
| ------ ^^^^^^ unreachable expression
29+
| |
30+
| any code following this expression is unreachable
4131

4232
error: unreachable expression
4333
--> $DIR/expr_struct.rs:29:13
4434
|
4535
LL | let x = Foo { a: 22, b: return };
46-
| ^^^^^^^^^^^^^^^^^^^^^^^^
47-
|
48-
note: any code following this expression is unreachable
49-
--> $DIR/expr_struct.rs:29:29
50-
|
51-
LL | let x = Foo { a: 22, b: return };
52-
| ^^^^^^
36+
| ^^^^^^^^^^^^^^^^------^^
37+
| | |
38+
| | any code following this expression is unreachable
39+
| unreachable expression
5340

5441
error: aborting due to 4 previous errors
5542

‎src/test/ui/reachable/expr_tup.stderr

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

1815
error: unreachable expression
1916
--> $DIR/expr_tup.rs:14:29
2017
|
2118
LL | let x: (usize, usize) = (2, return);
22-
| ^^^^^^^^^^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/expr_tup.rs:14:33
26-
|
27-
LL | let x: (usize, usize) = (2, 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_type.stderr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ error: unreachable expression
22
--> $DIR/expr_type.rs:9:13
33
|
44
LL | let 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_type.rs:4:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/expr_type.rs:9:14
14-
|
15-
LL | let x = {return}: !;
16-
| ^^^^^^
1715

1816
error: aborting due to previous error
1917

‎src/test/ui/reachable/expr_unary.stderr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@ error: unreachable expression
88
--> $DIR/expr_unary.rs:8:16
99
|
1010
LL | let x: ! = ! { return; };
11-
| ^^^^^^^^^^^^^
11+
| ^^^^------^^^
12+
| | |
13+
| | any code following this expression is unreachable
14+
| unreachable expression
1215
|
1316
note: lint level defined here
1417
--> $DIR/expr_unary.rs:5:9
1518
|
1619
LL | #![deny(unreachable_code)]
1720
| ^^^^^^^^^^^^^^^^
18-
note: any code following this expression is unreachable
19-
--> $DIR/expr_unary.rs:8:20
20-
|
21-
LL | let x: ! = ! { return; };
22-
| ^^^^^^
2321

2422
error: aborting due to 2 previous errors
2523

‎src/test/ui/reachable/expr_while.stderr

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,31 @@ error: unreachable block in `while` expression
22
--> $DIR/expr_while.rs:7:20
33
|
44
LL | while {return} {
5-
| ____________________^
5+
| ____________------__^
6+
| | |
7+
| | any code following this expression is unreachable
68
LL | |
79
LL | | println!("Hello, world!");
810
LL | | }
9-
| |_____^
11+
| |_____^ unreachable block in `while` expression
1012
|
1113
note: lint level defined here
1214
--> $DIR/expr_while.rs:4:9
1315
|
1416
LL | #![deny(unreachable_code)]
1517
| ^^^^^^^^^^^^^^^^
16-
note: any code following this expression is unreachable
17-
--> $DIR/expr_while.rs:7:12
18-
|
19-
LL | while {return} {
20-
| ^^^^^^
2118

2219
error: unreachable block in `while` expression
2320
--> $DIR/expr_while.rs:22:20
2421
|
2522
LL | while {return} {
26-
| ____________________^
23+
| ____________------__^
24+
| | |
25+
| | any code following this expression is unreachable
2726
LL | |
2827
LL | | println!("I am dead.");
2928
LL | | }
30-
| |_____^
31-
|
32-
note: any code following this expression is unreachable
33-
--> $DIR/expr_while.rs:22:12
34-
|
35-
LL | while {return} {
36-
| ^^^^^^
29+
| |_____^ unreachable block in `while` expression
3730

3831
error: aborting due to 2 previous errors
3932

‎src/test/ui/rfc-2497-if-let-chains/protect-precedences.stderr

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ warning: unreachable block in `if` expression
22
--> $DIR/protect-precedences.rs:13:41
33
|
44
LL | if let _ = return true && false {};
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/protect-precedences.rs:13:20
10-
|
11-
LL | if let _ = return true && false {};
12-
| ^^^^^^^^^^^^^^^^^^^^
1310

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
error: unreachable statement
22
--> $DIR/unreachable-code.rs:7:3
33
|
4+
LL | loop{}
5+
| ------ any code following this expression is unreachable
6+
LL |
47
LL | let a = 3;
5-
| ^^^^^^^^^^
8+
| ^^^^^^^^^^ unreachable statement
69
|
710
note: lint level defined here
811
--> $DIR/unreachable-code.rs:1:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/unreachable-code.rs:5:3
14-
|
15-
LL | loop{}
16-
| ^^^^^^
1715

1816
error: aborting due to previous error
1917

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
11
error: unreachable expression
22
--> $DIR/unreachable-in-call.rs:14:10
33
|
4+
LL | call(diverge(),
5+
| --------- any code following this expression is unreachable
46
LL | get_u8());
5-
| ^^^^^^^^
7+
| ^^^^^^^^ unreachable expression
68
|
79
note: lint level defined here
810
--> $DIR/unreachable-in-call.rs:2:9
911
|
1012
LL | #![deny(unreachable_code)]
1113
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/unreachable-in-call.rs:13:10
14-
|
15-
LL | call(diverge(),
16-
| ^^^^^^^^^
1714

1815
error: unreachable call
1916
--> $DIR/unreachable-in-call.rs:17:5
2017
|
2118
LL | call(
22-
| ^^^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/unreachable-in-call.rs:19:9
26-
|
19+
| ^^^^ unreachable call
20+
LL | get_u8(),
2721
LL | diverge());
28-
| ^^^^^^^^^
22+
| --------- any code following this expression is unreachable
2923

3024
error: aborting due to 2 previous errors
3125

‎src/test/ui/unreachable/unreachable-try-pattern.stderr

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@ warning: unreachable expression
22
--> $DIR/unreachable-try-pattern.rs:19:36
33
|
44
LL | let y = (match x { Ok(n) => Ok(n as u32), Err(e) => Err(e) })?;
5-
| ^^^^^^^^
5+
| -^^^^^^^
6+
| |
7+
| unreachable expression
8+
| any code following this expression is unreachable
69
|
710
note: lint level defined here
811
--> $DIR/unreachable-try-pattern.rs:3:9
912
|
1013
LL | #![warn(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/unreachable-try-pattern.rs:19:36
14-
|
15-
LL | let y = (match x { Ok(n) => Ok(n as u32), Err(e) => Err(e) })?;
16-
| ^
1715

1816
warning: unreachable pattern
1917
--> $DIR/unreachable-try-pattern.rs:19:24

‎src/test/ui/unreachable/unwarned-match-on-never.stderr

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,34 @@ error: unreachable expression
22
--> $DIR/unwarned-match-on-never.rs:10:5
33
|
44
LL | match x {}
5-
| ^^^^^^^^^^
5+
| - any code following this expression is unreachable
6+
LL | // But matches in unreachable code are warned.
7+
LL | match x {}
8+
| ^^^^^^^^^^ unreachable expression
69
|
710
note: lint level defined here
811
--> $DIR/unwarned-match-on-never.rs:1:9
912
|
1013
LL | #![deny(unreachable_code)]
1114
| ^^^^^^^^^^^^^^^^
12-
note: any code following this expression is unreachable
13-
--> $DIR/unwarned-match-on-never.rs:8:11
14-
|
15-
LL | match x {}
16-
| ^
1715

1816
error: unreachable arm
1917
--> $DIR/unwarned-match-on-never.rs:15:15
2018
|
21-
LL | () => ()
22-
| ^^
23-
|
24-
note: any code following this expression is unreachable
25-
--> $DIR/unwarned-match-on-never.rs:14:11
26-
|
2719
LL | match (return) {
28-
| ^^^^^^^^
20+
| -------- any code following this expression is unreachable
21+
LL | () => ()
22+
| ^^ unreachable arm
2923

3024
error: unreachable expression
3125
--> $DIR/unwarned-match-on-never.rs:21:5
3226
|
27+
LL | return;
28+
| ------ any code following this expression is unreachable
3329
LL | / match () {
3430
LL | | () => (),
3531
LL | | }
36-
| |_____^
37-
|
38-
note: any code following this expression is unreachable
39-
--> $DIR/unwarned-match-on-never.rs:20:5
40-
|
41-
LL | return;
42-
| ^^^^^^
32+
| |_____^ unreachable expression
4333

4434
error: aborting due to 3 previous errors
4535

0 commit comments

Comments
 (0)
Please sign in to comment.