Auto merge of #12864 - tesuji:non-no-effect, r=y21

ignore array from `deref_addrof` lint

Split from https://github.com/rust-lang/rust-clippy/pull/12854

changelog: ignore array from `deref_addrof` lint

r? y21
This commit is contained in:
bors 2024-05-30 10:16:50 +00:00
commit 03654badfd
4 changed files with 20 additions and 3 deletions

View File

@ -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()
{

View File

@ -43,6 +43,10 @@ fn main() {
let b = *aref;
let _ = unsafe { *core::ptr::addr_of!(a) };
let _repeat = [0; 64];
// do NOT lint for array as sematic differences with/out `*&`.
let _arr = *&[0, 1, 2, 3, 4];
}
#[derive(Copy, Clone)]

View File

@ -43,6 +43,10 @@ fn main() {
let b = **&aref;
let _ = unsafe { *core::ptr::addr_of!(a) };
let _repeat = *&[0; 64];
// do NOT lint for array as sematic differences with/out `*&`.
let _arr = *&[0, 1, 2, 3, 4];
}
#[derive(Copy, Clone)]

View File

@ -50,7 +50,13 @@ LL | let b = **&aref;
| ^^^^^^ help: try: `aref`
error: immediately dereferencing a reference
--> tests/ui/deref_addrof.rs:53:17
--> 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:57:17
|
LL | inline!(*& $(@expr self))
| ^^^^^^^^^^^^^^^^ help: try: `$(@expr self)`
@ -58,12 +64,12 @@ LL | inline!(*& $(@expr self))
= note: this error originates in the macro `__inline_mac_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
error: immediately dereferencing a reference
--> tests/ui/deref_addrof.rs:57:17
--> tests/ui/deref_addrof.rs:61:17
|
LL | inline!(*&mut $(@expr self))
| ^^^^^^^^^^^^^^^^^^^ help: try: `$(@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 10 previous errors
error: aborting due to 11 previous errors