Improve error message for breaks in blocks

Before it was always stated that it was a "break outside of a loop" when you
could very well be in a loop, but just in a block instead.

Closes #3064
This commit is contained in:
Alex Crichton 2013-11-11 11:29:15 -08:00
parent 0cc5e6c83f
commit 5fdbcc4020
3 changed files with 60 additions and 49 deletions

View file

@ -8,15 +8,26 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:`break` outside of loop
struct Foo {
t: ~str
}
fn cond() -> bool { true }
fn foo(_: ||) {}
fn main() {
let pth = break;
let pth = break; //~ ERROR: `break` outside of loop
if cond() { continue } //~ ERROR: `continue` outside of loop
while cond() {
if cond() { break }
if cond() { continue }
do foo {
if cond() { break } //~ ERROR: `break` inside of a closure
if cond() { continue } //~ ERROR: `continue` inside of a closure
}
}
let rs: Foo = Foo{t: pth};
}

View file

@ -10,6 +10,6 @@
fn main() {
let _x = || {
return //~ ERROR: `return` in block function
return //~ ERROR: `return` in a closure
};
}