about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/reference.rs3
-rw-r--r--tests/ui/deref_addrof.fixed4
-rw-r--r--tests/ui/deref_addrof.rs2
-rw-r--r--tests/ui/deref_addrof.stderr10
4 files changed, 8 insertions, 11 deletions
diff --git a/clippy_lints/src/reference.rs b/clippy_lints/src/reference.rs
index 16086ba6637..8f32cf5f2a1 100644
--- a/clippy_lints/src/reference.rs
+++ b/clippy_lints/src/reference.rs
@@ -48,6 +48,9 @@ impl EarlyLintPass for DerefAddrOf {
     fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
         if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind
             && let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).kind
+            // NOTE(tesuji): `*&` forces rustc to const-promote the array to `.rodata` section.
+            // See #12854 for details.
+            && !matches!(addrof_target.kind, ExprKind::Array(_))
             && deref_target.span.eq_ctxt(e.span)
             && !addrof_target.span.from_expansion()
         {
diff --git a/tests/ui/deref_addrof.fixed b/tests/ui/deref_addrof.fixed
index db7c44c4c63..b6278c6ca8a 100644
--- a/tests/ui/deref_addrof.fixed
+++ b/tests/ui/deref_addrof.fixed
@@ -44,9 +44,9 @@ fn main() {
 
     let _ = unsafe { *core::ptr::addr_of!(a) };
 
-    // do NOT lint for array as sematic differences with/out `*&`.
     let _repeat = [0; 64];
-    let _arr = [0, 1, 2, 3, 4];
+    // do NOT lint for array as sematic differences with/out `*&`.
+    let _arr = *&[0, 1, 2, 3, 4];
 }
 
 #[derive(Copy, Clone)]
diff --git a/tests/ui/deref_addrof.rs b/tests/ui/deref_addrof.rs
index 79b82a76a13..572b0fdb102 100644
--- a/tests/ui/deref_addrof.rs
+++ b/tests/ui/deref_addrof.rs
@@ -44,8 +44,8 @@ fn main() {
 
     let _ = unsafe { *core::ptr::addr_of!(a) };
 
-    // do NOT lint for array as sematic differences with/out `*&`.
     let _repeat = *&[0; 64];
+    // do NOT lint for array as sematic differences with/out `*&`.
     let _arr = *&[0, 1, 2, 3, 4];
 }
 
diff --git a/tests/ui/deref_addrof.stderr b/tests/ui/deref_addrof.stderr
index 856d775d932..20069f746c8 100644
--- a/tests/ui/deref_addrof.stderr
+++ b/tests/ui/deref_addrof.stderr
@@ -50,18 +50,12 @@ LL |     let b = **&aref;
    |              ^^^^^^ help: try: `aref`
 
 error: immediately dereferencing a reference
-  --> tests/ui/deref_addrof.rs:48:19
+  --> tests/ui/deref_addrof.rs:47:19
    |
 LL |     let _repeat = *&[0; 64];
    |                   ^^^^^^^^^ help: try: `[0; 64]`
 
 error: immediately dereferencing a reference
-  --> tests/ui/deref_addrof.rs:49:16
-   |
-LL |     let _arr = *&[0, 1, 2, 3, 4];
-   |                ^^^^^^^^^^^^^^^^^ help: try: `[0, 1, 2, 3, 4]`
-
-error: immediately dereferencing a reference
   --> tests/ui/deref_addrof.rs:57:17
    |
 LL |         inline!(*& $(@expr self))
@@ -77,5 +71,5 @@ LL |         inline!(*&mut $(@expr self))
    |
    = note: this error originates in the macro `__inline_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: aborting due to 12 previous errors
+error: aborting due to 11 previous errors