From f5a2751da597f92426adb9e5a6b51a86c324a6f0 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Sat, 25 Oct 2025 21:24:29 +0200 Subject: [PATCH 1/3] rename `tests/ui/useless_vec{,_unfixable}.rs` will improve the diff for the next commit --- tests/ui/{useless_vec.rs => useless_vec_unfixable.rs} | 0 tests/ui/{useless_vec.stderr => useless_vec_unfixable.stderr} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/ui/{useless_vec.rs => useless_vec_unfixable.rs} (100%) rename tests/ui/{useless_vec.stderr => useless_vec_unfixable.stderr} (92%) diff --git a/tests/ui/useless_vec.rs b/tests/ui/useless_vec_unfixable.rs similarity index 100% rename from tests/ui/useless_vec.rs rename to tests/ui/useless_vec_unfixable.rs diff --git a/tests/ui/useless_vec.stderr b/tests/ui/useless_vec_unfixable.stderr similarity index 92% rename from tests/ui/useless_vec.stderr rename to tests/ui/useless_vec_unfixable.stderr index e47364fb06d3..41a172bd58d1 100644 --- a/tests/ui/useless_vec.stderr +++ b/tests/ui/useless_vec_unfixable.stderr @@ -1,5 +1,5 @@ error: useless use of `vec!` - --> tests/ui/useless_vec.rs:8:26 + --> tests/ui/useless_vec_unfixable.rs:8:26 | LL | let _some_variable = vec![ | __________________________^ From 7534814fc41253ca585c62d41466457ab9f35007 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Sat, 25 Oct 2025 16:20:37 +0200 Subject: [PATCH 2/3] rename lint files to match lint name --- clippy_lints/src/declared_lints.rs | 2 +- clippy_lints/src/lib.rs | 4 +- clippy_lints/src/ptr/ptr_arg.rs | 2 +- clippy_lints/src/{vec.rs => useless_vec.rs} | 0 tests/ui/{vec.fixed => useless_vec.fixed} | 0 tests/ui/{vec.rs => useless_vec.rs} | 0 tests/ui/{vec.stderr => useless_vec.stderr} | 44 ++++++++++----------- 7 files changed, 26 insertions(+), 26 deletions(-) rename clippy_lints/src/{vec.rs => useless_vec.rs} (100%) rename tests/ui/{vec.fixed => useless_vec.fixed} (100%) rename tests/ui/{vec.rs => useless_vec.rs} (100%) rename tests/ui/{vec.stderr => useless_vec.stderr} (82%) diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs index a754eea31165..b251f27a4dcf 100644 --- a/clippy_lints/src/declared_lints.rs +++ b/clippy_lints/src/declared_lints.rs @@ -777,7 +777,7 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[ crate::use_self::USE_SELF_INFO, crate::useless_concat::USELESS_CONCAT_INFO, crate::useless_conversion::USELESS_CONVERSION_INFO, - crate::vec::USELESS_VEC_INFO, + crate::useless_vec::USELESS_VEC_INFO, crate::vec_init_then_push::VEC_INIT_THEN_PUSH_INFO, crate::visibility::NEEDLESS_PUB_SELF_INFO, crate::visibility::PUB_WITHOUT_SHORTHAND_INFO, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 033f85e70ef0..a769ed3e580d 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -386,7 +386,7 @@ mod upper_case_acronyms; mod use_self; mod useless_concat; mod useless_conversion; -mod vec; +mod useless_vec; mod vec_init_then_push; mod visibility; mod volatile_composites; @@ -530,7 +530,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co store.register_late_pass(move |_| Box::new(transmute::Transmute::new(conf))); store.register_late_pass(move |_| Box::new(cognitive_complexity::CognitiveComplexity::new(conf))); store.register_late_pass(move |_| Box::new(escape::BoxedLocal::new(conf))); - store.register_late_pass(move |_| Box::new(vec::UselessVec::new(conf))); + store.register_late_pass(move |_| Box::new(useless_vec::UselessVec::new(conf))); store.register_late_pass(move |_| Box::new(panic_unimplemented::PanicUnimplemented::new(conf))); store.register_late_pass(|_| Box::new(strings::StringLitAsBytes)); store.register_late_pass(|_| Box::new(derive::Derive)); diff --git a/clippy_lints/src/ptr/ptr_arg.rs b/clippy_lints/src/ptr/ptr_arg.rs index fd9230f00a8b..332acb746a7a 100644 --- a/clippy_lints/src/ptr/ptr_arg.rs +++ b/clippy_lints/src/ptr/ptr_arg.rs @@ -23,7 +23,7 @@ use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use std::{fmt, iter}; -use crate::vec::is_allowed_vec_method; +use crate::useless_vec::is_allowed_vec_method; pub(super) fn check_body<'tcx>( cx: &LateContext<'tcx>, diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/useless_vec.rs similarity index 100% rename from clippy_lints/src/vec.rs rename to clippy_lints/src/useless_vec.rs diff --git a/tests/ui/vec.fixed b/tests/ui/useless_vec.fixed similarity index 100% rename from tests/ui/vec.fixed rename to tests/ui/useless_vec.fixed diff --git a/tests/ui/vec.rs b/tests/ui/useless_vec.rs similarity index 100% rename from tests/ui/vec.rs rename to tests/ui/useless_vec.rs diff --git a/tests/ui/vec.stderr b/tests/ui/useless_vec.stderr similarity index 82% rename from tests/ui/vec.stderr rename to tests/ui/useless_vec.stderr index d16c8a8944a2..25be94072e2d 100644 --- a/tests/ui/vec.stderr +++ b/tests/ui/useless_vec.stderr @@ -1,5 +1,5 @@ error: useless use of `vec!` - --> tests/ui/vec.rs:30:14 + --> tests/ui/useless_vec.rs:30:14 | LL | on_slice(&vec![]); | ^^^^^^^ help: you can use a slice directly: `&[]` @@ -8,127 +8,127 @@ LL | on_slice(&vec![]); = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` error: useless use of `vec!` - --> tests/ui/vec.rs:33:18 + --> tests/ui/useless_vec.rs:33:18 | LL | on_mut_slice(&mut vec![]); | ^^^^^^^^^^^ help: you can use a slice directly: `&mut []` error: useless use of `vec!` - --> tests/ui/vec.rs:36:14 + --> tests/ui/useless_vec.rs:36:14 | LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:39:18 + --> tests/ui/useless_vec.rs:39:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:42:14 + --> tests/ui/useless_vec.rs:42:14 | LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:45:18 + --> tests/ui/useless_vec.rs:45:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:48:14 + --> tests/ui/useless_vec.rs:48:14 | LL | on_slice(&vec!(1, 2)); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:51:18 + --> tests/ui/useless_vec.rs:51:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:54:14 + --> tests/ui/useless_vec.rs:54:14 | LL | on_slice(&vec![1; 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:57:18 + --> tests/ui/useless_vec.rs:57:18 | LL | on_mut_slice(&mut vec![1; 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1; 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:84:19 + --> tests/ui/useless_vec.rs:84:19 | LL | let _x: i32 = vec![1, 2, 3].iter().sum(); | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:88:17 + --> tests/ui/useless_vec.rs:88:17 | LL | let mut x = vec![1, 2, 3]; | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:95:22 + --> tests/ui/useless_vec.rs:95:22 | LL | let _x: &[i32] = &vec![1, 2, 3]; | ^^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:98:14 + --> tests/ui/useless_vec.rs:98:14 | LL | for _ in vec![1, 2, 3] {} | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:138:20 + --> tests/ui/useless_vec.rs:138:20 | LL | for _string in vec![repro!(true), repro!(null)] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]` error: useless use of `vec!` - --> tests/ui/vec.rs:156:18 + --> tests/ui/useless_vec.rs:156:18 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:156:30 + --> tests/ui/useless_vec.rs:156:30 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1; 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:177:14 + --> tests/ui/useless_vec.rs:177:14 | LL | for a in vec![1, 2, 3] { | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/vec.rs:182:14 + --> tests/ui/useless_vec.rs:182:14 | LL | for a in vec![String::new(), String::new()] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]` error: useless use of `vec!` - --> tests/ui/vec.rs:215:33 + --> tests/ui/useless_vec.rs:215:33 | LL | this_macro_doesnt_need_vec!(vec![1]); | ^^^^^^^ help: you can use an array directly: `[1]` error: useless use of `vec!` - --> tests/ui/vec.rs:242:14 + --> tests/ui/useless_vec.rs:242:14 | LL | for a in &(vec![1, 2]) {} | ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/vec.rs:250:13 + --> tests/ui/useless_vec.rs:250:13 | LL | let v = &vec![]; | ^^^^^^^ help: you can use a slice directly: `&[]` From a8a8e989700b7b33ee1e66b21f9b6c02174aebb2 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Sat, 25 Oct 2025 16:37:22 +0200 Subject: [PATCH 3/3] clean-up - move `is_allowed_vec_method` (a stripped-down version of it, anyway, as the function doesn't make sense as is out of context) to utils, as it's shared between `useless_vec` and `ptr_arg` - add another test for non-standard macro brace case - rm unneeded `allow`s - rm duplicated tests - add comments to some tests --- clippy_lints/src/ptr/ptr_arg.rs | 6 +-- clippy_lints/src/useless_vec.rs | 35 +++++++------- clippy_utils/src/lib.rs | 3 ++ tests/ui/useless_vec.fixed | 38 ++++++++------- tests/ui/useless_vec.rs | 38 ++++++++------- tests/ui/useless_vec.stderr | 66 +++++++++++---------------- tests/ui/useless_vec_unfixable.rs | 1 - tests/ui/useless_vec_unfixable.stderr | 2 +- 8 files changed, 85 insertions(+), 104 deletions(-) diff --git a/clippy_lints/src/ptr/ptr_arg.rs b/clippy_lints/src/ptr/ptr_arg.rs index 332acb746a7a..4bfff64b1bd4 100644 --- a/clippy_lints/src/ptr/ptr_arg.rs +++ b/clippy_lints/src/ptr/ptr_arg.rs @@ -2,7 +2,7 @@ use super::PTR_ARG; use clippy_utils::diagnostics::span_lint_hir_and_then; use clippy_utils::res::MaybeResPath; use clippy_utils::source::SpanRangeExt; -use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, sym}; +use clippy_utils::{VEC_METHODS_SHADOWING_SLICE_METHODS, get_expr_use_or_unification_node, is_lint_allowed, sym}; use hir::LifetimeKind; use rustc_abi::ExternAbi; use rustc_errors::Applicability; @@ -23,8 +23,6 @@ use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _; use std::{fmt, iter}; -use crate::useless_vec::is_allowed_vec_method; - pub(super) fn check_body<'tcx>( cx: &LateContext<'tcx>, body: &Body<'tcx>, @@ -383,7 +381,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[ // Some methods exist on both `[T]` and `Vec`, such as `len`, where the receiver type // doesn't coerce to a slice and our adjusted type check below isn't enough, // but it would still be valid to call with a slice - if is_allowed_vec_method(use_expr) { + if VEC_METHODS_SHADOWING_SLICE_METHODS.contains(&name) { return; } } diff --git a/clippy_lints/src/useless_vec.rs b/clippy_lints/src/useless_vec.rs index b87db836869d..28c339ce2b7d 100644 --- a/clippy_lints/src/useless_vec.rs +++ b/clippy_lints/src/useless_vec.rs @@ -10,7 +10,7 @@ use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::source::SpanRangeExt; use clippy_utils::ty::is_copy; use clippy_utils::visitors::for_each_local_use_after_expr; -use clippy_utils::{get_parent_expr, higher, is_in_test, span_contains_comment, sym}; +use clippy_utils::{VEC_METHODS_SHADOWING_SLICE_METHODS, get_parent_expr, higher, is_in_test, span_contains_comment}; use rustc_errors::Applicability; use rustc_hir::{BorrowKind, Expr, ExprKind, HirId, LetStmt, Mutability, Node, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; @@ -123,8 +123,16 @@ impl UselessVec { // allow indexing into a vec and some set of allowed method calls that exist on slices, too if let Some(parent) = get_parent_expr(cx, expr) && (adjusts_to_slice(cx, expr) - || matches!(parent.kind, ExprKind::Index(..)) - || is_allowed_vec_method(parent)) + || match parent.kind { + ExprKind::Index(..) => true, + ExprKind::MethodCall(path, _, [], _) => { + // If the given expression is a method call to a `Vec` method that also exists on + // slices, it means that this expression does not actually require a `Vec` and could + // just work with an array. + VEC_METHODS_SHADOWING_SLICE_METHODS.contains(&path.ident.name) + }, + _ => false, + }) { ControlFlow::Continue(()) } else { @@ -144,8 +152,9 @@ impl UselessVec { VecToArray::Impossible }, // search for `for _ in vec![...]` - Node::Expr(Expr { span, .. }) - if span.is_desugaring(DesugaringKind::ForLoop) && self.msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) => + Node::Expr(expr) + if expr.span.is_desugaring(DesugaringKind::ForLoop) + && self.msrv.meets(cx, msrvs::ARRAY_INTO_ITERATOR) => { VecToArray::Possible }, @@ -276,9 +285,8 @@ impl SuggestedType { assert!(args_span.is_none_or(|s| !s.from_expansion())); assert!(len_span.is_none_or(|s| !s.from_expansion())); - let maybe_args = args_span - .map(|sp| sp.get_source_text(cx).expect("spans are always crate-local")) - .map_or(String::new(), |x| x.to_owned()); + let maybe_args = args_span.map(|sp| sp.get_source_text(cx).expect("spans are always crate-local")); + let maybe_args = maybe_args.as_deref().unwrap_or_default(); let maybe_len = len_span .map(|sp| sp.get_source_text(cx).expect("spans are always crate-local")) .map(|st| format!("; {st}")) @@ -301,17 +309,6 @@ fn adjusts_to_slice(cx: &LateContext<'_>, e: &Expr<'_>) -> bool { matches!(cx.typeck_results().expr_ty_adjusted(e).kind(), ty::Ref(_, ty, _) if ty.is_slice()) } -/// Checks if the given expression is a method call to a `Vec` method -/// that also exists on slices. If this returns true, it means that -/// this expression does not actually require a `Vec` and could just work with an array. -pub fn is_allowed_vec_method(e: &Expr<'_>) -> bool { - if let ExprKind::MethodCall(path, _, [], _) = e.kind { - matches!(path.ident.name, sym::as_ptr | sym::is_empty | sym::len) - } else { - false - } -} - fn suggest_type(expr: &Expr<'_>) -> SuggestedType { if let ExprKind::AddrOf(BorrowKind::Ref, mutability, _) = expr.kind { // `expr` is `&vec![_]`, so suggest `&[_]` (or `&mut[_]` resp.) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 46c5af058ccc..3124ada0e94a 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -136,6 +136,9 @@ use crate::res::{MaybeDef, MaybeQPath, MaybeResPath}; use crate::ty::{adt_and_variant_of_res, can_partially_move_ty, expr_sig, is_copy, is_recursively_primitive_type}; use crate::visitors::for_each_expr_without_closures; +/// Methods on `Vec` that also exists on slices. +pub const VEC_METHODS_SHADOWING_SLICE_METHODS: [Symbol; 3] = [sym::as_ptr, sym::is_empty, sym::len]; + #[macro_export] macro_rules! extract_msrv_attr { () => { diff --git a/tests/ui/useless_vec.fixed b/tests/ui/useless_vec.fixed index 55742459c92c..3cea4862611d 100644 --- a/tests/ui/useless_vec.fixed +++ b/tests/ui/useless_vec.fixed @@ -1,5 +1,4 @@ #![warn(clippy::useless_vec)] -#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args, unused)] use std::rc::Rc; @@ -39,17 +38,14 @@ fn main() { on_mut_slice(&mut [1, 2]); //~^ useless_vec - on_slice(&[1, 2]); - //~^ useless_vec - on_slice(&[1, 2]); - on_mut_slice(&mut [1, 2]); - //~^ useless_vec #[rustfmt::skip] - on_slice(&[1, 2]); - //~^ useless_vec - on_slice(&[1, 2]); - on_mut_slice(&mut [1, 2]); - //~^ useless_vec + #[allow(clippy::nonstandard_macro_braces)] // not an `expect` as it will only lint _before_ the fix + { + on_slice(&[1, 2]); + //~^ useless_vec + on_mut_slice(&mut [1, 2]); + //~^ useless_vec + }; on_slice(&[1; 2]); //~^ useless_vec @@ -75,22 +71,24 @@ fn main() { on_vec(&vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack` on_mut_vec(&mut vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack` - // Ok + // Ok, size of `vec` higher than `too_large_for_stack` for a in vec![1; 201] { - println!("{:?}", a); + println!("{a:?}"); } // https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-783979246 let _x: i32 = [1, 2, 3].iter().sum(); //~^ useless_vec - // Do lint - let mut x = [1, 2, 3]; - //~^ useless_vec - x.fill(123); - dbg!(x[0]); - dbg!(x.len()); - dbg!(x.iter().sum::()); + // Do lint, only used as slice + { + let mut x = [1, 2, 3]; + //~^ useless_vec + x.fill(123); + dbg!(x[0]); + dbg!(x.len()); + dbg!(x.iter().sum::()); + } let _x: &[i32] = &[1, 2, 3]; //~^ useless_vec diff --git a/tests/ui/useless_vec.rs b/tests/ui/useless_vec.rs index fbf7131323c3..2b5d71ae7fa4 100644 --- a/tests/ui/useless_vec.rs +++ b/tests/ui/useless_vec.rs @@ -1,5 +1,4 @@ #![warn(clippy::useless_vec)] -#![allow(clippy::nonstandard_macro_braces, clippy::uninlined_format_args, unused)] use std::rc::Rc; @@ -39,17 +38,14 @@ fn main() { on_mut_slice(&mut vec![1, 2]); //~^ useless_vec - on_slice(&vec![1, 2]); - //~^ useless_vec - on_slice(&[1, 2]); - on_mut_slice(&mut vec![1, 2]); - //~^ useless_vec #[rustfmt::skip] - on_slice(&vec!(1, 2)); - //~^ useless_vec - on_slice(&[1, 2]); - on_mut_slice(&mut vec![1, 2]); - //~^ useless_vec + #[allow(clippy::nonstandard_macro_braces)] // not an `expect` as it will only lint _before_ the fix + { + on_slice(&vec!(1, 2)); + //~^ useless_vec + on_mut_slice(&mut vec!(1, 2)); + //~^ useless_vec + }; on_slice(&vec![1; 2]); //~^ useless_vec @@ -75,22 +71,24 @@ fn main() { on_vec(&vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack` on_mut_vec(&mut vec![1; 201]); // Ok, size of `vec` higher than `too_large_for_stack` - // Ok + // Ok, size of `vec` higher than `too_large_for_stack` for a in vec![1; 201] { - println!("{:?}", a); + println!("{a:?}"); } // https://github.com/rust-lang/rust-clippy/issues/2262#issuecomment-783979246 let _x: i32 = vec![1, 2, 3].iter().sum(); //~^ useless_vec - // Do lint - let mut x = vec![1, 2, 3]; - //~^ useless_vec - x.fill(123); - dbg!(x[0]); - dbg!(x.len()); - dbg!(x.iter().sum::()); + // Do lint, only used as slice + { + let mut x = vec![1, 2, 3]; + //~^ useless_vec + x.fill(123); + dbg!(x[0]); + dbg!(x.len()); + dbg!(x.iter().sum::()); + } let _x: &[i32] = &vec![1, 2, 3]; //~^ useless_vec diff --git a/tests/ui/useless_vec.stderr b/tests/ui/useless_vec.stderr index 25be94072e2d..65120d8b338f 100644 --- a/tests/ui/useless_vec.stderr +++ b/tests/ui/useless_vec.stderr @@ -1,5 +1,5 @@ error: useless use of `vec!` - --> tests/ui/useless_vec.rs:30:14 + --> tests/ui/useless_vec.rs:29:14 | LL | on_slice(&vec![]); | ^^^^^^^ help: you can use a slice directly: `&[]` @@ -8,130 +8,118 @@ LL | on_slice(&vec![]); = help: to override `-D warnings` add `#[allow(clippy::useless_vec)]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:33:18 + --> tests/ui/useless_vec.rs:32:18 | LL | on_mut_slice(&mut vec![]); | ^^^^^^^^^^^ help: you can use a slice directly: `&mut []` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:36:14 + --> tests/ui/useless_vec.rs:35:14 | LL | on_slice(&vec![1, 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:39:18 + --> tests/ui/useless_vec.rs:38:18 | LL | on_mut_slice(&mut vec![1, 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:42:14 + --> tests/ui/useless_vec.rs:44:18 | -LL | on_slice(&vec![1, 2]); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> tests/ui/useless_vec.rs:45:18 - | -LL | on_mut_slice(&mut vec![1, 2]); - | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` +LL | on_slice(&vec!(1, 2)); + | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:48:14 + --> tests/ui/useless_vec.rs:46:22 | -LL | on_slice(&vec!(1, 2)); - | ^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` - -error: useless use of `vec!` - --> tests/ui/useless_vec.rs:51:18 - | -LL | on_mut_slice(&mut vec![1, 2]); - | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` +LL | on_mut_slice(&mut vec!(1, 2)); + | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1, 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:54:14 + --> tests/ui/useless_vec.rs:50:14 | LL | on_slice(&vec![1; 2]); | ^^^^^^^^^^^ help: you can use a slice directly: `&[1; 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:57:18 + --> tests/ui/useless_vec.rs:53:18 | LL | on_mut_slice(&mut vec![1; 2]); | ^^^^^^^^^^^^^^^ help: you can use a slice directly: `&mut [1; 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:84:19 + --> tests/ui/useless_vec.rs:80:19 | LL | let _x: i32 = vec![1, 2, 3].iter().sum(); | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:88:17 + --> tests/ui/useless_vec.rs:85:21 | -LL | let mut x = vec![1, 2, 3]; - | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` +LL | let mut x = vec![1, 2, 3]; + | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:95:22 + --> tests/ui/useless_vec.rs:93:22 | LL | let _x: &[i32] = &vec![1, 2, 3]; | ^^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:98:14 + --> tests/ui/useless_vec.rs:96:14 | LL | for _ in vec![1, 2, 3] {} | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:138:20 + --> tests/ui/useless_vec.rs:136:20 | LL | for _string in vec![repro!(true), repro!(null)] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:156:18 + --> tests/ui/useless_vec.rs:154:18 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1, 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:156:30 + --> tests/ui/useless_vec.rs:154:30 | LL | in_macro!(1, vec![1, 2], vec![1; 2]); | ^^^^^^^^^^ help: you can use an array directly: `[1; 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:177:14 + --> tests/ui/useless_vec.rs:175:14 | LL | for a in vec![1, 2, 3] { | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:182:14 + --> tests/ui/useless_vec.rs:180:14 | LL | for a in vec![String::new(), String::new()] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:215:33 + --> tests/ui/useless_vec.rs:213:33 | LL | this_macro_doesnt_need_vec!(vec![1]); | ^^^^^^^ help: you can use an array directly: `[1]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:242:14 + --> tests/ui/useless_vec.rs:240:14 | LL | for a in &(vec![1, 2]) {} | ^^^^^^^^^^^^^ help: you can use a slice directly: `&[1, 2]` error: useless use of `vec!` - --> tests/ui/useless_vec.rs:250:13 + --> tests/ui/useless_vec.rs:248:13 | LL | let v = &vec![]; | ^^^^^^^ help: you can use a slice directly: `&[]` -error: aborting due to 22 previous errors +error: aborting due to 20 previous errors diff --git a/tests/ui/useless_vec_unfixable.rs b/tests/ui/useless_vec_unfixable.rs index 880809f81d7a..7f45f4df5ee6 100644 --- a/tests/ui/useless_vec_unfixable.rs +++ b/tests/ui/useless_vec_unfixable.rs @@ -1,5 +1,4 @@ //@no-rustfix: no suggestions - #![warn(clippy::useless_vec)] // Regression test for . diff --git a/tests/ui/useless_vec_unfixable.stderr b/tests/ui/useless_vec_unfixable.stderr index 41a172bd58d1..980194ac7191 100644 --- a/tests/ui/useless_vec_unfixable.stderr +++ b/tests/ui/useless_vec_unfixable.stderr @@ -1,5 +1,5 @@ error: useless use of `vec!` - --> tests/ui/useless_vec_unfixable.rs:8:26 + --> tests/ui/useless_vec_unfixable.rs:7:26 | LL | let _some_variable = vec![ | __________________________^