GCC Rust Weekly Status Report 5 – Loop Expressions

Control flow 1 Milestone as been completed this means the front-end can now handle Block expressions, Loop and While Loop expressions, as well as method resolution. The remaining “For” loop construct has been left out for now. This requires Iterators that will need generics and traits to be implemented first.

Since the milestone has been completed earlier than the target date, this will help shape the future estimates. Generics and Traits are complex in rust and 3 months each have been allocated to these features for now, but this might change as time goes by next month. Note that the Data Structures 2 project is not fully fleshed out with tickets so the percentage of completion is not accurate at the moment.

There is now a student interested in Google Summer of Code 2021 to work on GCC Rust, which I will mentor to get involved.

Overview of merges

Since last week the IfExpr parser bug ( https://github.com/Rust-GCC/gccrs/issues/214) has been fixed allowing for the syntax below to be compilable.

fn main() {
    let a = 123;
    let b = if a > 10 { a - 1 } else { a + 1 };

The bug fix ( https://github.com/Rust-GCC/gccrs/issues/173 ) for allowing the final compound assignment operator of |= has been merged.

Loop expressions are infinite loops, but if you use the break expression with a value, this acts as an implicit return for this type of Loop Expression, the value becomes assignable.

fn main() {
    let mut a = 1;
    let mut b = 1;

    let val = loop {
        if b > 10 {
            break b;
        let c = a + b;
        a = b;
        b = c;

The other usage of a Break Expression is where you use labels. This allows for a break to goto a label, in this case, the beginning of a loop expression.

fn main() {
    'outer: loop {
        'inner: loop {
            break 'outer;

It is worth noting that While Loops have also been implemented but while loops do not allow for breaks to return a value and return:

error[E0571]: `break` with value from a `while` loop
 --> test.rs:5:9
5 |         break 123;
  |         ^^^^^^^^^ can only break with a value inside `loop` or breakable block

If you consider an infinite loop expression, the only way for this type of loop to exit is to use a break expression that can be regarded as a return expression.

On the other hand, loops have a predicate expression that is evaluated to determine whether it will loop again or not. This means it might exit on its own, which can leave an opportunity for no final value to type resolve.

The final piece that was merged was BorrowExpressions and DereferenceExpressions which can be considered similar to the C++ references but the mutable borrow has not implemented yet.

Merged PRs

  • Fix bug parsing rust Ternary Expressions – PR216
  • Fix bug handling Function Pointer CallExpr as a FieldAccessExpr – let a = (d.a)(d.b); – PR218
  • Fix bug parsing |= compound assignment – PR221
  • Add compilation option -frust-dump-all – PR222
  • LoopExpr WhileLoopExpr, ContinueExpr and BreakExpr – PR223 PR229
  • BorrowExpr and DereferenceExpr – PR231
  • Char Type – PR230
  • Changes into the AST to reuse the parser and prepare for macro expansion – PR227

Overall Task Status

Last WeekThis WeekDelta
In Progress42-2
GitHub Issues

Test Cases

Last WeekThis WeekDelta
make check-rust


Last WeekThis WeekDelta
In Progress20-2
GitHub Bugs

Milestones Progress

MilestoneLast WeekThis WeekDeltaStart DateCompletion DateTarget
Data Structures 1100%100%30th Nov 202027th Jan 202129th Jan 2021
Control Flow 168%100%+32%28th Jan 202110th Feb 202126th Feb 2021
Data Structures 20%31%+31%11th Feb 2028st May 2021
Data Structures 30%0%27th Aug 2021
Control Flow 20%0%29th Oct 2021
Imports and Visibility0%0%TBD
GitHub Milestones


RiskImpact (1-3)Likelihood (0-10)Risk (I*L)Mitigation
Copyright assignments2510Be up front on all PRs that the code is destined to be upstreamed to FSF

Planned Activities

  • Documentation
  • Ticket planning for Generics
  • Investigate how other GCC/LLVM front-ends implement Templates
  • Mutable Borrowing
  • Add in adjustments for method receivers to borrow self for example

Leave a Reply

Your email address will not be published. Required fields are marked *