Skip to content

match_on_vec_items: false positive on match vec[..] #5551

Closed
@goffrie

Description

@goffrie

Sample program:

fn main() {
    let x = vec![1,2,3];
    match x[..] {
        [1, 2, 3] => println!("123"),
        _ => println!("not 123"),
    }
}

Clippy output:

error: indexing into a vector may panic
 --> src/main.rs:3:11
  |
3 |     match x[..] {
  |           ^^^^^ help: try this: `x.get(..)`
  |
  = note: `#[deny(clippy::match_on_vec_items)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_on_vec_items

error: aborting due to previous error

However, this use of indexing is infallible.

(note that I'm silencing this lint globally anyway because I don't consider it useful)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesgood 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