Skip to content
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

Can't use label for while loop #12643

Closed
chris-morgan opened this issue Mar 1, 2014 · 8 comments · Fixed by #16190
Closed

Can't use label for while loop #12643

chris-morgan opened this issue Mar 1, 2014 · 8 comments · Fixed by #16190
Labels
P-medium Medium priority

Comments

@chris-morgan
Copy link
Member

Say!
I like labelled breaks/continues!
I do! I like them, Sam-I-am!
And I would use them in a boat!
And I would use them with a goat...
And I will use them in the rain.
And in the dark. And on a train.
And in a car. And in a tree.
They are so good, so good, you see!

So I will use them in a box.
And I will use them with a fox.
And I will use them in a house.
And I will use them with a mouse.
And I will use them here and there.
Say! I will use them ANYWHERE!

I will use them with a for loop.
And I will use with a loop loop.
Say! I will use them ANYWHERE!
… except in a while loop.

Because they're not supported there.

@chris-morgan
Copy link
Member Author

Code examples:

fn main() {
    'eggs: loop {
        'ham: for _ in range(0, 0) {
            if 1 + 1 == 2 {
                break 'eggs;
            } else {
                continue 'ham;
            }
        }
    }
}

Compiles fine.

But with a while loop:

fn main() {
    'eggs: while 1 + 1 == 2 {
        break 'eggs;
    }
}

It doesn't compile:

green.rs:2:12: 2:17 error: expected `for` or `loop` after a label
green.rs:2     'eggs: while 1 + 1 == 2 {
                      ^~~~~

@edwardw
Copy link
Contributor

edwardw commented Mar 3, 2014

Should it? The AST node definition for while loop is ExprWhile(@Expr, P<Block>); there is no label there.

@huonw
Copy link
Member

huonw commented Mar 3, 2014

That's only because while doesn't have support for labelled breaks, a label would only be added if/when the compiler itself supported codegen for labelled whiles.

@pnkfelix
Copy link
Member

nominating.

I believe that, if necessary, we can add support for labelled whiles after 1.0 backwards compatibly. But I have to admit, it is super-surprising that loop { } supports it while while cond { } does not.

Therefore, I am recommending that we tag this as "P-high", but not add it to the 1.0 milestone.

@flaper87
Copy link
Contributor

Sounds like we should support this.

@pnkfelix +1 for your tagging recommendation.

@pnkfelix
Copy link
Member

P-high, but not 1.0 (we can add it backwards compatibly).

@Pythoner6
Copy link
Contributor

I've done some work on this (initial commit: Pythoner6@7e9a2fe). Once I have time to rebase and re-run the tests, I'll be submitting a pull request.

bors added a commit that referenced this issue Aug 30, 2014
Fixes #12643

> Say!
> I like labelled breaks/continues!

I will use them with a `for` loop.
And I will use with a `loop` loop.
Say! I will use them ANYWHERE!
… _even_ in a `while` loop.

Because they're now supported there.
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2022
fix: Fix completions for locals not working properly inside macro calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-medium Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@flaper87 @pnkfelix @chris-morgan @edwardw @huonw @Pythoner6 and others