]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/needless_lifetimes.txt
Rollup merge of #101614 - compiler-errors:rpitit-eq, r=jackh726
[rust.git] / src / tools / clippy / src / docs / needless_lifetimes.txt
1 ### What it does
2 Checks for lifetime annotations which can be removed by
3 relying on lifetime elision.
4
5 ### Why is this bad?
6 The additional lifetimes make the code look more
7 complicated, while there is nothing out of the ordinary going on. Removing
8 them leads to more readable code.
9
10 ### Known problems
11 - We bail out if the function has a `where` clause where lifetimes
12 are mentioned due to potential false positives.
13 - Lifetime bounds such as `impl Foo + 'a` and `T: 'a` must be elided with the
14 placeholder notation `'_` because the fully elided notation leaves the type bound to `'static`.
15
16 ### Example
17 ```
18 // Unnecessary lifetime annotations
19 fn in_and_out<'a>(x: &'a u8, y: u8) -> &'a u8 {
20     x
21 }
22 ```
23
24 Use instead:
25 ```
26 fn elided(x: &u8, y: u8) -> &u8 {
27     x
28 }
29 ```