]> git.lizzy.rs Git - rust.git/blob - src/docs/ptr_arg.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / ptr_arg.txt
1 ### What it does
2 This lint checks for function arguments of type `&String`, `&Vec`,
3 `&PathBuf`, and `Cow<_>`. It will also suggest you replace `.clone()` calls
4 with the appropriate `.to_owned()`/`to_string()` calls.
5
6 ### Why is this bad?
7 Requiring the argument to be of the specific size
8 makes the function less useful for no benefit; slices in the form of `&[T]`
9 or `&str` usually suffice and can be obtained from other types, too.
10
11 ### Known problems
12 There may be `fn(&Vec)`-typed references pointing to your function.
13 If you have them, you will get a compiler error after applying this lint's
14 suggestions. You then have the choice to undo your changes or change the
15 type of the reference.
16
17 Note that if the function is part of your public interface, there may be
18 other crates referencing it, of which you may not be aware. Carefully
19 deprecate the function before applying the lint suggestions in this case.
20
21 ### Example
22 ```
23 fn foo(&Vec<u32>) { .. }
24 ```
25
26 Use instead:
27 ```
28 fn foo(&[u32]) { .. }
29 ```