Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 5459679

Browse files
committed
[Clippy] Swap VecArgs::hir to use diagnostic items instead of paths
1 parent f66915e commit 5459679

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

clippy_lints/src/slow_vector_initialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl SlowVectorInit {
153153
&& is_expr_path_def_path(cx, func, &paths::VEC_WITH_CAPACITY)
154154
{
155155
Some(InitializedSize::Initialized(len_expr))
156-
} else if matches!(expr.kind, ExprKind::Call(func, _) if is_expr_path_def_path(cx, func, &paths::VEC_NEW)) {
156+
} else if matches!(expr.kind, ExprKind::Call(func, _) if is_path_diagnostic_item(cx, func, sym::vec_new)) {
157157
Some(InitializedSize::Uninitialized)
158158
} else {
159159
None

clippy_utils/src/higher.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use crate::consts::{ConstEvalCtxt, Constant};
66
use crate::ty::is_type_diagnostic_item;
7-
use crate::{is_expn_of, match_def_path, paths};
7+
use crate::is_expn_of;
88

99
use rustc_ast::ast;
1010
use rustc_hir as hir;
@@ -297,10 +297,10 @@ impl<'a> VecArgs<'a> {
297297
&& is_expn_of(fun.span, "vec").is_some()
298298
&& let Some(fun_def_id) = cx.qpath_res(qpath, fun.hir_id).opt_def_id()
299299
{
300-
return if match_def_path(cx, fun_def_id, &paths::VEC_FROM_ELEM) && args.len() == 2 {
300+
return if cx.tcx.is_diagnostic_item(sym::vec_from_elem, fun_def_id) && args.len() == 2 {
301301
// `vec![elem; size]` case
302302
Some(VecArgs::Repeat(&args[0], &args[1]))
303-
} else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
303+
} else if cx.tcx.is_diagnostic_item(sym::slice_into_vec, fun_def_id) && args.len() == 1 {
304304
// `vec![a, b, c]` case
305305
if let ExprKind::Call(_, [arg]) = &args[0].kind
306306
&& let ExprKind::Array(args) = arg.kind
@@ -309,7 +309,7 @@ impl<'a> VecArgs<'a> {
309309
} else {
310310
None
311311
}
312-
} else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() {
312+
} else if cx.tcx.is_diagnostic_item(sym::vec_new, fun_def_id) && args.is_empty() {
313313
Some(VecArgs::Vec(&[]))
314314
} else {
315315
None

clippy_utils/src/paths.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub const REGEX_NEW: [&str; 3] = ["regex", "Regex", "new"];
4949
pub const REGEX_SET_NEW: [&str; 3] = ["regex", "RegexSet", "new"];
5050
pub const SERDE_DESERIALIZE: [&str; 3] = ["serde", "de", "Deserialize"];
5151
pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
52-
pub const SLICE_INTO_VEC: [&str; 4] = ["alloc", "slice", "<impl [T]>", "into_vec"];
5352
pub const STD_IO_SEEK_FROM_CURRENT: [&str; 4] = ["std", "io", "SeekFrom", "Current"];
5453
pub const STD_IO_SEEKFROM_START: [&str; 4] = ["std", "io", "SeekFrom", "Start"];
5554
pub const STRING_NEW: [&str; 4] = ["alloc", "string", "String", "new"];
@@ -73,8 +72,6 @@ pub const TOKIO_IO_ASYNCWRITEEXT: [&str; 5] = ["tokio", "io", "util", "async_wri
7372
pub const TOKIO_IO_OPEN_OPTIONS: [&str; 4] = ["tokio", "fs", "open_options", "OpenOptions"];
7473
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
7574
pub const TOKIO_IO_OPEN_OPTIONS_NEW: [&str; 5] = ["tokio", "fs", "open_options", "OpenOptions", "new"];
76-
pub const VEC_FROM_ELEM: [&str; 3] = ["alloc", "vec", "from_elem"];
77-
pub const VEC_NEW: [&str; 4] = ["alloc", "vec", "Vec", "new"];
7875
pub const VEC_WITH_CAPACITY: [&str; 4] = ["alloc", "vec", "Vec", "with_capacity"];
7976
pub const INSTANT_NOW: [&str; 4] = ["std", "time", "Instant", "now"];
8077
pub const VEC_IS_EMPTY: [&str; 4] = ["alloc", "vec", "Vec", "is_empty"];

0 commit comments

Comments
 (0)