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

Better documentation for disallowed_method lint #7479

Open
juliancoffee opened this issue Jul 22, 2021 · 6 comments
Open

Better documentation for disallowed_method lint #7479

juliancoffee opened this issue Jul 22, 2021 · 6 comments
Labels
A-documentation Area: Adding or improving documentation

Comments

@juliancoffee
Copy link

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.

@juliancoffee
Copy link
Author

Saw this commit
70ce0c2
if I understand correctly, this is worked on currently?

@giraffate giraffate added the A-documentation Area: Adding or improving documentation label Aug 5, 2021
@Zenithsiz
Copy link

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.

@tisonkun
Copy link

tisonkun commented Aug 4, 2023

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).

@tisonkun
Copy link

tisonkun commented Aug 4, 2023

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().

@tisonkun
Copy link

tisonkun commented Aug 4, 2023

my_crate::f

I checked this way works now (may be related to #8852) and even with nested mod. My issue is the comment above #7479 (comment)

@9999years
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documentation Area: Adding or improving documentation
Projects
None yet
Development

No branches or pull requests

5 participants