]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/borrow_deref_ref.rs
Merge commit '2b2190cb5667cdd276a24ef8b9f3692209c54a89' into clippyup
[rust.git] / src / tools / clippy / tests / ui / borrow_deref_ref.rs
1 // run-rustfix
2
3 #![allow(dead_code, unused_variables)]
4
5 fn main() {}
6
7 mod should_lint {
8     fn one_help() {
9         let a = &12;
10         let b = &*a;
11
12         let b = &mut &*bar(&12);
13     }
14
15     fn bar(x: &u32) -> &u32 {
16         x
17     }
18 }
19
20 // this mod explains why we should not lint `&mut &* (&T)`
21 mod should_not_lint1 {
22     fn foo(x: &mut &u32) {
23         *x = &1;
24     }
25
26     fn main() {
27         let mut x = &0;
28         foo(&mut &*x); // should not lint
29         assert_eq!(*x, 0);
30
31         foo(&mut x);
32         assert_eq!(*x, 1);
33     }
34 }
35
36 // similar to should_not_lint1
37 mod should_not_lint2 {
38     struct S<'a> {
39         a: &'a u32,
40         b: u32,
41     }
42
43     fn main() {
44         let s = S { a: &1, b: 1 };
45         let x = &mut &*s.a;
46         *x = &2;
47     }
48 }
49
50 // this mod explains why we should not lint `& &* (&T)`
51 mod false_negative {
52     fn foo() {
53         let x = &12;
54         let addr_x = &x as *const _ as usize;
55         let addr_y = &&*x as *const _ as usize; // assert ok
56         // let addr_y = &x as *const _ as usize; // assert fail
57         assert_ne!(addr_x, addr_y);
58     }
59 }