From ea70fb75672645640303b29e3b4cb41ee7690f53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Sat, 21 Sep 2019 12:33:02 -0700 Subject: [PATCH] Do not trigger unreachable lint in async body and Use span labels --- src/librustc_typeck/check/mod.rs | 9 ++-- src/test/ui/dead-code-ret.stderr | 9 ++-- src/test/ui/if-ret.stderr | 9 ++-- src/test/ui/issues/issue-2150.stderr | 9 ++-- src/test/ui/issues/issue-7246.stderr | 9 ++-- .../ui/lint/lint-attr-non-item-node.stderr | 9 ++-- src/test/ui/lint/unreachable-async-fn.rs | 9 ++++ src/test/ui/liveness/liveness-unused.stderr | 9 ++-- .../match-no-arms-unreachable-after.stderr | 9 ++-- src/test/ui/never-assign-dead-code.stderr | 19 +++------ src/test/ui/reachable/expr_add.stderr | 10 ++--- src/test/ui/reachable/expr_again.stderr | 9 ++-- src/test/ui/reachable/expr_array.stderr | 20 ++++----- src/test/ui/reachable/expr_assign.stderr | 30 +++++--------- src/test/ui/reachable/expr_block.stderr | 20 ++++----- src/test/ui/reachable/expr_box.stderr | 10 ++--- src/test/ui/reachable/expr_call.stderr | 19 +++------ src/test/ui/reachable/expr_cast.stderr | 10 ++--- src/test/ui/reachable/expr_if.stderr | 23 ++++------- src/test/ui/reachable/expr_loop.stderr | 31 +++++--------- src/test/ui/reachable/expr_match.stderr | 20 ++++----- src/test/ui/reachable/expr_method.stderr | 19 +++------ src/test/ui/reachable/expr_repeat.stderr | 10 ++--- src/test/ui/reachable/expr_return.stderr | 10 ++--- .../ui/reachable/expr_return_in_macro.stderr | 13 ++---- src/test/ui/reachable/expr_struct.stderr | 41 +++++++------------ src/test/ui/reachable/expr_tup.stderr | 20 ++++----- src/test/ui/reachable/expr_type.stderr | 10 ++--- src/test/ui/reachable/expr_unary.stderr | 10 ++--- src/test/ui/reachable/expr_while.stderr | 23 ++++------- .../protect-precedences.stderr | 9 ++-- .../ui/unreachable/unreachable-code.stderr | 10 ++--- .../ui/unreachable/unreachable-in-call.stderr | 18 +++----- .../unreachable-try-pattern.stderr | 10 ++--- .../unwarned-match-on-never.stderr | 30 +++++--------- 35 files changed, 196 insertions(+), 339 deletions(-) create mode 100644 src/test/ui/lint/unreachable-async-fn.rs diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 0eeeee01c82..5d8d5880c0f 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2340,16 +2340,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // If span arose from a desugaring of `if` or `while`, then it is the condition itself, // which diverges, that we are about to lint on. This gives suboptimal diagnostics. // Instead, stop here so that the `if`- or `while`-expression's block is linted instead. - if !span.is_desugaring(DesugaringKind::CondTemporary) { + if !span.is_desugaring(DesugaringKind::CondTemporary) && + !span.is_desugaring(DesugaringKind::Async) + { self.diverges.set(Diverges::WarnedAlways); debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind); let msg = format!("unreachable {}", kind); self.tcx().struct_span_lint_hir(lint::builtin::UNREACHABLE_CODE, id, span, &msg) - .span_note( + .span_label(span, &msg) + .span_label( orig_span, - custom_note.unwrap_or("any code following this expression is unreachable") + custom_note.unwrap_or("any code following this expression is unreachable"), ) .emit(); } diff --git a/src/test/ui/dead-code-ret.stderr b/src/test/ui/dead-code-ret.stderr index 0ce31ea40dd..83841131599 100644 --- a/src/test/ui/dead-code-ret.stderr +++ b/src/test/ui/dead-code-ret.stderr @@ -1,19 +1,16 @@ error: unreachable statement --> $DIR/dead-code-ret.rs:7:5 | +LL | return; + | ------ any code following this expression is unreachable LL | println!("Paul is dead"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/dead-code-ret.rs:3:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/dead-code-ret.rs:6:5 - | -LL | return; - | ^^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/if-ret.stderr b/src/test/ui/if-ret.stderr index 2df8f22944e..58cc7076054 100644 --- a/src/test/ui/if-ret.stderr +++ b/src/test/ui/if-ret.stderr @@ -2,12 +2,9 @@ warning: unreachable block in `if` expression --> $DIR/if-ret.rs:6:24 | LL | fn foo() { if (return) { } } - | ^^^ + | -------- ^^^ unreachable block in `if` expression + | | + | any code following this expression is unreachable | = note: `#[warn(unreachable_code)]` on by default -note: any code following this expression is unreachable - --> $DIR/if-ret.rs:6:15 - | -LL | fn foo() { if (return) { } } - | ^^^^^^^^ diff --git a/src/test/ui/issues/issue-2150.stderr b/src/test/ui/issues/issue-2150.stderr index 623f098d0b3..6e102ecb62f 100644 --- a/src/test/ui/issues/issue-2150.stderr +++ b/src/test/ui/issues/issue-2150.stderr @@ -1,19 +1,16 @@ error: unreachable statement --> $DIR/issue-2150.rs:8:5 | +LL | panic!(); + | --------- any code following this expression is unreachable LL | for x in &v { i += 1; } - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/issue-2150.rs:1:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/issue-2150.rs:7:5 - | -LL | panic!(); - | ^^^^^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/issues/issue-7246.stderr b/src/test/ui/issues/issue-7246.stderr index d1b23672dc7..a11ce1654ca 100644 --- a/src/test/ui/issues/issue-7246.stderr +++ b/src/test/ui/issues/issue-7246.stderr @@ -1,19 +1,16 @@ error: unreachable statement --> $DIR/issue-7246.rs:7:5 | +LL | return; + | ------ any code following this expression is unreachable LL | if *ptr::null() {}; - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/issue-7246.rs:1:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/issue-7246.rs:6:5 - | -LL | return; - | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/lint/lint-attr-non-item-node.stderr b/src/test/ui/lint/lint-attr-non-item-node.stderr index e6c76c24c91..0d428c256e7 100644 --- a/src/test/ui/lint/lint-attr-non-item-node.stderr +++ b/src/test/ui/lint/lint-attr-non-item-node.stderr @@ -1,19 +1,16 @@ error: unreachable statement --> $DIR/lint-attr-non-item-node.rs:7:9 | +LL | break; + | ----- any code following this expression is unreachable LL | "unreachable"; - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/lint-attr-non-item-node.rs:4:12 | LL | #[deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/lint-attr-non-item-node.rs:6:9 - | -LL | break; - | ^^^^^ error: aborting due to previous error diff --git a/src/test/ui/lint/unreachable-async-fn.rs b/src/test/ui/lint/unreachable-async-fn.rs new file mode 100644 index 00000000000..6e09c3136b5 --- /dev/null +++ b/src/test/ui/lint/unreachable-async-fn.rs @@ -0,0 +1,9 @@ +// run-pass +// edition:2018 +#[allow(dead_code)] + +async fn foo () { // unreachable lint doesn't trigger + unimplemented!() +} + +fn main() {} diff --git a/src/test/ui/liveness/liveness-unused.stderr b/src/test/ui/liveness/liveness-unused.stderr index 84e9b5bab99..6ea20081e50 100644 --- a/src/test/ui/liveness/liveness-unused.stderr +++ b/src/test/ui/liveness/liveness-unused.stderr @@ -1,8 +1,10 @@ warning: unreachable statement --> $DIR/liveness-unused.rs:92:9 | +LL | continue; + | -------- any code following this expression is unreachable LL | drop(*x as i32); - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/liveness-unused.rs:1:9 @@ -10,11 +12,6 @@ note: lint level defined here LL | #![warn(unused)] | ^^^^^^ = note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]` -note: any code following this expression is unreachable - --> $DIR/liveness-unused.rs:91:9 - | -LL | continue; - | ^^^^^^^^ error: unused variable: `x` --> $DIR/liveness-unused.rs:8:7 diff --git a/src/test/ui/match/match-no-arms-unreachable-after.stderr b/src/test/ui/match/match-no-arms-unreachable-after.stderr index 6c46b2473cc..66e5c91ad20 100644 --- a/src/test/ui/match/match-no-arms-unreachable-after.stderr +++ b/src/test/ui/match/match-no-arms-unreachable-after.stderr @@ -1,19 +1,16 @@ error: unreachable statement --> $DIR/match-no-arms-unreachable-after.rs:8:5 | +LL | match v { } + | ----------- any code following this expression is unreachable LL | let x = 2; - | ^^^^^^^^^^ + | ^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/match-no-arms-unreachable-after.rs:2:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/match-no-arms-unreachable-after.rs:7:5 - | -LL | match v { } - | ^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/never-assign-dead-code.stderr b/src/test/ui/never-assign-dead-code.stderr index 436c703e4b6..b887d580e68 100644 --- a/src/test/ui/never-assign-dead-code.stderr +++ b/src/test/ui/never-assign-dead-code.stderr @@ -1,8 +1,10 @@ warning: unreachable statement --> $DIR/never-assign-dead-code.rs:10:5 | +LL | let x: ! = panic!("aah"); + | ------------- any code following this expression is unreachable LL | drop(x); - | ^^^^^^^^ + | ^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/never-assign-dead-code.rs:5:9 @@ -10,24 +12,15 @@ note: lint level defined here LL | #![warn(unused)] | ^^^^^^ = note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]` -note: any code following this expression is unreachable - --> $DIR/never-assign-dead-code.rs:9:16 - | -LL | let x: ! = panic!("aah"); - | ^^^^^^^^^^^^^ = note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) warning: unreachable call --> $DIR/never-assign-dead-code.rs:10:5 | LL | drop(x); - | ^^^^ - | -note: any code following this expression is unreachable - --> $DIR/never-assign-dead-code.rs:10:10 - | -LL | drop(x); - | ^ + | ^^^^ - any code following this expression is unreachable + | | + | unreachable call warning: unused variable: `x` --> $DIR/never-assign-dead-code.rs:9:9 diff --git a/src/test/ui/reachable/expr_add.stderr b/src/test/ui/reachable/expr_add.stderr index 47b4e467abe..880dea1cc35 100644 --- a/src/test/ui/reachable/expr_add.stderr +++ b/src/test/ui/reachable/expr_add.stderr @@ -2,18 +2,16 @@ error: unreachable expression --> $DIR/expr_add.rs:17:13 | LL | let x = Foo + return; - | ^^^^^^^^^^^^ + | ^^^^^^------ + | | | + | | any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_add.rs:3:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_add.rs:17:19 - | -LL | let x = Foo + return; - | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/reachable/expr_again.stderr b/src/test/ui/reachable/expr_again.stderr index 8e246d940fd..95006884242 100644 --- a/src/test/ui/reachable/expr_again.stderr +++ b/src/test/ui/reachable/expr_again.stderr @@ -1,19 +1,16 @@ error: unreachable statement --> $DIR/expr_again.rs:8:9 | +LL | continue; + | -------- any code following this expression is unreachable LL | println!("hi"); - | ^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/expr_again.rs:3:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_again.rs:7:9 - | -LL | continue; - | ^^^^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/reachable/expr_array.stderr b/src/test/ui/reachable/expr_array.stderr index 419a332e632..b3138d3c33f 100644 --- a/src/test/ui/reachable/expr_array.stderr +++ b/src/test/ui/reachable/expr_array.stderr @@ -2,30 +2,24 @@ error: unreachable expression --> $DIR/expr_array.rs:9:34 | LL | let x: [usize; 2] = [return, 22]; - | ^^ + | ------ ^^ unreachable expression + | | + | any code following this expression is unreachable | note: lint level defined here --> $DIR/expr_array.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_array.rs:9:26 - | -LL | let x: [usize; 2] = [return, 22]; - | ^^^^^^ error: unreachable expression --> $DIR/expr_array.rs:14:25 | LL | let x: [usize; 2] = [22, return]; - | ^^^^^^^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_array.rs:14:30 - | -LL | let x: [usize; 2] = [22, return]; - | ^^^^^^ + | ^^^^^------^ + | | | + | | any code following this expression is unreachable + | unreachable expression error: aborting due to 2 previous errors diff --git a/src/test/ui/reachable/expr_assign.stderr b/src/test/ui/reachable/expr_assign.stderr index 7388fb4a6b9..3004da04063 100644 --- a/src/test/ui/reachable/expr_assign.stderr +++ b/src/test/ui/reachable/expr_assign.stderr @@ -2,42 +2,32 @@ error: unreachable expression --> $DIR/expr_assign.rs:10:5 | LL | x = return; - | ^^^^^^^^^^ + | ^^^^------ + | | | + | | any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_assign.rs:5:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_assign.rs:10:9 - | -LL | x = return; - | ^^^^^^ error: unreachable expression --> $DIR/expr_assign.rs:20:14 | LL | *p = return; - | ^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_assign.rs:20:9 - | -LL | *p = return; - | ^^ + | -- ^^^^^^ unreachable expression + | | + | any code following this expression is unreachable error: unreachable expression --> $DIR/expr_assign.rs:26:15 | LL | *{return; &mut i} = 22; - | ^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_assign.rs:26:7 - | -LL | *{return; &mut i} = 22; - | ^^^^^^ + | ------ ^^^^^^ unreachable expression + | | + | any code following this expression is unreachable error: aborting due to 3 previous errors diff --git a/src/test/ui/reachable/expr_block.stderr b/src/test/ui/reachable/expr_block.stderr index 03a6139d688..44baddd1e55 100644 --- a/src/test/ui/reachable/expr_block.stderr +++ b/src/test/ui/reachable/expr_block.stderr @@ -1,31 +1,25 @@ error: unreachable expression --> $DIR/expr_block.rs:10:9 | +LL | return; + | ------ any code following this expression is unreachable LL | 22 - | ^^ + | ^^ unreachable expression | note: lint level defined here --> $DIR/expr_block.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_block.rs:9:9 - | -LL | return; - | ^^^^^^ error: unreachable statement --> $DIR/expr_block.rs:25:9 | -LL | println!("foo"); - | ^^^^^^^^^^^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_block.rs:24:9 - | LL | return; - | ^^^^^^ + | ------ any code following this expression is unreachable +LL | println!("foo"); + | ^^^^^^^^^^^^^^^^ unreachable statement + | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/reachable/expr_box.stderr b/src/test/ui/reachable/expr_box.stderr index d0f666d2be4..b01a13e9df2 100644 --- a/src/test/ui/reachable/expr_box.stderr +++ b/src/test/ui/reachable/expr_box.stderr @@ -2,18 +2,16 @@ error: unreachable expression --> $DIR/expr_box.rs:6:13 | LL | let x = box return; - | ^^^^^^^^^^ + | ^^^^------ + | | | + | | any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_box.rs:3:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_box.rs:6:17 - | -LL | let x = box return; - | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/reachable/expr_call.stderr b/src/test/ui/reachable/expr_call.stderr index 3fcea90e7cd..ae8b4dd87b5 100644 --- a/src/test/ui/reachable/expr_call.stderr +++ b/src/test/ui/reachable/expr_call.stderr @@ -2,30 +2,23 @@ error: unreachable expression --> $DIR/expr_call.rs:13:17 | LL | foo(return, 22); - | ^^ + | ------ ^^ unreachable expression + | | + | any code following this expression is unreachable | note: lint level defined here --> $DIR/expr_call.rs:5:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_call.rs:13:9 - | -LL | foo(return, 22); - | ^^^^^^ error: unreachable call --> $DIR/expr_call.rs:18:5 | LL | bar(return); - | ^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_call.rs:18:9 - | -LL | bar(return); - | ^^^^^^ + | ^^^ ------ any code following this expression is unreachable + | | + | unreachable call error: aborting due to 2 previous errors diff --git a/src/test/ui/reachable/expr_cast.stderr b/src/test/ui/reachable/expr_cast.stderr index d3ce0ca079f..81813d1d71c 100644 --- a/src/test/ui/reachable/expr_cast.stderr +++ b/src/test/ui/reachable/expr_cast.stderr @@ -2,18 +2,16 @@ error: unreachable expression --> $DIR/expr_cast.rs:9:13 | LL | let x = {return} as !; - | ^^^^^^^^^^^^^ + | ^------^^^^^^ + | || + | |any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_cast.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_cast.rs:9:14 - | -LL | let x = {return} as !; - | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/reachable/expr_if.stderr b/src/test/ui/reachable/expr_if.stderr index 03284576086..ccd45ccec62 100644 --- a/src/test/ui/reachable/expr_if.stderr +++ b/src/test/ui/reachable/expr_if.stderr @@ -2,33 +2,28 @@ error: unreachable block in `if` expression --> $DIR/expr_if.rs:7:17 | LL | if {return} { - | _________________^ + | _________------__^ + | | | + | | any code following this expression is unreachable LL | | println!("Hello, world!"); LL | | } - | |_____^ + | |_____^ unreachable block in `if` expression | note: lint level defined here --> $DIR/expr_if.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_if.rs:7:9 - | -LL | if {return} { - | ^^^^^^ error: unreachable statement --> $DIR/expr_if.rs:27:5 | -LL | println!("But I am."); - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_if.rs:21:9 - | LL | return; - | ^^^^^^ + | ------ any code following this expression is unreachable +... +LL | println!("But I am."); + | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/reachable/expr_loop.stderr b/src/test/ui/reachable/expr_loop.stderr index a4cf8cfcfd9..5f279c9630d 100644 --- a/src/test/ui/reachable/expr_loop.stderr +++ b/src/test/ui/reachable/expr_loop.stderr @@ -1,45 +1,36 @@ error: unreachable statement --> $DIR/expr_loop.rs:8:5 | +LL | loop { return; } + | ------ any code following this expression is unreachable LL | println!("I am dead."); - | ^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/expr_loop.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_loop.rs:7:12 - | -LL | loop { return; } - | ^^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: unreachable statement --> $DIR/expr_loop.rs:21:5 | -LL | println!("I am dead."); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_loop.rs:20:12 - | LL | loop { return; } - | ^^^^^^ + | ------ any code following this expression is unreachable +LL | println!("I am dead."); + | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: unreachable statement --> $DIR/expr_loop.rs:32:5 | -LL | println!("I am dead."); - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_loop.rs:31:5 - | LL | loop { 'middle: loop { loop { break 'middle; } } } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | -------------------------------------------------- any code following this expression is unreachable +LL | println!("I am dead."); + | ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to 3 previous errors diff --git a/src/test/ui/reachable/expr_match.stderr b/src/test/ui/reachable/expr_match.stderr index f587e524d35..d39acdc2909 100644 --- a/src/test/ui/reachable/expr_match.stderr +++ b/src/test/ui/reachable/expr_match.stderr @@ -1,32 +1,26 @@ error: unreachable statement --> $DIR/expr_match.rs:8:5 | +LL | match () { () => return } + | ------------------------- any code following this `match` expression is unreachable, as all arms diverge LL | println!("I am dead"); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/expr_match.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this `match` expression is unreachable, as all arms diverge - --> $DIR/expr_match.rs:7:5 - | -LL | match () { () => return } - | ^^^^^^^^^^^^^^^^^^^^^^^^^ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: unreachable statement --> $DIR/expr_match.rs:19:5 | -LL | println!("I am dead"); - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: any code following this `match` expression is unreachable, as all arms diverge - --> $DIR/expr_match.rs:18:5 - | LL | match () { () if false => return, () => return } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ------------------------------------------------ any code following this `match` expression is unreachable, as all arms diverge +LL | println!("I am dead"); + | ^^^^^^^^^^^^^^^^^^^^^^ unreachable statement + | = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to 2 previous errors diff --git a/src/test/ui/reachable/expr_method.stderr b/src/test/ui/reachable/expr_method.stderr index 7ad279c9f48..82a0745f062 100644 --- a/src/test/ui/reachable/expr_method.stderr +++ b/src/test/ui/reachable/expr_method.stderr @@ -2,30 +2,23 @@ error: unreachable expression --> $DIR/expr_method.rs:16:21 | LL | Foo.foo(return, 22); - | ^^ + | ------ ^^ unreachable expression + | | + | any code following this expression is unreachable | note: lint level defined here --> $DIR/expr_method.rs:5:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_method.rs:16:13 - | -LL | Foo.foo(return, 22); - | ^^^^^^ error: unreachable call --> $DIR/expr_method.rs:21:9 | LL | Foo.bar(return); - | ^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_method.rs:21:13 - | -LL | Foo.bar(return); - | ^^^^^^ + | ^^^ ------ any code following this expression is unreachable + | | + | unreachable call error: aborting due to 2 previous errors diff --git a/src/test/ui/reachable/expr_repeat.stderr b/src/test/ui/reachable/expr_repeat.stderr index 3ff6be76dae..34129936fd7 100644 --- a/src/test/ui/reachable/expr_repeat.stderr +++ b/src/test/ui/reachable/expr_repeat.stderr @@ -2,18 +2,16 @@ error: unreachable expression --> $DIR/expr_repeat.rs:9:25 | LL | let x: [usize; 2] = [return; 2]; - | ^^^^^^^^^^^ + | ^------^^^^ + | || + | |any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_repeat.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_repeat.rs:9:26 - | -LL | let x: [usize; 2] = [return; 2]; - | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/reachable/expr_return.stderr b/src/test/ui/reachable/expr_return.stderr index 31f7ebe7618..c0a94746d08 100644 --- a/src/test/ui/reachable/expr_return.stderr +++ b/src/test/ui/reachable/expr_return.stderr @@ -2,18 +2,16 @@ error: unreachable expression --> $DIR/expr_return.rs:10:22 | LL | let x = {return {return {return;}}}; - | ^^^^^^^^^^^^^^^^ + | ^^^^^^^^------^^ + | | | + | | any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_return.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_return.rs:10:30 - | -LL | let x = {return {return {return;}}}; - | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/reachable/expr_return_in_macro.stderr b/src/test/ui/reachable/expr_return_in_macro.stderr index ff3abb5551f..2bc6a763cfa 100644 --- a/src/test/ui/reachable/expr_return_in_macro.stderr +++ b/src/test/ui/reachable/expr_return_in_macro.stderr @@ -1,22 +1,17 @@ error: unreachable expression --> $DIR/expr_return_in_macro.rs:13:5 | +LL | return () + | --------- any code following this expression is unreachable +... LL | return early_return!(); - | ^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ unreachable expression | note: lint level defined here --> $DIR/expr_return_in_macro.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_return_in_macro.rs:8:9 - | -LL | return () - | ^^^^^^^^^ -... -LL | return early_return!(); - | --------------- in this macro invocation error: aborting due to previous error diff --git a/src/test/ui/reachable/expr_struct.stderr b/src/test/ui/reachable/expr_struct.stderr index d08bcc4f0d1..b3ca06eada3 100644 --- a/src/test/ui/reachable/expr_struct.stderr +++ b/src/test/ui/reachable/expr_struct.stderr @@ -2,54 +2,41 @@ error: unreachable expression --> $DIR/expr_struct.rs:14:13 | LL | let x = Foo { a: 22, b: 33, ..return }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^------^^ + | | | + | | any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_struct.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_struct.rs:14:35 - | -LL | let x = Foo { a: 22, b: 33, ..return }; - | ^^^^^^ error: unreachable expression --> $DIR/expr_struct.rs:19:33 | LL | let x = Foo { a: return, b: 33, ..return }; - | ^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_struct.rs:19:22 - | -LL | let x = Foo { a: return, b: 33, ..return }; - | ^^^^^^ + | ------ ^^ unreachable expression + | | + | any code following this expression is unreachable error: unreachable expression --> $DIR/expr_struct.rs:24:39 | LL | let x = Foo { a: 22, b: return, ..return }; - | ^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_struct.rs:24:29 - | -LL | let x = Foo { a: 22, b: return, ..return }; - | ^^^^^^ + | ------ ^^^^^^ unreachable expression + | | + | any code following this expression is unreachable error: unreachable expression --> $DIR/expr_struct.rs:29:13 | LL | let x = Foo { a: 22, b: return }; - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_struct.rs:29:29 - | -LL | let x = Foo { a: 22, b: return }; - | ^^^^^^ + | ^^^^^^^^^^^^^^^^------^^ + | | | + | | any code following this expression is unreachable + | unreachable expression error: aborting due to 4 previous errors diff --git a/src/test/ui/reachable/expr_tup.stderr b/src/test/ui/reachable/expr_tup.stderr index 788499533db..aaaf6462da8 100644 --- a/src/test/ui/reachable/expr_tup.stderr +++ b/src/test/ui/reachable/expr_tup.stderr @@ -2,30 +2,24 @@ error: unreachable expression --> $DIR/expr_tup.rs:9:38 | LL | let x: (usize, usize) = (return, 2); - | ^ + | ------ ^ unreachable expression + | | + | any code following this expression is unreachable | note: lint level defined here --> $DIR/expr_tup.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_tup.rs:9:30 - | -LL | let x: (usize, usize) = (return, 2); - | ^^^^^^ error: unreachable expression --> $DIR/expr_tup.rs:14:29 | LL | let x: (usize, usize) = (2, return); - | ^^^^^^^^^^^ - | -note: any code following this expression is unreachable - --> $DIR/expr_tup.rs:14:33 - | -LL | let x: (usize, usize) = (2, return); - | ^^^^^^ + | ^^^^------^ + | | | + | | any code following this expression is unreachable + | unreachable expression error: aborting due to 2 previous errors diff --git a/src/test/ui/reachable/expr_type.stderr b/src/test/ui/reachable/expr_type.stderr index 15eb735da75..cb6e8d7039f 100644 --- a/src/test/ui/reachable/expr_type.stderr +++ b/src/test/ui/reachable/expr_type.stderr @@ -2,18 +2,16 @@ error: unreachable expression --> $DIR/expr_type.rs:9:13 | LL | let x = {return}: !; - | ^^^^^^^^^^^ + | ^------^^^^ + | || + | |any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_type.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_type.rs:9:14 - | -LL | let x = {return}: !; - | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/reachable/expr_unary.stderr b/src/test/ui/reachable/expr_unary.stderr index 7f865196166..f5c3564217b 100644 --- a/src/test/ui/reachable/expr_unary.stderr +++ b/src/test/ui/reachable/expr_unary.stderr @@ -8,18 +8,16 @@ error: unreachable expression --> $DIR/expr_unary.rs:8:16 | LL | let x: ! = ! { return; }; - | ^^^^^^^^^^^^^ + | ^^^^------^^^ + | | | + | | any code following this expression is unreachable + | unreachable expression | note: lint level defined here --> $DIR/expr_unary.rs:5:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_unary.rs:8:20 - | -LL | let x: ! = ! { return; }; - | ^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/reachable/expr_while.stderr b/src/test/ui/reachable/expr_while.stderr index b6d6d11ac69..edb1dd2b9bc 100644 --- a/src/test/ui/reachable/expr_while.stderr +++ b/src/test/ui/reachable/expr_while.stderr @@ -2,38 +2,31 @@ error: unreachable block in `while` expression --> $DIR/expr_while.rs:7:20 | LL | while {return} { - | ____________________^ + | ____________------__^ + | | | + | | any code following this expression is unreachable LL | | LL | | println!("Hello, world!"); LL | | } - | |_____^ + | |_____^ unreachable block in `while` expression | note: lint level defined here --> $DIR/expr_while.rs:4:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/expr_while.rs:7:12 - | -LL | while {return} { - | ^^^^^^ error: unreachable block in `while` expression --> $DIR/expr_while.rs:22:20 | LL | while {return} { - | ____________________^ + | ____________------__^ + | | | + | | any code following this expression is unreachable LL | | LL | | println!("I am dead."); LL | | } - | |_____^ - | -note: any code following this expression is unreachable - --> $DIR/expr_while.rs:22:12 - | -LL | while {return} { - | ^^^^^^ + | |_____^ unreachable block in `while` expression error: aborting due to 2 previous errors diff --git a/src/test/ui/rfc-2497-if-let-chains/protect-precedences.stderr b/src/test/ui/rfc-2497-if-let-chains/protect-precedences.stderr index ca98a394714..cf8f0e98305 100644 --- a/src/test/ui/rfc-2497-if-let-chains/protect-precedences.stderr +++ b/src/test/ui/rfc-2497-if-let-chains/protect-precedences.stderr @@ -2,12 +2,9 @@ warning: unreachable block in `if` expression --> $DIR/protect-precedences.rs:13:41 | LL | if let _ = return true && false {}; - | ^^ + | -------------------- ^^ unreachable block in `if` expression + | | + | any code following this expression is unreachable | = note: `#[warn(unreachable_code)]` on by default -note: any code following this expression is unreachable - --> $DIR/protect-precedences.rs:13:20 - | -LL | if let _ = return true && false {}; - | ^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/unreachable/unreachable-code.stderr b/src/test/ui/unreachable/unreachable-code.stderr index 226f088c63a..184440db5df 100644 --- a/src/test/ui/unreachable/unreachable-code.stderr +++ b/src/test/ui/unreachable/unreachable-code.stderr @@ -1,19 +1,17 @@ error: unreachable statement --> $DIR/unreachable-code.rs:7:3 | +LL | loop{} + | ------ any code following this expression is unreachable +LL | LL | let a = 3; - | ^^^^^^^^^^ + | ^^^^^^^^^^ unreachable statement | note: lint level defined here --> $DIR/unreachable-code.rs:1:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/unreachable-code.rs:5:3 - | -LL | loop{} - | ^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/unreachable/unreachable-in-call.stderr b/src/test/ui/unreachable/unreachable-in-call.stderr index 928f5634a12..1d081d1c762 100644 --- a/src/test/ui/unreachable/unreachable-in-call.stderr +++ b/src/test/ui/unreachable/unreachable-in-call.stderr @@ -1,31 +1,25 @@ error: unreachable expression --> $DIR/unreachable-in-call.rs:14:10 | +LL | call(diverge(), + | --------- any code following this expression is unreachable LL | get_u8()); - | ^^^^^^^^ + | ^^^^^^^^ unreachable expression | note: lint level defined here --> $DIR/unreachable-in-call.rs:2:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/unreachable-in-call.rs:13:10 - | -LL | call(diverge(), - | ^^^^^^^^^ error: unreachable call --> $DIR/unreachable-in-call.rs:17:5 | LL | call( - | ^^^^ - | -note: any code following this expression is unreachable - --> $DIR/unreachable-in-call.rs:19:9 - | + | ^^^^ unreachable call +LL | get_u8(), LL | diverge()); - | ^^^^^^^^^ + | --------- any code following this expression is unreachable error: aborting due to 2 previous errors diff --git a/src/test/ui/unreachable/unreachable-try-pattern.stderr b/src/test/ui/unreachable/unreachable-try-pattern.stderr index 889df790124..707038442a2 100644 --- a/src/test/ui/unreachable/unreachable-try-pattern.stderr +++ b/src/test/ui/unreachable/unreachable-try-pattern.stderr @@ -2,18 +2,16 @@ warning: unreachable expression --> $DIR/unreachable-try-pattern.rs:19:36 | LL | let y = (match x { Ok(n) => Ok(n as u32), Err(e) => Err(e) })?; - | ^^^^^^^^ + | -^^^^^^^ + | | + | unreachable expression + | any code following this expression is unreachable | note: lint level defined here --> $DIR/unreachable-try-pattern.rs:3:9 | LL | #![warn(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/unreachable-try-pattern.rs:19:36 - | -LL | let y = (match x { Ok(n) => Ok(n as u32), Err(e) => Err(e) })?; - | ^ warning: unreachable pattern --> $DIR/unreachable-try-pattern.rs:19:24 diff --git a/src/test/ui/unreachable/unwarned-match-on-never.stderr b/src/test/ui/unreachable/unwarned-match-on-never.stderr index 9ce6e3df804..6b2fb4a33c1 100644 --- a/src/test/ui/unreachable/unwarned-match-on-never.stderr +++ b/src/test/ui/unreachable/unwarned-match-on-never.stderr @@ -2,44 +2,34 @@ error: unreachable expression --> $DIR/unwarned-match-on-never.rs:10:5 | LL | match x {} - | ^^^^^^^^^^ + | - any code following this expression is unreachable +LL | // But matches in unreachable code are warned. +LL | match x {} + | ^^^^^^^^^^ unreachable expression | note: lint level defined here --> $DIR/unwarned-match-on-never.rs:1:9 | LL | #![deny(unreachable_code)] | ^^^^^^^^^^^^^^^^ -note: any code following this expression is unreachable - --> $DIR/unwarned-match-on-never.rs:8:11 - | -LL | match x {} - | ^ error: unreachable arm --> $DIR/unwarned-match-on-never.rs:15:15 | -LL | () => () - | ^^ - | -note: any code following this expression is unreachable - --> $DIR/unwarned-match-on-never.rs:14:11 - | LL | match (return) { - | ^^^^^^^^ + | -------- any code following this expression is unreachable +LL | () => () + | ^^ unreachable arm error: unreachable expression --> $DIR/unwarned-match-on-never.rs:21:5 | +LL | return; + | ------ any code following this expression is unreachable LL | / match () { LL | | () => (), LL | | } - | |_____^ - | -note: any code following this expression is unreachable - --> $DIR/unwarned-match-on-never.rs:20:5 - | -LL | return; - | ^^^^^^ + | |_____^ unreachable expression error: aborting due to 3 previous errors