Rollup merge of #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.
This commit is contained in:
commit
7d63422bb2
@ -1502,7 +1502,7 @@ fn check_ret(&self,
|
||||
} else {
|
||||
let ends_with_stmt = match body.expr {
|
||||
None if !body.stmts.is_empty() =>
|
||||
match body.stmts.first().unwrap().node {
|
||||
match body.stmts.last().unwrap().node {
|
||||
hir::StmtSemi(ref e, _) => {
|
||||
self.ir.tcx.expr_ty(&e) == t_ret
|
||||
},
|
||||
@ -1515,7 +1515,7 @@ fn check_ret(&self,
|
||||
E0269,
|
||||
"not all control paths return a value");
|
||||
if ends_with_stmt {
|
||||
let last_stmt = body.stmts.first().unwrap();
|
||||
let last_stmt = body.stmts.last().unwrap();
|
||||
let original_span = original_sp(self.ir.tcx.sess.codemap(),
|
||||
last_stmt.span, sp);
|
||||
let span_semicolon = Span {
|
||||
|
23
src/test/compile-fail/consider-removing-last-semi.rs
Normal file
23
src/test/compile-fail/consider-removing-last-semi.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn f() -> String { //~ ERROR E0269
|
||||
//~^ HELP detailed explanation
|
||||
0u8;
|
||||
"bla".to_string(); //~ HELP consider removing this semicolon
|
||||
}
|
||||
|
||||
fn g() -> String { //~ ERROR E0269
|
||||
//~^ HELP detailed explanation
|
||||
"this won't work".to_string();
|
||||
"removeme".to_string(); //~ HELP consider removing this semicolon
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user