Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
emilk opened this issue Feb 26, 2023 · 3 comments
Closed

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

emilk opened this issue Feb 26, 2023 · 3 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@emilk
Copy link

emilk commented Feb 26, 2023

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

@emilk emilk added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 26, 2023
@Jarcho
Copy link
Contributor

Jarcho commented Feb 26, 2023

This may not be fixable. instant::Instant is an alias to std::time::Instant on everything but wasm.

@emilk
Copy link
Author

emilk commented Feb 26, 2023

Oh right, of course… that’s interesting. I guess I would need to only disallow std::time::Instant on wasm32, which isn’t possible afaict. Or make a PR to instant to turn instant::Instant into a thin newtype instead. Thanks for the explanation!

@waynexia
Copy link

Another lint disallowed_types seems to work. Here is our case for forbidding std::time::Instant apache/datafusion@edb67fa

clippy.toml:

disallowed-types = [
    { path = "std::time::Instant", reason = "" },
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants