]> git.lizzy.rs Git - rust.git/blob - tests/ui/deref_addrof.fixed
Don't lint `deref_addrof` when the two operations occur in different expansions
[rust.git] / tests / ui / deref_addrof.fixed
1 // run-rustfix
2 #![allow(clippy::return_self_not_must_use)]
3 #![warn(clippy::deref_addrof)]
4
5 fn get_number() -> usize {
6     10
7 }
8
9 fn get_reference(n: &usize) -> &usize {
10     n
11 }
12
13 #[allow(clippy::double_parens)]
14 #[allow(unused_variables, unused_parens)]
15 fn main() {
16     let a = 10;
17     let aref = &a;
18
19     let b = a;
20
21     let b = get_number();
22
23     let b = *get_reference(&a);
24
25     let bytes: Vec<usize> = vec![1, 2, 3, 4];
26     let b = bytes[1..2][0];
27
28     //This produces a suggestion of 'let b = (a);' which
29     //will trigger the 'unused_parens' lint
30     let b = (a);
31
32     let b = a;
33
34     #[rustfmt::skip]
35     let b = a;
36
37     let b = &a;
38
39     let b = *aref;
40
41     let _ = unsafe { *core::ptr::addr_of!(a) };
42 }
43
44 #[rustfmt::skip]
45 macro_rules! m {
46     ($visitor: expr) => {
47         $visitor
48     };
49 }
50
51 #[rustfmt::skip]
52 macro_rules! m_mut {
53     ($visitor: expr) => {
54         $visitor
55     };
56 }
57
58 #[derive(Copy, Clone)]
59 pub struct S;
60 impl S {
61     pub fn f(&self) -> &Self {
62         m!(self)
63     }
64     #[allow(unused_mut)] // mut will be unused, once the macro is fixed
65     pub fn f_mut(mut self) -> Self {
66         m_mut!(self)
67     }
68 }