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

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

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-typesystem Area: The 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-typesystem Area: The 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants