about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-11-15 16:11:06 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2016-12-08 20:49:33 -0800
commit8dee5ab805298bcb095a262787ddf60cc48b10ba (patch)
tree294a9bc000673be322ce7c2675ddfcacce0243a1
parent5a065641fda719b1eeac85419981fee9d1122ded (diff)
downloadrust-8dee5ab805298bcb095a262787ddf60cc48b10ba.tar.gz
rust-8dee5ab805298bcb095a262787ddf60cc48b10ba.zip
Add E0571 test
-rw-r--r--src/librustc_typeck/check/mod.rs2
-rw-r--r--src/librustc_typeck/diagnostics.rs11
-rw-r--r--src/test/compile-fail/E0571.rs13
3 files changed, 19 insertions, 7 deletions
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index 755ea718f89..1ace79b0c55 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -3707,7 +3707,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
           hir::ExprRet(ref expr_opt) => {
             if self.ret_ty.is_none() {
                 struct_span_err!(self.tcx.sess, expr.span, E0571,
-                                 "return statement cannot be out of a function scope").emit();
+                                 "return statement outside of function body").emit();
             } else if let Some(ref e) = *expr_opt {
                 self.check_expr_coercable_to_type(&e, self.ret_ty.unwrap());
             } else {
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index 65b606b4582..86220cf57c4 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -4165,24 +4165,23 @@ If necessary, you can circumvent this check using custom target specifications.
 "##,
 
 E0571: r##"
-A return statement was outside a function scope.
+A return statement was found outside of a function body.
 
 Erroneous code example:
 
 ```compile_fail,E0571
-const FOO: u32 = return 0; // error: return statement cannot be out of a
-                           //        function scope
+const FOO: u32 = return 0; // error: return statement outside of function body
 
 fn main() {}
 ```
 
-To fix this issue, just remove the return statement or move it into a function
-scope. Example:
+To fix this issue, just remove the return keyword or move the expression into a
+function. Example:
 
 ```
 const FOO: u32 = 0;
 
-fn some_fn() -> i32 {
+fn some_fn() -> u32 {
     return FOO;
 }
 
diff --git a/src/test/compile-fail/E0571.rs b/src/test/compile-fail/E0571.rs
new file mode 100644
index 00000000000..d300c597008
--- /dev/null
+++ b/src/test/compile-fail/E0571.rs
@@ -0,0 +1,13 @@
+// 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.
+
+const FOO: u32 = return 0; //~ ERROR E0571
+
+fn main() {}