]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/deref_addrof.rs
Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
[rust.git] / tests / ui / deref_addrof.rs
index 5641a73cbc1cb1b73e766dbbfb8de1d515a12e6d..49f360b9a7f9e2ca7f7d6275d69f546f764b41d9 100644 (file)
@@ -1,4 +1,6 @@
 // run-rustfix
+#![allow(clippy::return_self_not_must_use)]
+#![warn(clippy::deref_addrof)]
 
 fn get_number() -> usize {
     10
@@ -8,9 +10,8 @@ fn get_reference(n: &usize) -> &usize {
     n
 }
 
-#[allow(clippy::many_single_char_names, clippy::double_parens)]
+#[allow(clippy::double_parens)]
 #[allow(unused_variables, unused_parens)]
-#[warn(clippy::deref_addrof)]
 fn main() {
     let a = 10;
     let aref = &a;
@@ -36,4 +37,32 @@ fn main() {
     let b = *&&a;
 
     let b = **&aref;
+
+    let _ = unsafe { *core::ptr::addr_of!(a) };
+}
+
+#[rustfmt::skip]
+macro_rules! m {
+    ($visitor: expr) => {
+        *& $visitor
+    };
+}
+
+#[rustfmt::skip]
+macro_rules! m_mut {
+    ($visitor: expr) => {
+        *& mut $visitor
+    };
+}
+
+#[derive(Copy, Clone)]
+pub struct S;
+impl S {
+    pub fn f(&self) -> &Self {
+        m!(self)
+    }
+    #[allow(unused_mut)] // mut will be unused, once the macro is fixed
+    pub fn f_mut(mut self) -> Self {
+        m_mut!(self)
+    }
 }