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 not working #8577

Closed
xxchan opened this issue Mar 24, 2022 · 8 comments
Closed

disallowed-methods not working #8577

xxchan opened this issue Mar 24, 2022 · 8 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't

Comments

@xxchan
Copy link
Contributor

xxchan commented Mar 24, 2022

Summary

# in clippy.toml
disallowed-methods = [
     "std::boxed::Box::new"
]
// in main.rs

fn main() {
    let _box = Box::new(3); 
}

no warning

❯ cargo clean; cargo clippy 
    Checking nono v0.1.0 (D:\tmp\nono)
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s

Lint Name

disallowed-methods

Reproducer

No response

Version

rustc 1.58.1 (db9d1b20b 2022-01-20)
binary: rustc
commit-hash: db9d1b20bba1968c1ec1fc49616d4742c1725b4b
commit-date: 2022-01-20
host: x86_64-pc-windows-msvc
release: 1.58.1
LLVM version: 13.0.0

also for 

rustc 1.61.0-nightly (1eb72580d 2022-03-08)
binary: rustc
commit-hash: 1eb72580d076935a3e590deb6e5813a5aef3eca4
commit-date: 2022-03-08
host: x86_64-unknown-linux-gnu
release: 1.61.0-nightly
LLVM version: 14.0.0
@xxchan xxchan added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Mar 24, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Mar 24, 2022

The proper path for Box is alloc::boxed::Box. std just re-exports it. It would be nice if it worked, but I don't think we have easy access to re-exported names from clippy.

Edit: re-exported paths work fine.

@xxchan
Copy link
Contributor Author

xxchan commented Mar 24, 2022

This is from the example: https://rust-lang.github.io/rust-clippy/master/#disallowed_methods

Btw I also tried std::time::Instant::now, but it also didn't work. I felt it strange, and was not sure whether it's my problem...

@xxchan
Copy link
Contributor Author

xxchan commented Mar 24, 2022

I tried v1.49.0, which is the first version supporting disallowed_methods. But it also didn't work.🤨

@Jarcho
Copy link
Contributor

Jarcho commented Mar 24, 2022

Just tested on 1.59.0. It works with both std::boxed::Box::new and alloc::boxed::Box::new. I had to explicitly enable the lint though.

@xxchan
Copy link
Contributor Author

xxchan commented Mar 24, 2022

Oh indeed. I misunderstood the clippy config file... Thank you for your hint.

Now it works fine for Box::new.

But the method I actually wanted to disallow is fixedbitset::FixedBitSet::from_iter. It seems that the trait method cannot be disallowed?

@Jarcho
Copy link
Contributor

Jarcho commented Mar 24, 2022

The lint is /supposed/ to be enabled by default. I don't know what's happening there.

For trait methods it might only work if you name the method on the trait itself, rather than on the type that implements it. Less than useful in this case, unfortunately.

@xxchan
Copy link
Contributor Author

xxchan commented Mar 24, 2022

I found actually it works on v1.61.0-nightly. (Before I just tested the from_iter but not Box on 1.61`) It may because #8261 is quite recent.

Anyway thanks for your help @Jarcho!

@xxchan xxchan closed this as completed Mar 24, 2022
@Jarcho
Copy link
Contributor

Jarcho commented Mar 25, 2022

Just opened #8581 about disallowing methods on trait impls.

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-negative Issue: The lint should have been triggered on code, but wasn't
Projects
None yet
Development

No branches or pull requests

2 participants