Skip to content

disallowed_methods false positive instant::Instant vs std::time::Instant #10406

Closed
@emilk

Description

@emilk

Summary

I want to forbid std::time::Instant::now, because it doesn't work on web/wasm:

❯ cat clippy.toml 
disallowed-methods = ["std::time::Instant::now"]

Instead I want to use https://crates.io/crates/instant

However, when I use instant::Instant::now I get a false-positive error.

Lint Name

disallowed_methods

Reproducer

I tried this code:

fn main() {
    instant::Instant::now();
}

I saw this happen:

warning: use of a disallowed method `std::time::Instant::now`
 --> src/main.rs:2:15
  |
2 |     let now = instant::Instant::now();
  |               ^^^^^^^^^^^^^^^^^^^^^^^
  |

I expected to see this happen: No warning

Version

rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: aarch64-apple-darwin
release: 1.67.1
LLVM version: 15.0.6

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions