Add E0571 test
This commit is contained in:
parent
5a065641fd
commit
8dee5ab805
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
13
src/test/compile-fail/E0571.rs
Normal file
13
src/test/compile-fail/E0571.rs
Normal 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() {}
|
Loading…
Reference in New Issue
Block a user