Better documentation for disallowed_method lint
https://rust-lang.github.io/rust-clippy/master/#disallowed_method Doc on All Clippy Lints shows the example of how to use it with methods from the standard library, but no example on how to use it with user-defined types neither if this is possible to use with methods of user-defined types/imported items.
When I tried to use this with nightly-2021-07-06 in rust-toolchain I managed to get it to work with std::vec::Vec::append, but no luck with user-defined methods.
Saw this commit https://github.com/rust-lang/rust-clippy/commit/70ce0c2c55b18f7c9a4bc8d767c626f8d5948fae if I understand correctly, this is worked on currently?
I believe local methods still can't be used with this lint.
For example, in a crate called my_crate with the following contents:
fn f() { }
fn g() {
f();
}
And with the following clippy.toml
disallowed-methods = [
"f"
]
The call in g isn't warned about.
Using crate::f, my_crate::f and ::my_crate::f also doesn't work.
As the clippy.toml can be defined for workspace, I suppose my_crate::f should work as a design (but it doesn't work yet).
Besides, I may want to disallow trait method for a specific implementation. Given -
trait A { fn f (); }
Struct B; impl A for B { ... }
Struct C; impl A for C { ... }
I'd like to forbit B.f() but not C.f(). It seems now we all resolved to A::f().
my_crate::f
I checked this way works now (may be related to https://github.com/rust-lang/rust-clippy/pull/8852) and even with nested mod. My issue is the comment above https://github.com/rust-lang/rust-clippy/issues/7479#issuecomment-1664869201
Note: Today (Rust 1.81, though it's probably worked for a while), this works in clippy.toml:
[[disallowed-methods]]
path = "std::fs::rename"
reason = "Use fs_err::rename"
However, the documentation only includes examples for methods on types, not methods on modules, so we should clean that up.