From 1890620b2611aaec28edc5537183a2c7734ae3ce Mon Sep 17 00:00:00 2001 From: GnomedDev Date: Wed, 18 Sep 2024 22:08:04 +0100 Subject: [PATCH] [Clippy] Swap `instant_subtraction` to use diagnostic item instead of path --- compiler/rustc_span/src/symbol.rs | 1 + library/std/src/time.rs | 1 + src/tools/clippy/clippy_lints/src/instant_subtraction.rs | 2 +- src/tools/clippy/clippy_utils/src/paths.rs | 1 - 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 8a3ec7a8f71..bac5bb96569 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1061,6 +1061,7 @@ inline_const, inline_const_pat, inout, + instant_now, instruction_set, integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below integral, diff --git a/library/std/src/time.rs b/library/std/src/time.rs index ae46670c25e..f28a0568a3c 100644 --- a/library/std/src/time.rs +++ b/library/std/src/time.rs @@ -280,6 +280,7 @@ impl Instant { /// ``` #[must_use] #[stable(feature = "time2", since = "1.8.0")] + #[cfg_attr(not(test), rustc_diagnostic_item = "instant_now")] pub fn now() -> Instant { Instant(time::Instant::now()) } diff --git a/src/tools/clippy/clippy_lints/src/instant_subtraction.rs b/src/tools/clippy/clippy_lints/src/instant_subtraction.rs index f41fdf3203c..6d6820311b6 100644 --- a/src/tools/clippy/clippy_lints/src/instant_subtraction.rs +++ b/src/tools/clippy/clippy_lints/src/instant_subtraction.rs @@ -112,7 +112,7 @@ fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) { fn is_instant_now_call(cx: &LateContext<'_>, expr_block: &'_ Expr<'_>) -> bool { if let ExprKind::Call(fn_expr, []) = expr_block.kind && let Some(fn_id) = clippy_utils::path_def_id(cx, fn_expr) - && clippy_utils::match_def_path(cx, fn_id, &clippy_utils::paths::INSTANT_NOW) + && cx.tcx.is_diagnostic_item(sym::instant_now, fn_id) { true } else { diff --git a/src/tools/clippy/clippy_utils/src/paths.rs b/src/tools/clippy/clippy_utils/src/paths.rs index 89c1bd8a8a0..26f680e2666 100644 --- a/src/tools/clippy/clippy_utils/src/paths.rs +++ b/src/tools/clippy/clippy_utils/src/paths.rs @@ -72,4 +72,3 @@ pub const TOKIO_IO_OPEN_OPTIONS: [&str; 4] = ["tokio", "fs", "open_options", "OpenOptions"]; #[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"];