Skip to content

Commit 0163ccc

Browse files
Fix "consider removing this semicolon" help
Check last statement in a block, not the first
1 parent c0b8c43 commit 0163ccc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15021502
} else {
15031503
let ends_with_stmt = match body.expr {
15041504
None if !body.stmts.is_empty() =>
1505-
match body.stmts.first().unwrap().node {
1505+
match body.stmts.last().unwrap().node {
15061506
hir::StmtSemi(ref e, _) => {
15071507
self.ir.tcx.expr_ty(&e) == t_ret
15081508
},
@@ -1515,7 +1515,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15151515
E0269,
15161516
"not all control paths return a value");
15171517
if ends_with_stmt {
1518-
let last_stmt = body.stmts.first().unwrap();
1518+
let last_stmt = body.stmts.last().unwrap();
15191519
let original_span = original_sp(self.ir.tcx.sess.codemap(),
15201520
last_stmt.span, sp);
15211521
let span_semicolon = Span {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn f() -> String { //~ ERROR E0269
12+
//~^ HELP detailed explanation
13+
0u8;
14+
"bla".to_string(); //~ HELP consider removing this semicolon
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)