Skip to content

Commit

Permalink
Auto merge of #64669 - estebank:unreachable, r=Centril
Browse files Browse the repository at this point in the history
Use span label instead of note in unreachable lint

Fix #64636.
  • Loading branch information
bors committed Sep 22, 2019
2 parents ef906d0 + 9991d54 commit 4ff32c0
Show file tree
Hide file tree
Showing 35 changed files with 191 additions and 334 deletions.
9 changes: 6 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
9 changes: 3 additions & 6 deletions src/test/ui/dead-code-ret.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/test/ui/if-ret.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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) { } }
| ^^^^^^^^

9 changes: 3 additions & 6 deletions src/test/ui/issues/issue-2150.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/test/ui/issues/issue-7246.stderr
Original file line number Diff line number Diff line change
@@ -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

9 changes: 3 additions & 6 deletions src/test/ui/lint/lint-attr-non-item-node.stderr
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions src/test/ui/lint/unreachable-async-fn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// check-pass
// edition:2018

#[allow(dead_code)]
async fn foo () { // unreachable lint doesn't trigger
unimplemented!()
}

fn main() {}
9 changes: 3 additions & 6 deletions src/test/ui/liveness/liveness-unused.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
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
|
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
Expand Down
9 changes: 3 additions & 6 deletions src/test/ui/match/match-no-arms-unreachable-after.stderr
Original file line number Diff line number Diff line change
@@ -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

19 changes: 6 additions & 13 deletions src/test/ui/never-assign-dead-code.stderr
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
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
|
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
Expand Down
10 changes: 4 additions & 6 deletions src/test/ui/reachable/expr_add.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

9 changes: 3 additions & 6 deletions src/test/ui/reachable/expr_again.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 7 additions & 13 deletions src/test/ui/reachable/expr_array.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

30 changes: 10 additions & 20 deletions src/test/ui/reachable/expr_assign.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Loading

0 comments on commit 4ff32c0

Please sign in to comment.