]> git.lizzy.rs Git - rust.git/commitdiff
Fix "consider removing this semicolon" help
authorJonas Schievink <jonas@schievink.net>
Sun, 3 Apr 2016 20:10:21 +0000 (22:10 +0200)
committerJonas Schievink <jonas@schievink.net>
Sun, 3 Apr 2016 20:12:48 +0000 (22:12 +0200)
Check last statement in a block, not the first

src/librustc/middle/liveness.rs
src/test/compile-fail/consider-removing-last-semi.rs [new file with mode: 0644]

index cc37ee7dbda051571308108b50e9a7025f5a594d..4451e7ac472e544c463c49c35c6c74359d4b41f1 100644 (file)
@@ -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 {
diff --git a/src/test/compile-fail/consider-removing-last-semi.rs b/src/test/compile-fail/consider-removing-last-semi.rs
new file mode 100644 (file)
index 0000000..a25f0b1
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 main() {}