]> git.lizzy.rs Git - rust.git/blob - tests/ui/reference.rs
Merge pull request #3265 from mikerite/fix-export
[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
11 #![feature(tool_lints)]
12
13
14 fn get_number() -> usize {
15     10
16 }
17
18 fn get_reference(n : &usize) -> &usize {
19     n
20 }
21
22 #[allow(clippy::many_single_char_names, clippy::double_parens)]
23 #[allow(unused_variables)]
24 #[warn(clippy::deref_addrof)]
25 fn main() {
26     let a = 10;
27     let aref = &a;
28
29     let b = *&a;
30
31     let b = *&get_number();
32
33     let b = *get_reference(&a);
34
35     let bytes : Vec<usize> = vec![1, 2, 3, 4];
36     let b = *&bytes[1..2][0];
37
38     //This produces a suggestion of 'let b = (a);' which
39     //will trigger the 'unused_parens' lint
40     let b = *&(a);
41
42     let b = *(&a);
43
44     let b = *((&a));
45
46     let b = *&&a;
47
48     let b = **&aref;
49
50     //This produces a suggestion of 'let b = *&a;' which
51     //will trigger the 'clippy::deref_addrof' lint again
52     let b = **&&a;
53
54     {
55         let mut x = 10;
56         let y = *&mut x;
57     }
58
59     {
60         //This produces a suggestion of 'let y = *&mut x' which
61         //will trigger the 'clippy::deref_addrof' lint again
62         let mut x = 10;
63         let y = **&mut &mut x;
64     }
65 }