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

Commit 1b76ae6

Browse files
committed
[Clippy] Swap manual_strip to use diagnostic items instead of paths
1 parent acb6748 commit 1b76ae6

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

clippy_lints/src/manual_strip.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant};
44
use clippy_utils::diagnostics::span_lint_and_then;
55
use clippy_utils::source::snippet;
66
use clippy_utils::usage::mutated_variables;
7-
use clippy_utils::{eq_expr_value, higher, match_def_path, paths};
7+
use clippy_utils::{eq_expr_value, higher};
88
use rustc_ast::ast::LitKind;
99
use rustc_errors::Applicability;
1010
use rustc_hir::def::Res;
@@ -14,7 +14,7 @@ use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::ty;
1515
use rustc_session::impl_lint_pass;
1616
use rustc_span::source_map::Spanned;
17-
use rustc_span::Span;
17+
use rustc_span::{sym, Span};
1818
use std::iter;
1919

2020
declare_clippy_lint! {
@@ -76,9 +76,9 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
7676
&& self.msrv.meets(msrvs::STR_STRIP_PREFIX)
7777
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id)
7878
{
79-
let strip_kind = if match_def_path(cx, method_def_id, &paths::STR_STARTS_WITH) {
79+
let strip_kind = if cx.tcx.is_diagnostic_item(sym::str_starts_with, method_def_id) {
8080
StripKind::Prefix
81-
} else if match_def_path(cx, method_def_id, &paths::STR_ENDS_WITH) {
81+
} else if cx.tcx.is_diagnostic_item(sym::str_ends_with, method_def_id) {
8282
StripKind::Suffix
8383
} else {
8484
return;
@@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
137137
fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
138138
if let ExprKind::MethodCall(_, arg, [], _) = expr.kind
139139
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
140-
&& match_def_path(cx, method_def_id, &paths::STR_LEN)
140+
&& cx.tcx.is_diagnostic_item(sym::str_len, method_def_id)
141141
{
142142
Some(arg)
143143
} else {

clippy_utils/src/paths.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
5252
pub const STD_IO_SEEK_FROM_CURRENT: [&str; 4] = ["std", "io", "SeekFrom", "Current"];
5353
pub const STD_IO_SEEKFROM_START: [&str; 4] = ["std", "io", "SeekFrom", "Start"];
5454
pub const STRING_NEW: [&str; 4] = ["alloc", "string", "String", "new"];
55-
pub const STR_ENDS_WITH: [&str; 4] = ["core", "str", "<impl str>", "ends_with"];
56-
pub const STR_LEN: [&str; 4] = ["core", "str", "<impl str>", "len"];
57-
pub const STR_STARTS_WITH: [&str; 4] = ["core", "str", "<impl str>", "starts_with"];
5855
pub const SYMBOL: [&str; 3] = ["rustc_span", "symbol", "Symbol"];
5956
pub const SYMBOL_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Symbol", "as_str"];
6057
pub const SYMBOL_INTERN: [&str; 4] = ["rustc_span", "symbol", "Symbol", "intern"];

0 commit comments

Comments
 (0)