Skip to content

Wrong compiler error for assignment in if conditonal #17283

Closed
@anshin

Description

@anshin

I'm running a recent nightly (rustc 0.12.0-pre-nightly (0d3bd7720 2014-08-27 21:31:13 +0000)) on x86_64 GNU/Linux. I get this error:

assign.rs:6:18: 6:19 error: expected `:`, found `!`
assign.rs:6             print!("{}", i);
                             ^

with the following program:

fn main() {
    let n = 11u;

    for mut i in range(1u, 10) {
        if i = n {
            print!("{}", i);
        }
    }
}

I don't know whether assignments within if conditions are supposed to be allowed, but the compiler should probably recognize that case and report something more useful. I also have no idea what it wants with the colon.

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