Skip to content

Commit c58f3c1

Browse files
committed
ignore array from deref_addrof lint
1 parent 4dcab72 commit c58f3c1

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

clippy_lints/src/reference.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ impl EarlyLintPass for DerefAddrOf {
4848
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
4949
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind
5050
&& let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).kind
51+
// NOTE(tesuji): semantics diffences with/out `*&` for array
52+
&& !matches!(addrof_target.kind, ExprKind::Array(_) | ExprKind::Repeat(..))
5153
&& deref_target.span.eq_ctxt(e.span)
5254
&& !addrof_target.span.from_expansion()
5355
{

tests/ui/deref_addrof.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ fn main() {
4545
let _ = unsafe { *core::ptr::addr_of!(a) };
4646

4747
// do NOT lint for array as sematic differences with/out `*&`.
48-
let _repeat = [0; 64];
49-
let _arr = [0, 1, 2, 3, 4];
48+
let _repeat = *&[0; 64];
49+
let _arr = *&[0, 1, 2, 3, 4];
5050
}
5151

5252
#[derive(Copy, Clone)]

tests/ui/deref_addrof.stderr

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ error: immediately dereferencing a reference
4949
LL | let b = **&aref;
5050
| ^^^^^^ help: try: `aref`
5151

52-
error: immediately dereferencing a reference
53-
--> tests/ui/deref_addrof.rs:48:19
54-
|
55-
LL | let _repeat = *&[0; 64];
56-
| ^^^^^^^^^ help: try: `[0; 64]`
57-
58-
error: immediately dereferencing a reference
59-
--> tests/ui/deref_addrof.rs:49:16
60-
|
61-
LL | let _arr = *&[0, 1, 2, 3, 4];
62-
| ^^^^^^^^^^^^^^^^^ help: try: `[0, 1, 2, 3, 4]`
63-
6452
error: immediately dereferencing a reference
6553
--> tests/ui/deref_addrof.rs:57:17
6654
|
@@ -77,5 +65,5 @@ LL | inline!(*&mut $(@expr self))
7765
|
7866
= note: this error originates in the macro `__inline_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
7967

80-
error: aborting due to 12 previous errors
68+
error: aborting due to 10 previous errors
8169

0 commit comments

Comments
 (0)