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

Remove loop keyword from the language #12975

Closed
liigo opened this issue Mar 17, 2014 · 8 comments
Closed

Remove loop keyword from the language #12975

liigo opened this issue Mar 17, 2014 · 8 comments

Comments

@liigo
Copy link
Contributor

liigo commented Mar 17, 2014

loop loops can be removed, because it doesn't do any special jobs than while true {} (which maybe simplified to while { }).

Do we really need two similar loops? (loop VS. while)

@liigo
Copy link
Contributor Author

liigo commented Mar 17, 2014

cc #2233: Remove while loops

@huonw
Copy link
Member

huonw commented Mar 17, 2014

loop does currently have a special job:

let mut a;
loop {
     a = 1;
     // ... break ...
}
do_something(a)

is valid but the while true equivalent is not: the compiler isn't sure that a is initialised. Of course, this is just a minor detail, we could special case the while true form like Java.

@alexcrichton
Copy link
Member

Language changes such as this require and RFC rather than an issue in the rust repository, I would recommend following the procedure over at https://github.com/rust-lang/rfcs.

@pnkfelix
Copy link
Member

Also, we definitely cannot remove loop-de-loops until #12643 is fixed.

@Thiez
Copy link
Contributor

Thiez commented Mar 17, 2014

loop could not be replaced by while {stuff} because {stuff} would be interpreted as the condition (e.g. while { condition } { body }).

@liigo
Copy link
Contributor Author

liigo commented Mar 20, 2014

@alexcrichton Obviously requires an RFC. I'm much appreciate if someone has interest writing it. (I'm not a native-english user, too hard to write it for me, sorry.)

@pnkfelix @Thiez We can do more if we want to remove or replace it.

jkleint pushed a commit to jkleint/rust that referenced this issue Nov 2, 2014
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.
@jkleint
Copy link

jkleint commented Nov 2, 2014

I'd like to take up replacing the loop keyword with while true. Now that #12643 is fixed, this should be straightforward. It looks like we can recognize the two tokens while true in the parser and invoke the existing loop parsing machinery with very minimal changes. This allows us to remove loop before Rust 1.0 is frozen, and the internal implementation can be cleaned up at any later time.

I have a rough pass at an RFC up here:
https://github.com/jkleint/rfcs/blob/remove-loop-keyword/text/0000-remove-loop-keyword.md
I am requesting comments on my Request For Comments.

I am willing to do the work of replacing all occurrences of loop with while true in the source and documentation, but I will need help actually modifying the compiler. This is my first real change to Rust and first RFC, so I would love advice and input.

Also, if anyone can point me to an easy way to mechanically transform Rust source, I might make a tool to help with migration.

Thanks!

@liigo
Copy link
Contributor Author

liigo commented Nov 4, 2014

@jkleint thank you for working on this!

lnicola pushed a commit to lnicola/rust that referenced this issue Aug 23, 2022
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 a pull request may close this issue.

6 participants