]> git.lizzy.rs Git - rust.git/blob - src/docs/redundant_slicing.txt
6798911ed76c08b5da77afdbf12c8c7f809fb5fb
[rust.git] / src / docs / redundant_slicing.txt
1 ### What it does
2 Checks for redundant slicing expressions which use the full range, and
3 do not change the type.
4
5 ### Why is this bad?
6 It unnecessarily adds complexity to the expression.
7
8 ### Known problems
9 If the type being sliced has an implementation of `Index<RangeFull>`
10 that actually changes anything then it can't be removed. However, this would be surprising
11 to people reading the code and should have a note with it.
12
13 ### Example
14 ```
15 fn get_slice(x: &[u32]) -> &[u32] {
16     &x[..]
17 }
18 ```
19 Use instead:
20 ```
21 fn get_slice(x: &[u32]) -> &[u32] {
22     x
23 }
24 ```