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

Commit 1890620

Browse files
committed
[Clippy] Swap instant_subtraction to use diagnostic item instead of path
1 parent 372f68b commit 1890620

File tree

4 files changed

+3
-2
lines changed

4 files changed

+3
-2
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ symbols! {
10611061
inline_const,
10621062
inline_const_pat,
10631063
inout,
1064+
instant_now,
10641065
instruction_set,
10651066
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
10661067
integral,

library/std/src/time.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ impl Instant {
280280
/// ```
281281
#[must_use]
282282
#[stable(feature = "time2", since = "1.8.0")]
283+
#[cfg_attr(not(test), rustc_diagnostic_item = "instant_now")]
283284
pub fn now() -> Instant {
284285
Instant(time::Instant::now())
285286
}

src/tools/clippy/clippy_lints/src/instant_subtraction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl LateLintPass<'_> for InstantSubtraction {
112112
fn is_instant_now_call(cx: &LateContext<'_>, expr_block: &'_ Expr<'_>) -> bool {
113113
if let ExprKind::Call(fn_expr, []) = expr_block.kind
114114
&& let Some(fn_id) = clippy_utils::path_def_id(cx, fn_expr)
115-
&& clippy_utils::match_def_path(cx, fn_id, &clippy_utils::paths::INSTANT_NOW)
115+
&& cx.tcx.is_diagnostic_item(sym::instant_now, fn_id)
116116
{
117117
true
118118
} else {

src/tools/clippy/clippy_utils/src/paths.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,3 @@ pub const TOKIO_IO_ASYNCWRITEEXT: [&str; 5] = ["tokio", "io", "util", "async_wri
7272
pub const TOKIO_IO_OPEN_OPTIONS: [&str; 4] = ["tokio", "fs", "open_options", "OpenOptions"];
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"];
75-
pub const INSTANT_NOW: [&str; 4] = ["std", "time", "Instant", "now"];

0 commit comments

Comments
 (0)