Skip to content

loop {break 'outer} should have type ! #23451

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
andersk opened this issue Mar 17, 2015 · 0 comments · Fixed by #23467
Closed

loop {break 'outer} should have type ! #23451

andersk opened this issue Mar 17, 2015 · 0 comments · Fixed by #23467
Labels
A-type-system Area: Type system

Comments

@andersk
Copy link
Contributor

andersk commented Mar 17, 2015

The expression loop {break} has type (), as it must. However, within a second loop labeled 'outer, the expression loop {break 'outer} should have type !, not (). Note that break 'outer and even loop {loop {break 'outer}} are already correctly typed as !.

Example with incorrect type error:

fn foo() {
    'outer: loop {
        let a : i32;
        a = break 'outer  // ok
    }
}

fn bar() {
    'outer: loop {
        let a : i32;
        a = loop {break 'outer}  // error: mismatched types: expected i32, found ()
    }
}

fn baz() {
    'outer: loop {
        let a : i32;
        a = loop {loop {break 'outer}}  // ok
    }
}

I’m using rustc 1.0.0-dev (built 2015-03-17) from ppa:hansjorg/rust.

@kmcallister kmcallister added the A-type-system Area: Type system label Mar 18, 2015
Manishearth pushed a commit to Manishearth/rust that referenced this issue Mar 18, 2015
Closes rust-lang#23451.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Manishearth added a commit to Manishearth/rust that referenced this issue Mar 18, 2015
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants