Skip to content

Commit e1d27eb

Browse files
committed
Reduce span to function name in unreachable calls
1 parent 6187684 commit e1d27eb

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

src/librustc_typeck/check/expr.rs

+4
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
161161
// Warn for non-block expressions with diverging children.
162162
match expr.node {
163163
ExprKind::Block(..) | ExprKind::Loop(..) | ExprKind::Match(..) => {},
164+
ExprKind::Call(ref callee, _) =>
165+
self.warn_if_unreachable(expr.hir_id, callee.span, "call"),
166+
ExprKind::MethodCall(_, ref span, _) =>
167+
self.warn_if_unreachable(expr.hir_id, *span, "call"),
164168
_ => self.warn_if_unreachable(expr.hir_id, expr.span, "expression"),
165169
}
166170

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ LL | #![warn(unused)]
1111
| ^^^^^^
1212
= note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]`
1313

14-
warning: unreachable expression
14+
warning: unreachable call
1515
--> $DIR/never-assign-dead-code.rs:10:5
1616
|
1717
LL | drop(x);
18-
| ^^^^^^^
18+
| ^^^^
1919

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

src/test/ui/reachable/expr_call.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ note: lint level defined here
1010
LL | #![deny(unreachable_code)]
1111
| ^^^^^^^^^^^^^^^^
1212

13-
error: unreachable expression
13+
error: unreachable call
1414
--> $DIR/expr_call.rs:18:5
1515
|
1616
LL | bar(return);
17-
| ^^^^^^^^^^^
17+
| ^^^
1818

1919
error: aborting due to 2 previous errors
2020

src/test/ui/reachable/expr_method.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ note: lint level defined here
1010
LL | #![deny(unreachable_code)]
1111
| ^^^^^^^^^^^^^^^^
1212

13-
error: unreachable expression
14-
--> $DIR/expr_method.rs:21:5
13+
error: unreachable call
14+
--> $DIR/expr_method.rs:21:9
1515
|
1616
LL | Foo.bar(return);
17-
| ^^^^^^^^^^^^^^^
17+
| ^^^
1818

1919
error: aborting due to 2 previous errors
2020

src/test/ui/unreachable/unreachable-in-call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn diverge_first() {
1414
get_u8()); //~ ERROR unreachable expression
1515
}
1616
fn diverge_second() {
17-
call( //~ ERROR unreachable expression
17+
call( //~ ERROR unreachable call
1818
get_u8(),
1919
diverge());
2020
}

src/test/ui/unreachable/unreachable-in-call.stderr

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ note: lint level defined here
1010
LL | #![deny(unreachable_code)]
1111
| ^^^^^^^^^^^^^^^^
1212

13-
error: unreachable expression
13+
error: unreachable call
1414
--> $DIR/unreachable-in-call.rs:17:5
1515
|
16-
LL | / call(
17-
LL | | get_u8(),
18-
LL | | diverge());
19-
| |__________________^
16+
LL | call(
17+
| ^^^^
2018

2119
error: aborting due to 2 previous errors
2220

0 commit comments

Comments
 (0)