mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
[Clippy] Swap instant_subtraction
to use diagnostic item instead of path
This commit is contained in:
parent
372f68b6a6
commit
1890620b26
@ -1061,6 +1061,7 @@ symbols! {
|
|||||||
inline_const,
|
inline_const,
|
||||||
inline_const_pat,
|
inline_const_pat,
|
||||||
inout,
|
inout,
|
||||||
|
instant_now,
|
||||||
instruction_set,
|
instruction_set,
|
||||||
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
|
integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below
|
||||||
integral,
|
integral,
|
||||||
|
@ -280,6 +280,7 @@ impl Instant {
|
|||||||
/// ```
|
/// ```
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[stable(feature = "time2", since = "1.8.0")]
|
#[stable(feature = "time2", since = "1.8.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "instant_now")]
|
||||||
pub fn now() -> Instant {
|
pub fn now() -> Instant {
|
||||||
Instant(time::Instant::now())
|
Instant(time::Instant::now())
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ impl LateLintPass<'_> for InstantSubtraction {
|
|||||||
fn is_instant_now_call(cx: &LateContext<'_>, expr_block: &'_ Expr<'_>) -> bool {
|
fn is_instant_now_call(cx: &LateContext<'_>, expr_block: &'_ Expr<'_>) -> bool {
|
||||||
if let ExprKind::Call(fn_expr, []) = expr_block.kind
|
if let ExprKind::Call(fn_expr, []) = expr_block.kind
|
||||||
&& let Some(fn_id) = clippy_utils::path_def_id(cx, fn_expr)
|
&& 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
|
true
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,4 +72,3 @@ pub const TOKIO_IO_ASYNCWRITEEXT: [&str; 5] = ["tokio", "io", "util", "async_wri
|
|||||||
pub const TOKIO_IO_OPEN_OPTIONS: [&str; 4] = ["tokio", "fs", "open_options", "OpenOptions"];
|
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
|
#[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 TOKIO_IO_OPEN_OPTIONS_NEW: [&str; 5] = ["tokio", "fs", "open_options", "OpenOptions", "new"];
|
||||||
pub const INSTANT_NOW: [&str; 4] = ["std", "time", "Instant", "now"];
|
|
||||||
|
Loading…
Reference in New Issue
Block a user