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

Implement the loop_break_value feature. #37487

Merged
merged 1 commit into from
Nov 23, 2016
Merged

Commits on Nov 22, 2016

  1. Implement the loop_break_value feature.

    This implements RFC 1624, tracking issue rust-lang#37339.
    
    - `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
      currently deduced type of that loop, the desired type, and a list of
      break expressions currently seen. `loop` loops get a fresh type
      variable as their initial type (this logic is stolen from that for
      arrays). `while` loops get `()`.
    - `break {expr}` looks up the broken loop, and unifies the type of
      `expr` with the type of the loop.
    - `break` with no expr unifies the loop's type with `()`.
    - When building MIR, `loop` loops no longer construct a `()` value at
      termination of the loop; rather, the `break` expression assigns the
      result of the loop. `while` loops are unchanged.
    - `break` respects contexts in which expressions may not end with braced
      blocks. That is, `while break { break-value } { while-body }` is
      illegal; this preserves backwards compatibility.
    - The RFC did not make it clear, but I chose to make `break ()` inside
      of a `while` loop illegal, just in case we wanted to do anything with
      that design space in the future.
    
    This is my first time dealing with this part of rustc so I'm sure
    there's plenty of problems to pick on here ^_^
    goffrie committed Nov 22, 2016
    Configuration menu
    Copy the full SHA
    9d42549 View commit details
    Browse the repository at this point in the history