Skip to content

Commit ffc9d2f

Browse files
committed
oops: semantics of repeat expr in array is the same
1 parent c58f3c1 commit ffc9d2f

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

clippy_lints/src/reference.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +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(..))
51+
// NOTE(tesuji): semantics diffences with/out `*&` for array literal `[x, y, ..]`
52+
&& !matches!(addrof_target.kind, ExprKind::Array(_))
5353
&& deref_target.span.eq_ctxt(e.span)
5454
&& !addrof_target.span.from_expansion()
5555
{

tests/ui/deref_addrof.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ fn main() {
4444

4545
let _ = unsafe { *core::ptr::addr_of!(a) };
4646

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

tests/ui/deref_addrof.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ fn main() {
4444

4545
let _ = unsafe { *core::ptr::addr_of!(a) };
4646

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

tests/ui/deref_addrof.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ 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:47:19
54+
|
55+
LL | let _repeat = *&[0; 64];
56+
| ^^^^^^^^^ help: try: `[0; 64]`
57+
5258
error: immediately dereferencing a reference
5359
--> tests/ui/deref_addrof.rs:57:17
5460
|
@@ -65,5 +71,5 @@ LL | inline!(*&mut $(@expr self))
6571
|
6672
= note: this error originates in the macro `__inline_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
6773

68-
error: aborting due to 10 previous errors
74+
error: aborting due to 11 previous errors
6975

0 commit comments

Comments
 (0)