Skip to content

Labels on breaks ignored for inference #4663

@robojumper

Description

@robojumper

Contrived example:

fn foo() {
    let _x = || 'outer: loop {
        let inner = 'inner: loop {
            let i = Default::default();
            if (break 'outer i) {
                loop { break 'inner 5i8; };
            } else if true {
                break 'inner 6;
            }
            break 7;
        };
        break inner < 8;
    };
}

rust-analyzer currently infers inner, i, 6, 7, and 8 to be of type i32. Correct would be inner, 6, 7: i8 and i: bool.

I briefly looked into this and decided it would be necessary to extend the HIR Expr with block labels / break/continue targets. The AST currently only offers the pseudo-lifetimes as SyntaxTokens. What would be a good type to represent the labels in the HIR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions