]> git.lizzy.rs Git - rust.git/blob - src/docs/needless_pass_by_value.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / needless_pass_by_value.txt
1 ### What it does
2 Checks for functions taking arguments by value, but not
3 consuming them in its
4 body.
5
6 ### Why is this bad?
7 Taking arguments by reference is more flexible and can
8 sometimes avoid
9 unnecessary allocations.
10
11 ### Known problems
12 * This lint suggests taking an argument by reference,
13 however sometimes it is better to let users decide the argument type
14 (by using `Borrow` trait, for example), depending on how the function is used.
15
16 ### Example
17 ```
18 fn foo(v: Vec<i32>) {
19     assert_eq!(v.len(), 42);
20 }
21 ```
22 should be
23 ```
24 fn foo(v: &[i32]) {
25     assert_eq!(v.len(), 42);
26 }
27 ```