]> git.lizzy.rs Git - rust.git/blob - tests/ui/reference.rs
Auto merge of #3635 - matthiaskrgr:revert_random_state_3603, r=xfix
[rust.git] / tests / ui / reference.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 fn get_number() -> usize {
11     10
12 }
13
14 fn get_reference(n: &usize) -> &usize {
15     n
16 }
17
18 #[allow(clippy::many_single_char_names, clippy::double_parens)]
19 #[allow(unused_variables)]
20 #[warn(clippy::deref_addrof)]
21 fn main() {
22     let a = 10;
23     let aref = &a;
24
25     let b = *&a;
26
27     let b = *&get_number();
28
29     let b = *get_reference(&a);
30
31     let bytes: Vec<usize> = vec![1, 2, 3, 4];
32     let b = *&bytes[1..2][0];
33
34     //This produces a suggestion of 'let b = (a);' which
35     //will trigger the 'unused_parens' lint
36     let b = *&(a);
37
38     let b = *(&a);
39
40     #[rustfmt::skip]
41     let b = *((&a));
42
43     let b = *&&a;
44
45     let b = **&aref;
46
47     //This produces a suggestion of 'let b = *&a;' which
48     //will trigger the 'clippy::deref_addrof' lint again
49     let b = **&&a;
50
51     {
52         let mut x = 10;
53         let y = *&mut x;
54     }
55
56     {
57         //This produces a suggestion of 'let y = *&mut x' which
58         //will trigger the 'clippy::deref_addrof' lint again
59         let mut x = 10;
60         let y = **&mut &mut x;
61     }
62 }