Add E0571 test

This commit is contained in:
Guillaume Gomez 2016-11-15 16:11:06 +01:00
parent 5a065641fd
commit 8dee5ab805
3 changed files with 19 additions and 7 deletions

View File

@ -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 {

View File

@ -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;
}

View File

@ -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() {}