Skip to content

Commit

Permalink
Reduce span to function name in unreachable calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuusweetfish committed Sep 6, 2019
1 parent 6187684 commit e1d27eb
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
4 changes: 4 additions & 0 deletions src/librustc_typeck/check/expr.rs
Expand Up @@ -161,6 +161,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// Warn for non-block expressions with diverging children.
match expr.node {
ExprKind::Block(..) | ExprKind::Loop(..) | ExprKind::Match(..) => {},
ExprKind::Call(ref callee, _) =>
self.warn_if_unreachable(expr.hir_id, callee.span, "call"),
ExprKind::MethodCall(_, ref span, _) =>
self.warn_if_unreachable(expr.hir_id, *span, "call"),
_ => self.warn_if_unreachable(expr.hir_id, expr.span, "expression"),
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/never-assign-dead-code.stderr
Expand Up @@ -11,11 +11,11 @@ LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`

warning: unreachable expression
warning: unreachable call
--> $DIR/never-assign-dead-code.rs:10:5
|
LL | drop(x);
| ^^^^^^^
| ^^^^

warning: unused variable: `x`
--> $DIR/never-assign-dead-code.rs:9:9
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/reachable/expr_call.stderr
Expand Up @@ -10,11 +10,11 @@ note: lint level defined here
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^

error: unreachable expression
error: unreachable call
--> $DIR/expr_call.rs:18:5
|
LL | bar(return);
| ^^^^^^^^^^^
| ^^^

error: aborting due to 2 previous errors

6 changes: 3 additions & 3 deletions src/test/ui/reachable/expr_method.stderr
Expand Up @@ -10,11 +10,11 @@ note: lint level defined here
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^

error: unreachable expression
--> $DIR/expr_method.rs:21:5
error: unreachable call
--> $DIR/expr_method.rs:21:9
|
LL | Foo.bar(return);
| ^^^^^^^^^^^^^^^
| ^^^

error: aborting due to 2 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/unreachable/unreachable-in-call.rs
Expand Up @@ -14,7 +14,7 @@ fn diverge_first() {
get_u8()); //~ ERROR unreachable expression
}
fn diverge_second() {
call( //~ ERROR unreachable expression
call( //~ ERROR unreachable call
get_u8(),
diverge());
}
Expand Down
8 changes: 3 additions & 5 deletions src/test/ui/unreachable/unreachable-in-call.stderr
Expand Up @@ -10,13 +10,11 @@ note: lint level defined here
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^

error: unreachable expression
error: unreachable call
--> $DIR/unreachable-in-call.rs:17:5
|
LL | / call(
LL | | get_u8(),
LL | | diverge());
| |__________________^
LL | call(
| ^^^^

error: aborting due to 2 previous errors

0 comments on commit e1d27eb

Please sign in to comment.