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

Commit f66915e

Browse files
committed
[Clippy] Swap single_char_add_str/format_push_string to use diagnostic items instead of paths
1 parent 959f7a2 commit f66915e

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed

clippy_lints/src/format_push_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::ty::is_type_lang_item;
3-
use clippy_utils::{higher, match_def_path, paths};
3+
use clippy_utils::higher;
44
use rustc_hir::{BinOpKind, Expr, ExprKind, LangItem, MatchSource};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::declare_lint_pass;
@@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatPushString {
7070
let arg = match expr.kind {
7171
ExprKind::MethodCall(_, _, [arg], _) => {
7272
if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
73-
&& match_def_path(cx, fn_def_id, &paths::PUSH_STR)
73+
&& cx.tcx.is_diagnostic_item(sym::string_push_str, fn_def_id)
7474
{
7575
arg
7676
} else {

clippy_lints/src/methods/single_char_add_str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use crate::methods::{single_char_insert_string, single_char_push_string};
2-
use clippy_utils::{match_def_path, paths};
32
use rustc_hir as hir;
43
use rustc_lint::LateContext;
4+
use rustc_span::sym;
55

66
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
77
if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) {
8-
if match_def_path(cx, fn_def_id, &paths::PUSH_STR) {
8+
if cx.tcx.is_diagnostic_item(sym::string_push_str, fn_def_id) {
99
single_char_push_string::check(cx, expr, receiver, args);
10-
} else if match_def_path(cx, fn_def_id, &paths::INSERT_STR) {
10+
} else if cx.tcx.is_diagnostic_item(sym::string_insert_str, fn_def_id) {
1111
single_char_insert_string::check(cx, expr, receiver, args);
1212
}
1313
}

clippy_utils/src/paths.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub const HASHSET_ITER_TY: [&str; 5] = ["std", "collections", "hash", "set", "It
2929
pub const HASHSET_DRAIN: [&str; 5] = ["std", "collections", "hash", "set", "Drain"];
3030
pub const IDENT: [&str; 3] = ["rustc_span", "symbol", "Ident"];
3131
pub const IDENT_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Ident", "as_str"];
32-
pub const INSERT_STR: [&str; 4] = ["alloc", "string", "String", "insert_str"];
3332
pub const ITERTOOLS_NEXT_TUPLE: [&str; 3] = ["itertools", "Itertools", "next_tuple"];
3433
pub const KW_MODULE: [&str; 3] = ["rustc_span", "symbol", "kw"];
3534
pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"];
@@ -42,7 +41,6 @@ pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwL
4241
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockWriteGuard"];
4342
#[cfg_attr(not(unix), allow(clippy::invalid_paths))]
4443
pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"];
45-
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
4644
pub const REGEX_BUILDER_NEW: [&str; 3] = ["regex", "RegexBuilder", "new"];
4745
pub const REGEX_BYTES_BUILDER_NEW: [&str; 4] = ["regex", "bytes", "RegexBuilder", "new"];
4846
pub const REGEX_BYTES_NEW: [&str; 4] = ["regex", "bytes", "Regex", "new"];

0 commit comments

Comments
 (0)