RS.CLIPPY.DISALLOWED_METHODS
Use of a disallowed method call
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: disallowed_methods. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Denies the configured methods and functions in clippy.toml
Note: Even though this lint is warn-by-default, it will only trigger if methods are defined in the clippy.toml file.
Why is this bad?
Some methods are undesirable in certain contexts, and it's beneficial to lint for them as needed.
Example
An example clippy.toml configuration:
disallowed-methods = [
# Can use a string as the path of the disallowed method.
"std::boxed::Box::new",
# Can also use an inline table with a `path` key.
{ path = "std::time::Instant::now" },
# When using an inline table, can add a `reason` for why the method
# is disallowed.
{ path = "std::vec::Vec::leak", reason = "no leaking memory" },
# Can also add a `replacement` that will be offered as a suggestion.
{ path = "std::sync::Mutex::new", reason = "prefer faster & simpler non-poisonable mutex", replacement = "parking_lot::Mutex::new" },
]
let xs = vec![1, 2, 3, 4];
xs.leak(); // Vec::leak is disallowed in the config.
// The diagnostic contains the message "no leaking memory".
let _now = Instant::now(); // Instant::now is disallowed in the config.
let _box = Box::new(3); // Box::new is disallowed in the config.
Use instead:
let mut xs = Vec::new(); // Vec::new is _not_ disallowed in the config.
xs.push(123); // Vec::push is _not_ disallowed in the config.
Past names
- disallowed_method
Configuration
-
disallowed-methods: The list of disallowed methods, written as fully qualified paths.(default:
[])