From 372f68b6a6e0b6997d065cef4f6cef16a6fb53e3 Mon Sep 17 00:00:00 2001 From: GnomedDev Date: Wed, 18 Sep 2024 22:05:02 +0100 Subject: [PATCH] [Clippy] Swap `waker_clone_wake` to use diagnostic item instead of path --- compiler/rustc_span/src/symbol.rs | 1 + library/core/src/task/wake.rs | 1 + src/tools/clippy/clippy_lints/src/methods/waker_clone_wake.rs | 4 ++-- src/tools/clippy/clippy_utils/src/paths.rs | 1 - 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index e795b7fb25c..8a3ec7a8f71 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -342,6 +342,7 @@ Upvars, Vec, VecDeque, + Waker, Wrapper, Wrapping, Yield, diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 5e559ad8d2c..a5103499c8a 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -414,6 +414,7 @@ pub const fn build(self) -> Context<'a> { /// [`Wake`]: ../../alloc/task/trait.Wake.html #[repr(transparent)] #[stable(feature = "futures_api", since = "1.36.0")] +#[cfg_attr(not(test), rustc_diagnostic_item = "Waker")] pub struct Waker { waker: RawWaker, } diff --git a/src/tools/clippy/clippy_lints/src/methods/waker_clone_wake.rs b/src/tools/clippy/clippy_lints/src/methods/waker_clone_wake.rs index da66632d55f..9b64cc7589c 100644 --- a/src/tools/clippy/clippy_lints/src/methods/waker_clone_wake.rs +++ b/src/tools/clippy/clippy_lints/src/methods/waker_clone_wake.rs @@ -1,6 +1,6 @@ use clippy_utils::diagnostics::span_lint_and_sugg; use clippy_utils::source::snippet_with_applicability; -use clippy_utils::{is_trait_method, match_def_path, paths}; +use clippy_utils::is_trait_method; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind}; use rustc_lint::LateContext; @@ -12,7 +12,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, recv: &' let ty = cx.typeck_results().expr_ty(recv); if let Some(did) = ty.ty_adt_def() - && match_def_path(cx, did.did(), &paths::WAKER) + && cx.tcx.is_diagnostic_item(sym::Waker, did.did()) && let ExprKind::MethodCall(_, waker_ref, &[], _) = recv.kind && is_trait_method(cx, recv, sym::Clone) { diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs index cb0330d0046..89c1bd8a8a0 100644 --- a/src/tools/clippy/clippy_utils/src/paths.rs +++ b/src/tools/clippy/clippy_utils/src/paths.rs @@ -73,4 +73,3 @@ #[expect(clippy::invalid_paths)] // internal lints do not know about all external crates pub const TOKIO_IO_OPEN_OPTIONS_NEW: [&str; 5] = ["tokio", "fs", "open_options", "OpenOptions", "new"]; pub const INSTANT_NOW: [&str; 4] = ["std", "time", "Instant", "now"]; -pub const WAKER: [&str; 4] = ["core", "task", "wake", "Waker"];