Skip to content

Commit

Permalink
[Clippy] Swap single_char_add_str/format_push_string to use diagn…
Browse files Browse the repository at this point in the history
…ostic items instead of paths
  • Loading branch information
GnomedDev committed Sep 19, 2024
1 parent 959f7a2 commit f66915e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/format_push_string.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::ty::is_type_lang_item;
use clippy_utils::{higher, match_def_path, paths};
use clippy_utils::higher;
use rustc_hir::{BinOpKind, Expr, ExprKind, LangItem, MatchSource};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
Expand Down Expand Up @@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatPushString {
let arg = match expr.kind {
ExprKind::MethodCall(_, _, [arg], _) => {
if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
&& match_def_path(cx, fn_def_id, &paths::PUSH_STR)
&& cx.tcx.is_diagnostic_item(sym::string_push_str, fn_def_id)
{
arg
} else {
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/single_char_add_str.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::methods::{single_char_insert_string, single_char_push_string};
use clippy_utils::{match_def_path, paths};
use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_span::sym;

pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, receiver: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) {
if match_def_path(cx, fn_def_id, &paths::PUSH_STR) {
if cx.tcx.is_diagnostic_item(sym::string_push_str, fn_def_id) {
single_char_push_string::check(cx, expr, receiver, args);
} else if match_def_path(cx, fn_def_id, &paths::INSERT_STR) {
} else if cx.tcx.is_diagnostic_item(sym::string_insert_str, fn_def_id) {
single_char_insert_string::check(cx, expr, receiver, args);
}
}
Expand Down
2 changes: 0 additions & 2 deletions clippy_utils/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub const HASHSET_ITER_TY: [&str; 5] = ["std", "collections", "hash", "set", "It
pub const HASHSET_DRAIN: [&str; 5] = ["std", "collections", "hash", "set", "Drain"];
pub const IDENT: [&str; 3] = ["rustc_span", "symbol", "Ident"];
pub const IDENT_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Ident", "as_str"];
pub const INSERT_STR: [&str; 4] = ["alloc", "string", "String", "insert_str"];
pub const ITERTOOLS_NEXT_TUPLE: [&str; 3] = ["itertools", "Itertools", "next_tuple"];
pub const KW_MODULE: [&str; 3] = ["rustc_span", "symbol", "kw"];
pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"];
Expand All @@ -42,7 +41,6 @@ pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwL
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockWriteGuard"];
#[cfg_attr(not(unix), allow(clippy::invalid_paths))]
pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"];
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
pub const REGEX_BUILDER_NEW: [&str; 3] = ["regex", "RegexBuilder", "new"];
pub const REGEX_BYTES_BUILDER_NEW: [&str; 4] = ["regex", "bytes", "RegexBuilder", "new"];
pub const REGEX_BYTES_NEW: [&str; 4] = ["regex", "bytes", "Regex", "new"];
Expand Down

0 comments on commit f66915e

Please sign in to comment.