Rust

E0426 Undeclared Label Used Fix

A label is not declared by using it. It exists only where it is written, with a colon, in front of a loop or a block - and a break or continue that names any other label has nothing to jump to. This guide works the shapes that draw E0426 - a break in a plain loop, a continue in a while loop, a break in a for loop, a label written too late, a label reused after its loop, and a misspelled label - and matches each one to its repair: put the label on the expression the jump is meant to leave or restart.

Written November 29, 2026 · Tested with Rust 1.99.1 · 17 min read

By the end of this guide
  • The rule underneath: a label names one loop or block, from inside it
  • How to read the diagnostic
  • The first failure: a break names a label in a plain loop
  • The second failure: a continue names a label in a while loop

Written November 29, 2026

Tested with Rust 1.99.1

What this guide is

Error E0426 is a break or continue naming a label that was never declared. The error codes index states it in one line - "An undeclared label was used" - and its example is a plain loop whose body is break 'a;, with the comment "error: use of undeclared label 'a". Its repair is the same program with one addition: 'a: written in front of the loop, after which the identical break 'a; is marked "ok!".

The point the example makes is that the two spellings of a label do different jobs. The label on a loop - 'a: loop - is the declaration: it names that loop, and it is the only place a label comes into existence. The label on a break or continue - break 'a; - is a use: it says which enclosing loop to leave or restart. A use with no matching declaration in any enclosing loop or labeled block is E0426, whatever the loop underneath is doing. Spelling is part of the match: a declared 'outer does not cover a use of 'outr, and a label declared on a later loop does not cover a use in an earlier one.

The forms in this guide each reproduce E0426 with a small, complete program: a break in a plain loop, a continue in a while loop, a break in a for loop, a label declared after the loop that uses it, a label reused after its own loop has ended, and a misspelled label. Each failure is followed by its repair. The repairs are all the same shape - declare the label on the right expression - but choosing the right expression is the whole problem: the label belongs on the loop the jump is meant to affect, which in nested loops is usually the outer one, not the loop the break sits in.

Build every program in this guide with rustc --edition 2021. In the compiler transcripts below, the file names are the bare names shown on the command line.

The rule underneath: a label names one loop or block, from inside it

The Rust Reference describes four loop expressions - loop, while, for, and the labeled block - and states that all four support break expressions and labels, that all except the labeled block also support continue, and that only loop and the labeled block can evaluate to a value carried by a break. A label written before any of them names that one expression. Inside its body, and inside anything nested in that body, break 'label leaves it and continue 'label restarts it. Outside that body the name does not exist: not before the labeled expression starts, not after it ends, and not in a sibling loop next to it.

That scope rule decides most repairs before any code changes. Find the break or continue that names the label, then walk outward through the loops and blocks enclosing it until reaching the one the jump is meant to leave or restart, and declare the label there. If no enclosing expression is the intended target - the jump sits in a plain block, or in a loop that has already ended - no declaration placed nearby will match, and the code needs restructuring, not just a label.

One more form is worth knowing before the failures: a label can be declared again inside its own scope. An inner loop may reuse the same label name as an outer loop; the inner declaration shadows the outer one for the inner body, and the compiler warns about it rather than erroring. That shape is worked in the traps, because a shadowed label makes a break land somewhere other than where a reader expects.

How to read the diagnostic

The header is "use of undeclared label", with the code E0426, and the name in backticks, as in "use of undeclared label 'a". The caret span sits under the label use itself and carries the single label "undeclared label 'a". There is no second span pointing at a declaration site, because there is no declaration to point at - the absence is the error. When a similarly named label is in reach, the diagnostic changes shape: the span gains a second label, "a label with a similar name is reachable", under the declaration, and a help line under the use, "try using similarly named label". That extra help is the fastest tell that the problem is spelling rather than a missing declaration, and it is worked in the traps.

Warnings can ride along with the error without being part of it. A break that would end a loop unconditionally makes the code after the loop unreachable, and the compiler says so in a separate warning in some of the transcripts below. The warning clears with the error when the label is declared, because the program then compiles as written; it is not a second defect to repair.

The first failure: a break names a label in a plain loop

This is the error index's own shape. The loop is a plain loop with no label in front of it, and its body breaks to 'a:

Rust
fn main() {
    loop {
        break 'a;
    }
    println!("done");
}
Output
error[E0426]: use of undeclared label `'a`
 --> a1.rs:3:15
  |
3 |         break 'a;
  |               ^^ undeclared label `'a`

warning: unreachable statement
 --> a1.rs:5:5
  |
2 | /     loop {
3 | |         break 'a;
4 | |     }
  | |_____- any code following this expression is unreachable
5 |       println!("done");
  |       ^^^^^^^^^^^^^^^^ unreachable statement
  |
  = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0426`.

Nothing in the program declares 'a - the name appears only at the use. The repair declares it, in the colon form, on the loop the break is meant to leave:

Rust
fn main() {
    'a: loop {
        break 'a;
    }
    println!("done");
}
Command
done

The output is done: the labeled loop is entered, the break 'a; leaves it at once, and execution continues after it. The break line did not change at all. What changed is that the name it uses now has a declaration, on the expression it was always meant to name.

The second failure: a continue names a label in a while loop

continue follows the same rule as break. This while loop counts up and continues to 'a, a label no loop declares:

Rust
fn main() {
    let mut n = 0;
    while n < 3 {
        n += 1;
        continue 'a;
    }
    println!("{n}");
}
Output
error[E0426]: use of undeclared label `'a`
 --> a2.rs:5:18
  |
5 |         continue 'a;
  |                  ^^ undeclared label `'a`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0426`.

The diagnostic is identical in form: the span under the label use, the single "undeclared label" label, no help. The repair declares the label on the while loop, and the continue then restarts that loop under its name:

Rust
fn main() {
    let mut n = 0;
    'a: while n < 3 {
        n += 1;
        continue 'a;
    }
    println!("{n}");
}
Output
3

The output is 3: each pass increments n, the continue 'a; returns control to the while condition, and the loop ends when the condition fails. A continue with a label matters most in nested loops, where it restarts an outer loop rather than the innermost one - the same declaration rule, with the label placed on the loop to be restarted, as the nested case below shows for break.

The third failure: a break names a label in a for loop

A for loop is labeled the same way. Here the body breaks to 'outer when the counter reaches 1, and the for carries no label:

Rust
fn main() {
    for i in 0..3 {
        if i == 1 {
            break 'outer;
        }
        println!("{i}");
    }
    println!("done");
}
Output
error[E0426]: use of undeclared label `'outer`
 --> a3.rs:4:19
  |
4 |             break 'outer;
  |                   ^^^^^^ undeclared label `'outer`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0426`.

The name 'outer was chosen as if the loop were the outer thing to leave, but a name in the author's head is not a declaration. Declaring it on the for makes the same body compile:

Rust
fn main() {
    'outer: for i in 0..3 {
        if i == 1 {
            break 'outer;
        }
        println!("{i}");
    }
    println!("done");
}
Output
0
done

The output is 0 followed by done: the first pass prints, the second pass breaks out of the labeled for, and the statement after the loop runs. The label name is free - 'outer, 'a, and 'rows all work the same way - as long as the declaration and every use spell it identically, apostrophe included.

The case a label exists for: breaking an outer loop from an inner one

An unlabeled break leaves only the innermost loop. Leaving an outer loop from inside an inner one is the job labels were made for, and it needs the label declared on the outer loop - the declaration the failures above were missing. This program counts once, enters an inner loop, and breaks the outer loop from inside it:

Rust
fn main() {
    let mut count = 0;
    'outer: loop {
        count += 1;
        loop {
            println!("inner {count}");
            break 'outer;
        }
    }
    println!("stopped at {count}");
}
Output
inner 1
stopped at 1

The output is inner 1 followed by stopped at 1: the inner loop prints once, break 'outer; leaves the labeled outer loop directly, and the inner loop's own end is never reached as a separate step. Without the label, the same inner break would leave only the inner loop, the outer loop would count again, and the program would not stop. When a nested loop needs to leave or restart more than itself, the label goes on the target loop - and that placement, not the break line, is what to check when E0426 appears in nested code.

A labeled loop can also carry a value out. Only loop and the labeled block support this form, and the label is named in the break that supplies the value:

Rust
fn main() {
    let result = 'a: loop {
        break 'a 42;
    };
    println!("{result}");
}
Output
42

The output is 42, the value the break 'a 42; carried out of the loop it named.

The traps

Trap
Three shapes look like near misses for the same declare-the-label repair and behave differently, and one compiler warning is worth separating from the error.

A label declared after the loop that uses it does not reach backward. In this program the second loop declares 'a correctly, and the first loop's break 'a; still draws E0426, because a label is in scope only inside the expression it prefixes:

Rust
fn main() {
    loop {
        break 'a;
    }
    'a: loop {
        break 'a;
    }
    println!("done");
}
Output
error[E0426]: use of undeclared label `'a`
 --> n1.rs:3:15
  |
3 |         break 'a;
  |               ^^ undeclared label `'a`

warning: unreachable statement
 --> n1.rs:5:5
  |
2 | /     loop {
3 | |         break 'a;
4 | |     }
  | |_____- any code following this expression is unreachable
5 | /     'a: loop {
6 | |         break 'a;
7 | |     }
  | |_____^ unreachable statement
  |
  = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0426`.

The repair is a declaration per loop that uses the name - or one declaration on a loop that encloses both uses. Moving the existing declaration earlier does nothing unless it lands on a loop enclosing the use.

A label also ends with its loop. This program breaks 'outer correctly from an inner loop, then uses the same name in a later, separate loop - and the second use draws E0426, because the declaration's scope ended with the first loop:

Rust
fn main() {
    'outer: loop {
        loop {
            break 'outer;
        }
        println!("unreachable");
    }
    loop {
        break 'outer;
    }
    println!("done");
}
Output
error[E0426]: use of undeclared label `'outer`
 --> n2.rs:9:15
  |
9 |         break 'outer;
  |               ^^^^^^ undeclared label `'outer`

warning: unreachable statement
 --> n2.rs:6:9
  |
4 |             break 'outer;
  |             ------------ any code following this expression is unreachable
5 |         }
6 |         println!("unreachable");
  |         ^^^^^^^^^^^^^^^^^^^^^^^ unreachable statement
  |
  = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

warning: unreachable statement
  --> n2.rs:11:5
   |
 8 | /     loop {
 9 | |         break 'outer;
10 | |     }
   | |_____- any code following this expression is unreachable
11 |       println!("done");
   |       ^^^^^^^^^^^^^^^^ unreachable statement

error: aborting due to 1 previous error; 2 warnings emitted

For more information about this error, try `rustc --explain E0426`.

Each loop that is jumped to by name needs its own declaration. Two sibling loops may declare the same label name independently; each declaration covers only its own body.

A misspelled label is the same error with better help. Here 'outer is declared and the body breaks to 'outr:

Rust
fn main() {
    'outer: loop {
        break 'outr;
    }
    println!("done");
}
Output
error[E0426]: use of undeclared label `'outr`
 --> n3.rs:3:15
  |
2 |     'outer: loop {
  |     ------ a label with a similar name is reachable
3 |         break 'outr;
  |               ^^^^^
  |               |
  |               undeclared label `'outr`
  |               help: try using similarly named label: `'outer`

warning: unused label
 --> n3.rs:2:5
  |
2 |     'outer: loop {
  |     ^^^^^^
  |
  = note: `#[warn(unused_labels)]` (part of `#[warn(unused)]`) on by default

warning: unreachable statement
 --> n3.rs:5:5
  |
2 | /     'outer: loop {
3 | |         break 'outr;
4 | |     }
  | |_____- any code following this expression is unreachable
5 |       println!("done");
  |       ^^^^^^^^^^^^^^^^ unreachable statement
  |
  = note: `#[warn(unreachable_code)]` (part of `#[warn(unused)]`) on by default

error: aborting due to 1 previous error; 2 warnings emitted

For more information about this error, try `rustc --explain E0426`.

The span now points at both ends: "a label with a similar name is reachable" under the declaration, and "try using similarly named label: 'outer" under the use. The compiler also warns that the declared label is unused, which is the same mismatch seen from the other side. The repair is to make the spellings agree - in either direction, as long as declaration and uses match everywhere.

A plain block is not a loop, and a break inside one draws more than E0426. This program tries to break to 'a from an unlabeled block:

Rust
fn main() {
    let result = {
        break 'a;
    };
    println!("{result}");
}
Output
error[E0426]: use of undeclared label `'a`
 --> n5.rs:3:15
  |
3 |         break 'a;
  |               ^^ undeclared label `'a`

error[E0268]: `break` outside of a loop or labeled block
 --> n5.rs:3:9
  |
3 |         break 'a;
  |         ^^^^^^^^ cannot `break` outside of a loop or labeled block
  |
help: consider labeling this block to be able to break within it
  |
2 ~     let result = 'block: {
3 ~         break 'block;
  |

error[E0277]: `()` doesn't implement `std::fmt::Display`
 --> n5.rs:5:15
  |
5 |     println!("{result}");
  |               ^^^^^^^^ `()` cannot be formatted with the default formatter
  |
  = help: the trait `std::fmt::Display` is not implemented for `()`
  = note: in format strings you may be able to use `{:?}` (or `{:#?}` for pretty-print) instead

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0268, E0277, E0426.
For more information about an error, try `rustc --explain E0268`.

Three errors arrive together: E0426 for the undeclared label, E0268, "break outside of a loop or labeled block", and a type error on the result, because the block supplies no value. The compiler's help on the E0268 span shows the intended form - label the block itself. A labeled block is a real target: it runs once, a break inside it leaves it, and a break with a value gives the block its value:

Rust
fn main() {
    'a: {
        break 'a;
    }
    println!("done");
}
Command
done

The output is done: the labeled block is entered, the break 'a; leaves it, and the statement after it runs. With a value, the same form returns it:

Rust
fn main() {
    let result = 'a: {
        break 'a 42;
    };
    println!("{result}");
}
Output
42

The output is 42. A labeled block cannot take continue - it runs once, so there is nothing to restart - which is the one asymmetry among the four labelable expressions.

Shadowing is legal and warned about, not an error. An inner loop may declare a label an outer loop already uses; the inner break then names the inner loop, and only after the inner loop ends does the name mean the outer one again:

Rust
fn main() {
    'a: loop {
        'a: loop {
            break 'a;
        }
        break 'a;
    }
    println!("done");
}
Command
done

The output is done, and the compiler warns that the label name shadows a label name already in scope, naming the first declaration. The warning is the useful part: a shadowed label compiles, but a reader tracking which loop a break leaves will likely track it wrong. Distinct names for nested loops - as in the continue case below - state the target on sight:

Rust
fn main() {
    let mut total = 0;
    'rows: for r in 0..3 {
        for c in 0..3 {
            if c == 2 {
                continue 'rows;
            }
            total += 1;
            println!("r{r} c{c}");
        }
    }
    println!("total {total}");
}
Output
r0 c0
r0 c1
r1 c0
r1 c1
r2 c0
r2 c1
total 6

The output lists the first two columns of each of three rows, then total 6: when the column counter reaches 2, continue 'rows; restarts the labeled outer for, skipping the rest of that row. No inner-loop continue without the label could skip the row that way.

A labeled while loop takes the same declaration, with break and continue both naming it:

Rust
fn main() {
    let mut n = 0;
    'a: while n < 10 {
        n += 1;
        if n == 3 {
            break 'a;
        }
    }
    println!("{n}");
}
Output
3

The output is 3: the labeled while counts to 3 and the break 'a; leaves it. And a single labeled loop can be both continued and broken by name, which is the form a retry loop usually wants:

Rust
fn main() {
    let mut hits = 0;
    'a: loop {
        hits += 1;
        if hits < 3 {
            continue 'a;
        }
        break 'a;
    }
    println!("{hits}");
}
Output
3

The output is 3: two passes continue the labeled loop, the third breaks it. Both jumps name the same declaration, written once, on the loop.

Fixes in reach order

When E0426 appears, work the use in this order. First, check the spelling against any label declared on an enclosing loop or block: if the diagnostic offers a similarly named label, make the spellings agree and stop there. Second, if no enclosing expression declares the name, decide which loop or block the jump is meant to leave or restart and declare the label there, in the form 'name: in front of that expression. Third, check the scope: a declaration on a later loop, on a loop that has already ended, or on a sibling loop does not cover the use - each target needs its declaration on itself, enclosing the use. Fourth, if the break sits in a plain block, label the block or move the break into a labeled loop; expect E0268 alongside E0426 until the break has a labelable target. Last, in nested loops, give each loop its own distinct label name, so no declaration shadows another and every break and continue states its target.

Decision summary

A label is declared in exactly one place: written with a colon in front of a loop, a while, a for, or a block. Every break 'name and continue 'name must name a label declared on an expression that encloses that use, spelled identically. A use with no such declaration is E0426 - whether the label was never written, was written on a loop that does not enclose the use, belongs to a loop that has ended, or is misspelled. The repair is almost never at the use: it is the declaration, placed on the expression the jump is meant to affect. Labels are what let a break or continue in nested code name an outer loop instead of the innermost one, a labeled loop and a labeled block can carry a value out through their break, and a labeled block is the one target that takes break but not continue.

Checklist

  • Every break 'name and continue 'name names a label declared on a loop or block enclosing that use.
  • The declaration is written in the colon form - 'name: - in front of the target loop or block, not only at the use.
  • Declaration and uses spell the label identically, apostrophe and full name included.
  • The label sits on the expression the jump is meant to leave or restart - in nested loops, the outer target, not automatically the innermost loop.
  • No use relies on a label declared on an earlier, later, or sibling loop; each target carries its own declaration.
  • Nested loops use distinct label names, so no label shadows another.
  • A break meant to carry a value names a labeled loop or a labeled block; a continue names a loop, never a labeled block.

Sources

  • Rust error codes index, E0426 - an undeclared label was used, its erroneous plain-loop example with break 'a;, and its repair declaring 'a: on the loop.
  • The Rust Reference, Loop expressions - the four loop expressions, that all support break and labels, that all except the labeled block support continue, and that only loop and the labeled block evaluate to a value from a break.
  • The Rust Programming Language, Loop Labels - labels on loops, breaking and continuing an outer loop from a nested loop, and the 'label: loop declaration form.

Keep Exploring