From e1d27eb73cc2f318157f744d8175e1ef0340ff52 Mon Sep 17 00:00:00 2001 From: Shiqing Date: Sat, 7 Sep 2019 00:16:11 +0800 Subject: [PATCH] Reduce span to function name in unreachable calls --- src/librustc_typeck/check/expr.rs | 4 ++++ src/test/ui/never-assign-dead-code.stderr | 4 ++-- src/test/ui/reachable/expr_call.stderr | 4 ++-- src/test/ui/reachable/expr_method.stderr | 6 +++--- src/test/ui/unreachable/unreachable-in-call.rs | 2 +- src/test/ui/unreachable/unreachable-in-call.stderr | 8 +++----- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 9644815f805..da72dfd1551 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -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"), } diff --git a/src/test/ui/never-assign-dead-code.stderr b/src/test/ui/never-assign-dead-code.stderr index 779780a90a8..b1b5bf03fe5 100644 --- a/src/test/ui/never-assign-dead-code.stderr +++ b/src/test/ui/never-assign-dead-code.stderr @@ -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 diff --git a/src/test/ui/reachable/expr_call.stderr b/src/test/ui/reachable/expr_call.stderr index df5cff16f9a..f2db17e4dfe 100644 --- a/src/test/ui/reachable/expr_call.stderr +++ b/src/test/ui/reachable/expr_call.stderr @@ -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 diff --git a/src/test/ui/reachable/expr_method.stderr b/src/test/ui/reachable/expr_method.stderr index bbfa2ef529a..947ea0fee88 100644 --- a/src/test/ui/reachable/expr_method.stderr +++ b/src/test/ui/reachable/expr_method.stderr @@ -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 diff --git a/src/test/ui/unreachable/unreachable-in-call.rs b/src/test/ui/unreachable/unreachable-in-call.rs index 25f849d7a0a..dd94e79f4d8 100644 --- a/src/test/ui/unreachable/unreachable-in-call.rs +++ b/src/test/ui/unreachable/unreachable-in-call.rs @@ -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()); } diff --git a/src/test/ui/unreachable/unreachable-in-call.stderr b/src/test/ui/unreachable/unreachable-in-call.stderr index f8dd54590f6..c740011c4a1 100644 --- a/src/test/ui/unreachable/unreachable-in-call.stderr +++ b/src/test/ui/unreachable/unreachable-in-call.stderr @@ -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