2 Denies the configured methods and functions in clippy.toml
4 Note: Even though this lint is warn-by-default, it will only trigger if
5 methods are defined in the clippy.toml file.
8 Some methods are undesirable in certain contexts, and it's beneficial to
9 lint for them as needed.
12 An example clippy.toml configuration:
14 disallowed-methods = [
15 # Can use a string as the path of the disallowed method.
16 "std::boxed::Box::new",
17 # Can also use an inline table with a `path` key.
18 { path = "std::time::Instant::now" },
19 # When using an inline table, can add a `reason` for why the method
21 { path = "std::vec::Vec::leak", reason = "no leaking memory" },
26 // Example code where clippy issues a warning
27 let xs = vec![1, 2, 3, 4];
28 xs.leak(); // Vec::leak is disallowed in the config.
29 // The diagnostic contains the message "no leaking memory".
31 let _now = Instant::now(); // Instant::now is disallowed in the config.
33 let _box = Box::new(3); // Box::new is disallowed in the config.
38 // Example code which does not raise clippy warning
39 let mut xs = Vec::new(); // Vec::new is _not_ disallowed in the config.
40 xs.push(123); // Vec::push is _not_ disallowed in the config.