]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/deref_addrof.rs
Update upstream source from tag 'upstream/1.52.1+dfsg1'
[rustc.git] / src / tools / clippy / tests / ui / deref_addrof.rs
CommitLineData
f20569fa
XL
1// run-rustfix
2#![warn(clippy::deref_addrof)]
3
4fn get_number() -> usize {
5 10
6}
7
8fn get_reference(n: &usize) -> &usize {
9 n
10}
11
12#[allow(clippy::many_single_char_names, clippy::double_parens)]
13#[allow(unused_variables, unused_parens)]
14fn main() {
15 let a = 10;
16 let aref = &a;
17
18 let b = *&a;
19
20 let b = *&get_number();
21
22 let b = *get_reference(&a);
23
24 let bytes: Vec<usize> = vec![1, 2, 3, 4];
25 let b = *&bytes[1..2][0];
26
27 //This produces a suggestion of 'let b = (a);' which
28 //will trigger the 'unused_parens' lint
29 let b = *&(a);
30
31 let b = *(&a);
32
33 #[rustfmt::skip]
34 let b = *((&a));
35
36 let b = *&&a;
37
38 let b = **&aref;
39}
40
41#[rustfmt::skip]
42macro_rules! m {
43 ($visitor: expr) => {
44 *& $visitor
45 };
46}
47
48#[rustfmt::skip]
49macro_rules! m_mut {
50 ($visitor: expr) => {
51 *& mut $visitor
52 };
53}
54
55pub struct S;
56impl S {
57 pub fn f(&self) -> &Self {
58 m!(self)
59 }
60 pub fn f_mut(&self) -> &Self {
61 m_mut!(self)
62 }
63}