Skip to content

Better documentation for disallowed_method lint #7479

Open
@juliancoffee

Description

@juliancoffee

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.

Activity

juliancoffee

juliancoffee commented on Jul 24, 2021

@juliancoffee
Author

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

Zenithsiz

Zenithsiz commented on Feb 2, 2022

@Zenithsiz

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

tisonkun commented on Aug 4, 2023

@tisonkun

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

tisonkun commented on Aug 4, 2023

@tisonkun

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

tisonkun commented on Aug 4, 2023

@tisonkun

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

9999years commented on Oct 16, 2024

@9999years
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-documentationArea: Adding or improving documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @9999years@giraffate@tisonkun@Zenithsiz@juliancoffee

        Issue actions

          Better documentation for disallowed_method lint · Issue #7479 · rust-lang/rust-clippy