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

Commit b015290

Browse files
committed
[Clippy] Swap manual_while_let_some to use diagnostic items instead of paths
1 parent 984bd6f commit b015290

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

clippy_lints/src/loops/manual_while_let_some.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::snippet;
3-
use clippy_utils::{match_def_path, paths, SpanlessEq};
3+
use clippy_utils::SpanlessEq;
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, ExprKind, Pat, Stmt, StmtKind, UnOp};
66
use rustc_lint::LateContext;
7-
use rustc_span::Span;
7+
use rustc_span::{sym, Symbol, Span};
88
use std::borrow::Cow;
99

1010
use super::MANUAL_WHILE_LET_SOME;
@@ -47,20 +47,20 @@ fn report_lint(cx: &LateContext<'_>, pop_span: Span, pop_stmt_kind: PopStmt<'_>,
4747
);
4848
}
4949

50-
fn match_method_call(cx: &LateContext<'_>, expr: &Expr<'_>, method: &[&str]) -> bool {
50+
fn match_method_call(cx: &LateContext<'_>, expr: &Expr<'_>, method: Symbol) -> bool {
5151
if let ExprKind::MethodCall(..) = expr.kind
5252
&& let Some(id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
5353
{
54-
match_def_path(cx, id, method)
54+
cx.tcx.is_diagnostic_item(method, id)
5555
} else {
5656
false
5757
}
5858
}
5959

6060
fn is_vec_pop_unwrap(cx: &LateContext<'_>, expr: &Expr<'_>, is_empty_recv: &Expr<'_>) -> bool {
61-
if (match_method_call(cx, expr, &paths::OPTION_UNWRAP) || match_method_call(cx, expr, &paths::OPTION_EXPECT))
61+
if (match_method_call(cx, expr, sym::option_unwrap) || match_method_call(cx, expr, sym::option_expect))
6262
&& let ExprKind::MethodCall(_, unwrap_recv, ..) = expr.kind
63-
&& match_method_call(cx, unwrap_recv, &paths::VEC_POP)
63+
&& match_method_call(cx, unwrap_recv, sym::vec_pop)
6464
&& let ExprKind::MethodCall(_, pop_recv, ..) = unwrap_recv.kind
6565
{
6666
// make sure they're the same `Vec`
@@ -96,7 +96,7 @@ fn check_call_arguments(cx: &LateContext<'_>, stmt: &Stmt<'_>, is_empty_recv: &E
9696
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, full_cond: &'tcx Expr<'_>, body: &'tcx Expr<'_>, loop_span: Span) {
9797
if let ExprKind::Unary(UnOp::Not, cond) = full_cond.kind
9898
&& let ExprKind::MethodCall(_, is_empty_recv, _, _) = cond.kind
99-
&& match_method_call(cx, cond, &paths::VEC_IS_EMPTY)
99+
&& match_method_call(cx, cond, sym::vec_is_empty)
100100
&& let ExprKind::Block(body, _) = body.kind
101101
&& let Some(stmt) = body.stmts.first()
102102
{

clippy_utils/src/paths.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,5 @@ pub const TOKIO_IO_OPEN_OPTIONS: [&str; 4] = ["tokio", "fs", "open_options", "Op
7373
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
7474
pub const TOKIO_IO_OPEN_OPTIONS_NEW: [&str; 5] = ["tokio", "fs", "open_options", "OpenOptions", "new"];
7575
pub const INSTANT_NOW: [&str; 4] = ["std", "time", "Instant", "now"];
76-
pub const VEC_IS_EMPTY: [&str; 4] = ["alloc", "vec", "Vec", "is_empty"];
77-
pub const VEC_POP: [&str; 4] = ["alloc", "vec", "Vec", "pop"];
7876
pub const WAKER: [&str; 4] = ["core", "task", "wake", "Waker"];
79-
pub const OPTION_UNWRAP: [&str; 4] = ["core", "option", "Option", "unwrap"];
80-
pub const OPTION_EXPECT: [&str; 4] = ["core", "option", "Option", "expect"];
8177
pub const BOOL_THEN: [&str; 4] = ["core", "bool", "<impl bool>", "then"];

0 commit comments

Comments
 (0)