]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/disallowed_methods.txt
Auto merge of #104673 - matthiaskrgr:rollup-85f65ov, r=matthiaskrgr
[rust.git] / src / tools / clippy / src / docs / disallowed_methods.txt
1 ### What it does
2 Denies the configured methods and functions in clippy.toml
3
4 Note: Even though this lint is warn-by-default, it will only trigger if
5 methods are defined in the clippy.toml file.
6
7 ### Why is this bad?
8 Some methods are undesirable in certain contexts, and it's beneficial to
9 lint for them as needed.
10
11 ### Example
12 An example clippy.toml configuration:
13 ```
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
20     # is disallowed.
21     { path = "std::vec::Vec::leak", reason = "no leaking memory" },
22 ]
23 ```
24
25 ```
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".
30
31 let _now = Instant::now(); // Instant::now is disallowed in the config.
32
33 let _box = Box::new(3); // Box::new is disallowed in the config.
34 ```
35
36 Use instead:
37 ```
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.
41 ```