Skip to content

Immutable binding becomes mutable in const block expression #15303

Closed
@Kimundi

Description

@Kimundi

Code (playpen):

static UINT: uint = {
    // BUG, allows assigning immutable variable x
    fn foo() -> uint {
        let x;
        x = 100;
        x = 200;
        x
    }
    100
};

// OK, produces a error about assigning immutable variable x
fn foo() -> uint {
    let x;
    x = 100;
    x = 200;
    x
}

fn main() {
    println!("{}", UINT)
}

Complete output:

<anon>:16:5: 16:12 error: re-assignment of immutable variable `x`
<anon>:16     x = 200;
              ^~~~~~~
<anon>:15:5: 15:12 note: prior assignment occurs here
<anon>:15     x = 100;
              ^~~~~~~
error: aborting due to previous error
playpen: application terminated with error code 101
Program ended.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions