]> git.lizzy.rs Git - rust.git/commitdiff
Don't lint `deref_addrof` when the two operations occur in different expansions
authorJason Newcomb <jsnewcomb@pm.me>
Wed, 12 Jan 2022 05:25:42 +0000 (00:25 -0500)
committerJason Newcomb <jsnewcomb@pm.me>
Wed, 12 Jan 2022 05:25:42 +0000 (00:25 -0500)
clippy_lints/src/reference.rs
tests/ui/deref_addrof.fixed
tests/ui/deref_addrof.rs
tests/ui/deref_addrof.stderr

index 22ae7a291d00e5486e9ef8cb6a7b306aefda8257..b24483723700c2b031a404dddb0fd70db862ccc1 100644 (file)
@@ -50,6 +50,7 @@ fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
         if_chain! {
             if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind;
             if let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).kind;
+            if deref_target.span.ctxt() == e.span.ctxt();
             if !addrof_target.span.from_expansion();
             then {
                 let mut applicability = Applicability::MachineApplicable;
index 0029fc673f1107105b110987b20bd6ff236dfab9..2f489deb1ee1f5910b3acd8038c5de8ac531c877 100644 (file)
@@ -37,6 +37,8 @@ fn main() {
     let b = &a;
 
     let b = *aref;
+
+    let _ = unsafe { *core::ptr::addr_of!(a) };
 }
 
 #[rustfmt::skip]
index f2f02dd5e723d8a78c1918c4f8e597df4239c0aa..49f360b9a7f9e2ca7f7d6275d69f546f764b41d9 100644 (file)
@@ -37,6 +37,8 @@ fn main() {
     let b = *&&a;
 
     let b = **&aref;
+
+    let _ = unsafe { *core::ptr::addr_of!(a) };
 }
 
 #[rustfmt::skip]
index 5bc1cbfa215100e5bdf0c41648e40dc85722927e..75371fcdb9677f476dc1bfaebceaa78cc0685d38 100644 (file)
@@ -49,7 +49,7 @@ LL |     let b = **&aref;
    |              ^^^^^^ help: try this: `aref`
 
 error: immediately dereferencing a reference
-  --> $DIR/deref_addrof.rs:45:9
+  --> $DIR/deref_addrof.rs:47:9
    |
 LL |         *& $visitor
    |         ^^^^^^^^^^^ help: try this: `$visitor`
@@ -60,7 +60,7 @@ LL |         m!(self)
    = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error: immediately dereferencing a reference
-  --> $DIR/deref_addrof.rs:52:9
+  --> $DIR/deref_addrof.rs:54:9
    |
 LL |         *& mut $visitor
    |         ^^^^^^^^^^^^^^^ help: try this: `$visitor`