Skip to content

First pass at replacing loop with while true. #18553

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

Closed
wants to merge 1 commit into from

Conversation

jkleint
Copy link

@jkleint jkleint commented Nov 2, 2014

Proto-RFC here: https://github.com/jkleint/rfcs/blob/remove-loop-keyword/text/0000-remove-loop-keyword.md

This is my first foray into modifying the Rust compiler, so please let me know if I'm way off the mark. I'm not sure this is the right way to do things, it's just to get the conversation started and show it may be simple.

This piggybacks on while-expression parsing the same way as while let to recognize while true and call the existing loop parsing code.

I haven't been able to thoroughly test it, but it does seem to compile code like this:

fn main() {
    let x;
    while true { x = 1i; break; }
    println!("{}", x)
}

which previously did not compile (x possibly uninitialized).

I'm unsure of how to use the existing deprecation machinery for a keyword, so I have just put in placeholder warnings, but please advise on how do do that properly. I'm also not sure if the source span properly encompasses the whole while loop.

Fixes #12975.

Piggybacks on while-expr parsing the same way as `while let` to
recognize `while true` and call the existing `loop` parsing code.

Fixes rust-lang#12975.
@alexcrichton
Copy link
Member

Currently language changes are required to go through the RFC process as outlined in the RFC repo's README.

In light of this, could you open an RFC for this change? In the meantime I'm going to close this PR against the rust repo to help clear out the queue.

@pcwalton
Copy link
Contributor

pcwalton commented Nov 3, 2014

This needs to go through the RFC process before submitting a PR. Closing.

@pcwalton
Copy link
Contributor

pcwalton commented Nov 3, 2014

Also even if we wanted to do this (which I don't want to) this implementation is nowhere near what we would need. I think you would want to get rid of ExprLoop entirely and add a method that applies a series of hacks to try to figure out whether a loop is endless to replace uses of it in the compiler. (You will at least need to consider things like ExprParen(ExprLit(true)).)

These hacks that you will have to add, by the way, are the reason I don't want to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove loop keyword from the language
3 participants