From b76e0426a115310c454d1846d53b4d263180065c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 31 Dec 2024 00:47:11 +0100 Subject: [PATCH] Add regression test for `useless_vec` with code comments --- tests/ui/useless_vec.rs | 15 +++++++++++++++ tests/ui/useless_vec.stderr | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/ui/useless_vec.rs create mode 100644 tests/ui/useless_vec.stderr diff --git a/tests/ui/useless_vec.rs b/tests/ui/useless_vec.rs new file mode 100644 index 0000000000000..880809f81d7ae --- /dev/null +++ b/tests/ui/useless_vec.rs @@ -0,0 +1,15 @@ +//@no-rustfix: no suggestions + +#![warn(clippy::useless_vec)] + +// Regression test for . +fn foo() { + // There should be no suggestion in this case. + let _some_variable = vec![ + //~^ useless_vec + 1, 2, // i'm here to stay + 3, 4, // but this one going away ;-; + ]; // that is life anyways +} + +fn main() {} diff --git a/tests/ui/useless_vec.stderr b/tests/ui/useless_vec.stderr new file mode 100644 index 0000000000000..e47364fb06d3b --- /dev/null +++ b/tests/ui/useless_vec.stderr @@ -0,0 +1,21 @@ +error: useless use of `vec!` + --> tests/ui/useless_vec.rs:8:26 + | +LL | let _some_variable = vec![ + | __________________________^ +LL | | +LL | | 1, 2, // i'm here to stay +LL | | 3, 4, // but this one going away ;-; +LL | | ]; // that is life anyways + | |_____^ + | + = note: `-D clippy::useless-vec` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` +help: you can use an array directly + | +LL ~ let _some_variable = [1, 2, // i'm here to stay +LL ~ 3, 4]; // that is life anyways + | + +error: aborting due to 1 previous error +