Skip to content

Commit 8dee5ab

Browse files
Add E0571 test
1 parent 5a06564 commit 8dee5ab

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3707,7 +3707,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
37073707
hir::ExprRet(ref expr_opt) => {
37083708
if self.ret_ty.is_none() {
37093709
struct_span_err!(self.tcx.sess, expr.span, E0571,
3710-
"return statement cannot be out of a function scope").emit();
3710+
"return statement outside of function body").emit();
37113711
} else if let Some(ref e) = *expr_opt {
37123712
self.check_expr_coercable_to_type(&e, self.ret_ty.unwrap());
37133713
} else {

src/librustc_typeck/diagnostics.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4165,24 +4165,23 @@ If necessary, you can circumvent this check using custom target specifications.
41654165
"##,
41664166

41674167
E0571: r##"
4168-
A return statement was outside a function scope.
4168+
A return statement was found outside of a function body.
41694169
41704170
Erroneous code example:
41714171
41724172
```compile_fail,E0571
4173-
const FOO: u32 = return 0; // error: return statement cannot be out of a
4174-
// function scope
4173+
const FOO: u32 = return 0; // error: return statement outside of function body
41754174
41764175
fn main() {}
41774176
```
41784177
4179-
To fix this issue, just remove the return statement or move it into a function
4180-
scope. Example:
4178+
To fix this issue, just remove the return keyword or move the expression into a
4179+
function. Example:
41814180
41824181
```
41834182
const FOO: u32 = 0;
41844183
4185-
fn some_fn() -> i32 {
4184+
fn some_fn() -> u32 {
41864185
return FOO;
41874186
}
41884187

src/test/compile-fail/E0571.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const FOO: u32 = return 0; //~ ERROR E0571
12+
13+
fn main() {}

0 commit comments

Comments
 (0)