Skip to content

Remove loop keyword from the language #12975

Closed

Description

@liigo

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)

Activity

  1. liigo commented on Mar 17, 2014

    @liigo
    ContributorAuthor

    cc #2233: Remove while loops

  2. huonw commented on Mar 17, 2014

    @huonw
    Contributor

    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.

  3. alexcrichton commented on Mar 17, 2014

    @alexcrichton
    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.

  4. pnkfelix commented on Mar 17, 2014

    @pnkfelix
    Contributor

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

  5. Thiez commented on Mar 17, 2014

    @Thiez
    Contributor

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

  6. liigo commented on Mar 20, 2014

    @liigo
    ContributorAuthor

    @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.

  7. added a commit that references this issue on Nov 2, 2014
    b18e90e
  8. jkleint commented on Nov 2, 2014

    @jkleint

    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!

  9. liigo commented on Nov 4, 2014

    @liigo
    ContributorAuthor

    @jkleint thank you for working on this!

  10. added a commit that references this issue on Aug 23, 2022
    b6fae56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions