0

I have some functions defined in my crate that I want to disallow the use of inside of the same, using clippy::disallowed_methods.

For example:

fn f() { ... }

fn g() {
    f(); // Warning
}

I've tried the following clippy.toml

disallowed-methods = [
  "crate::f"
]

But no warning shows up when I run cargo clippy.

I've also tried f, my_crate::f and ::my_crate::f, where my_crate is the name of the crate both functions are defined in, but none of them work.

I've tried it with other methods in external crates, such as std::vec::Vec::new and a warning successfully shows up.

Is there any way to make disallowed_methods work without moving the methods to another crate?

Filipe Rodrigues
  • 1,843
  • 2
  • 12
  • 21
  • Is your crate a binary, or library target? – eggyal Feb 02 '22 at 19:42
  • A binary, but ideally it should work in either, I might move logic from this binary to it's own crate eventually. – Filipe Rodrigues Feb 02 '22 at 19:45
  • Sure, I'm just speculating that a binary crate may not be addressable/named in quite the same way as a library crate, if at all. – eggyal Feb 02 '22 at 19:46
  • 1
    I just tried it out and it seems a library also doesn't work. I created a library named `t`, but using `f`, `t::f`, `::t::f` or `crate::f` still doesn't work, so I assume it's a shared problem. – Filipe Rodrigues Feb 02 '22 at 19:49
  • Github was down a few minutes ago, so I couldn't check, but apparently it's a known [issue](https://github.com/rust-lang/rust-clippy/issues/7479). Although it's still not working, so I guess the answer is that it's not supported yet? – Filipe Rodrigues Feb 02 '22 at 19:57

0 Answers0