]> git.lizzy.rs Git - rust.git/blob - tests/ui/reference.rs
Change explicit_counter_loop's message to add parentheses if necessary
[rust.git] / tests / ui / reference.rs
1 fn get_number() -> usize {
2     10
3 }
4
5 fn get_reference(n: &usize) -> &usize {
6     n
7 }
8
9 #[allow(clippy::many_single_char_names, clippy::double_parens)]
10 #[allow(unused_variables)]
11 #[warn(clippy::deref_addrof)]
12 fn main() {
13     let a = 10;
14     let aref = &a;
15
16     let b = *&a;
17
18     let b = *&get_number();
19
20     let b = *get_reference(&a);
21
22     let bytes: Vec<usize> = vec![1, 2, 3, 4];
23     let b = *&bytes[1..2][0];
24
25     //This produces a suggestion of 'let b = (a);' which
26     //will trigger the 'unused_parens' lint
27     let b = *&(a);
28
29     let b = *(&a);
30
31     #[rustfmt::skip]
32     let b = *((&a));
33
34     let b = *&&a;
35
36     let b = **&aref;
37
38     //This produces a suggestion of 'let b = *&a;' which
39     //will trigger the 'clippy::deref_addrof' lint again
40     let b = **&&a;
41
42     {
43         let mut x = 10;
44         let y = *&mut x;
45     }
46
47     {
48         //This produces a suggestion of 'let y = *&mut x' which
49         //will trigger the 'clippy::deref_addrof' lint again
50         let mut x = 10;
51         let y = **&mut &mut x;
52     }
53 }