]> git.lizzy.rs Git - rust.git/blob - src/docs/borrow_deref_ref.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / borrow_deref_ref.txt
1 ### What it does
2 Checks for `&*(&T)`.
3
4 ### Why is this bad?
5 Dereferencing and then borrowing a reference value has no effect in most cases.
6
7 ### Known problems
8 False negative on such code:
9 ```
10 let x = &12;
11 let addr_x = &x as *const _ as usize;
12 let addr_y = &&*x as *const _ as usize; // assert ok now, and lint triggered.
13                                         // But if we fix it, assert will fail.
14 assert_ne!(addr_x, addr_y);
15 ```
16
17 ### Example
18 ```
19 let s = &String::new();
20
21 let a: &String = &* s;
22 ```
23
24 Use instead:
25 ```
26 let a: &String = s;
27 ```