Skip to content

Ambiguous error for slice.windows() #107437

Closed
@Kuly14

Description

@Kuly14

I tried to run this code:

fn main() {
    let vec = vec![1, 2, 3, 4];
    for i in 0..vec.len() {
        for b in vec.windows(i) {
            // Do stuff
        }
    }
}

Of course this shouldn't work since you can't create windows that have 0 elements, but the problem is with the runtime error. It just panicks with this err:

thread 'main' panicked at 'size is zero', /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/slice/mod.rs:786:20
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

And it is very unclear where was the mistake.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions