]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/deref_addrof.rs
New upstream version 1.60.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / deref_addrof.rs
CommitLineData
f20569fa 1// run-rustfix
a2a8927a 2#![allow(clippy::return_self_not_must_use)]
f20569fa
XL
3#![warn(clippy::deref_addrof)]
4
5fn get_number() -> usize {
6 10
7}
8
9fn get_reference(n: &usize) -> &usize {
10 n
11}
12
c295e0f8 13#[allow(clippy::double_parens)]
f20569fa
XL
14#[allow(unused_variables, unused_parens)]
15fn 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;
5099ac24
FG
40
41 let _ = unsafe { *core::ptr::addr_of!(a) };
f20569fa
XL
42}
43
44#[rustfmt::skip]
45macro_rules! m {
46 ($visitor: expr) => {
47 *& $visitor
48 };
49}
50
51#[rustfmt::skip]
52macro_rules! m_mut {
53 ($visitor: expr) => {
54 *& mut $visitor
55 };
56}
57
3c0e092e 58#[derive(Copy, Clone)]
f20569fa
XL
59pub struct S;
60impl S {
61 pub fn f(&self) -> &Self {
62 m!(self)
63 }
3c0e092e
XL
64 #[allow(unused_mut)] // mut will be unused, once the macro is fixed
65 pub fn f_mut(mut self) -> Self {
f20569fa
XL
66 m_mut!(self)
67 }
68}