Sisu
E0143

Loop label used by an enclosing loop

Error

Built from the repository at commit a8614dc.

A loop may not take the loop label of a loop around it. Two loops side by side may share a loop label.

Why

A break or continue that names a loop label reaches the innermost loop around it with that loop label. When an inner loop takes an outer loop's loop label, no jump inside the inner loop can name the outer one, and a reader cannot tell which loop a jump was meant for. Rename one of the loop labels, or delete the one no jump needs.

Broken

fn main() {
    outer: for x in [1, 2] {
        outer: for y in [3, 4] {
            if x + y == 5 {
                break outer
            }
            print(y)
        }
    }
}

What sisu says

error[E0143]: loop label `outer` is already used by an enclosing loop
 --> E0143.sisu:3:9
  |
2 |     outer: for x in [1, 2] {
  |     ----- the enclosing loop's label
3 |         outer: for y in [3, 4] {
  |         ^^^^^
  |
  = help: rename one of the loop labels

sisu: 1 error
sisu: for more on a code, run `sisu explain <code>`: E0143

Fixed

fn main() {
    outer: for x in [1, 2] {
        for y in [3, 4] {
            if x + y == 5 {
                break outer
            }
            print(y)
        }
    }
}

Related

  • E0142: a loop label that is also a name in scope.
  • W0008: a loop label that is never used.