Skip to content

Vec::swap_remove fails if the vector is empty. #16200

Closed
@kennytm

Description

@kennytm

Sample code:

fn main() {
    let mut x: Vec<int> = vec!();
    let y = x.swap_remove(0);
    println!("{}", y);
}

Expected to print None, but instead it fails with:

task '<main>' failed at 'index out of bounds: the len is 0 but the index is 0', src/test.rs:1

rustc version: 0.12.0-pre.

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