-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better error message for "error: break' outside of loop" inside of
do' inside of `for'
#3064
Comments
The issue also exists for |
You cannot break from a |
oh, huh, for some reason I forgot that there was another closure going on here. Yeah, this is correct behaviour. Maybe a better error message. |
The way it works for ruby is that the interpreter sets jump targets in the method frame. Each black executed from the stack will look at the method's frame to find where to jump to for continue/break/return. |
Here is the syntax modernized version of the examples. fn foo1() {
let vec = ~[Some(())];
for vec::each(vec) |slot| {
do slot.each |_bucket| {
break; // error: `break` outside of loop
}
}
}
fn foo2() {
let vec = ~[Some(())];
for vec::each(vec) |slot| {
match *slot {
Some(_bucket) => { break; }
None => { }
}
} I vote for either leaving things as is (and accept the odd error message as a consequence of integration of light-weight closure syntax), or finding some way to "improve" the error message (though it is not clear how best to do so). |
Not critical for 0.6; de-milestoning |
(there are of course other options. e.g. we could look into mitsuhiko's suggestion and change the calling convention so that invoking a closure implicitly passes along some number >1 of continuations, corresponding to different places control should shift in response to |
Changing the calling convention is not needed. If we can return out of the whole function, we can certainly break out of a subloop---you just break set a variable in your local stack indicating the point you wish to break to. To handle |
(Let me rephrase: we cannot handle |
Yeah, I'm sensing this is more of a WONTFIX. We're landing those enhancements to the |
I agree that the functionality shouldn't be supported, but you don't think a less confusing error message would be doable? |
@graydon to be clear, I think that |
Visiting for triage, the error message is still the same. |
I think this should be obviated by the plan for the new |
I expect the need for the error message will still exist. |
Even with the new fn foo(f: ||) {}
fn main() {
loop {
do foo {
break;
}
}
} That still gives the same error message, which is still misleading because it's inside of a |
Automatic sync from rustc
The `reverse_postorder` function used before is internal to the compiler and reflects the internal body representation. Besides that, I would like to introduce transformation on the top of SMIR body, which will break the 1:1 relationship between basic blocks from internal body and monomorphic body from StableMIR.
fails to compile, though I claim it should, and be the same as:
The text was updated successfully, but these errors were encountered: