Skip to content

An variable assigned -1 can be inferred as uint #9037

Closed
@novalis

Description

@novalis
fn bar () -> uint {
    return 5;
}

fn foo (use_bar: bool) -> ~str {
    let mut a = -1;
    if use_bar {
        a = bar();
    }
    if a >= 0 {
        ~"a"
    } else {
        ~"b"
    }
}

fn main() {
    printfln!("%s", foo(false));
    printfln!("%s", foo(true));
}
bad-infer.rs:10:7: 10:13 warning: comparison is useless due to type limits [-W type-limits (default)]
bad-infer.rs:10     if a >= 0 {

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