Skip to content

False positive in reversed_empty_ranges used with Vec::splice #5689

@dtolnay

Description

@dtolnay
fn main() {
    let mut v = vec![3, 2, 1];
    v.splice(0..0, std::iter::repeat(0).take(4));
    println!("{:?}", v);  // [0, 0, 0, 0, 3, 2, 1]
}
error: this range is empty so it will yield no values
 --> src/main.rs:3:14
  |
3 |     v.splice(0..0, std::iter::repeat(0).take(4));
  |              ^^^^
  |
  = note: `#[deny(clippy::reversed_empty_ranges)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#reversed_empty_ranges

I believe this is a correct use of an empty range.
https://doc.rust-lang.org/std/vec/struct.Vec.html#method.splice

Mentioning @ebroto @yaahc who touched this lint recently in #5583.


clippy 0.0.212 (826cb06 2020-06-05)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't havegood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions