Skip to content

Clippy applies wrong fix for useless_vec for Edition 2021 #111034

Closed
rust-lang/rust-clippy
#10909
@yongqli

Description

@yongqli

Clippy applies the wrong fix to the following code:

fn g() {
    for x in vec![0, 1] {
        f(x);
    }
}

fn f(x: usize) { }

with the error:

The following errors were reported:
error[E0308]: mismatched types
  --> crate/src/lib.rs:8:11
   |
8  |         f(x);
   |         - ^ expected `usize`, found `&{integer}`
   |         |
   |         arguments to this function are incorrect
   |
note: function defined here
  --> crate/src/lib.rs:12:4
   |
12 | fn f(_x: usize) { }
   |    ^ ---------
help: consider dereferencing the borrow
   |
8  |         f(*x);
   |           +

It seems that clippy replaced vec![0, 1] with &[0, 1], which is not correct. For Edition 2021, it should replace it with [0, 1] instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-clippyArea: ClippyC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions