Skip to content

Error for uninitialized vec is unhelpful #2088

Closed
@evanmcc

Description

@evanmcc

trying to compile:

fn main() {
    let bar = ["aaaaaa", "bbbbbb", "cccccc"];
    let mut foo: [str];

    for b in bar { foo += [b]; }
}

fails with:

un.rs:9:8: 9:11 error: unsatisfied precondition constraint (for example, init(foo id=10 - arising from un.rs:6:12: 6:22)) for expression:
foo
precondition:
init(foo id=10 - arising from un.rs:6:12: 6:22)
prestate:
!init(main! id=101 - arising from un.rs:1:0: 1:0), !init(main id=100 - arising from un.rs:1:0: 1:0), init(bar id=2 - arising from un.rs:4:8: 4:44), !init(foo id=10 - arising from un.rs:6:12: 6:22), init(b id=17 - arising from un.rs:8:8: 8:9)
un.rs:9         foo += [b];
                ^~~

The fixed code below (note line 3) compiles correctly:

fn main() {
    let bar = ["aaaaaa", "bbbbbb", "cccccc"];
    let mut foo: [str] = [];

    for b in bar { foo += [b]; }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions