Skip to content

Commit 7d63422

Browse files
committed
Rollup merge of rust-lang#32710 - jonas-schievink:consider-last-semi, r=nagisa
Fix "consider removing this semicolon" help Check last statement in a block, not the first. Example of current weirdness: http://is.gd/w80J9h The help was only rarely emitted, and if so, often incorrectly (see above playpen). It was basically only useful with single-statement functions.
2 parents b6c1f1c + 99b6247 commit 7d63422

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 g() -> String { //~ ERROR E0269
18+
//~^ HELP detailed explanation
19+
"this won't work".to_string();
20+
"removeme".to_string(); //~ HELP consider removing this semicolon
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)