]> git.lizzy.rs Git - rust.git/blob - src/docs/toplevel_ref_arg.txt
Add iter_kv_map lint
[rust.git] / src / docs / toplevel_ref_arg.txt
1 ### What it does
2 Checks for function arguments and let bindings denoted as
3 `ref`.
4
5 ### Why is this bad?
6 The `ref` declaration makes the function take an owned
7 value, but turns the argument into a reference (which means that the value
8 is destroyed when exiting the function). This adds not much value: either
9 take a reference type, or take an owned value and create references in the
10 body.
11
12 For let bindings, `let x = &foo;` is preferred over `let ref x = foo`. The
13 type of `x` is more obvious with the former.
14
15 ### Known problems
16 If the argument is dereferenced within the function,
17 removing the `ref` will lead to errors. This can be fixed by removing the
18 dereferences, e.g., changing `*x` to `x` within the function.
19
20 ### Example
21 ```
22 fn foo(ref _x: u8) {}
23 ```
24
25 Use instead:
26 ```
27 fn foo(_x: &u8) {}
28 ```