ignore array from deref_addrof
lint
Note that semantics of repeat expr in array are the same
This commit is contained in:
parent
4dcab72c1c
commit
8bd2a17dfe
@ -48,6 +48,9 @@ impl EarlyLintPass for DerefAddrOf {
|
|||||||
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
|
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) {
|
||||||
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind
|
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.kind
|
||||||
&& let ExprKind::AddrOf(_, ref mutability, ref addrof_target) = without_parens(deref_target).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)
|
&& deref_target.span.eq_ctxt(e.span)
|
||||||
&& !addrof_target.span.from_expansion()
|
&& !addrof_target.span.from_expansion()
|
||||||
{
|
{
|
||||||
|
@ -44,9 +44,9 @@ fn main() {
|
|||||||
|
|
||||||
let _ = unsafe { *core::ptr::addr_of!(a) };
|
let _ = unsafe { *core::ptr::addr_of!(a) };
|
||||||
|
|
||||||
// do NOT lint for array as sematic differences with/out `*&`.
|
|
||||||
let _repeat = [0; 64];
|
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)]
|
#[derive(Copy, Clone)]
|
||||||
|
@ -44,8 +44,8 @@ fn main() {
|
|||||||
|
|
||||||
let _ = unsafe { *core::ptr::addr_of!(a) };
|
let _ = unsafe { *core::ptr::addr_of!(a) };
|
||||||
|
|
||||||
// do NOT lint for array as sematic differences with/out `*&`.
|
|
||||||
let _repeat = *&[0; 64];
|
let _repeat = *&[0; 64];
|
||||||
|
// do NOT lint for array as sematic differences with/out `*&`.
|
||||||
let _arr = *&[0, 1, 2, 3, 4];
|
let _arr = *&[0, 1, 2, 3, 4];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,17 +50,11 @@ LL | let b = **&aref;
|
|||||||
| ^^^^^^ help: try: `aref`
|
| ^^^^^^ help: try: `aref`
|
||||||
|
|
||||||
error: immediately dereferencing a reference
|
error: immediately dereferencing a reference
|
||||||
--> tests/ui/deref_addrof.rs:48:19
|
--> tests/ui/deref_addrof.rs:47:19
|
||||||
|
|
|
|
||||||
LL | let _repeat = *&[0; 64];
|
LL | let _repeat = *&[0; 64];
|
||||||
| ^^^^^^^^^ help: try: `[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
|
error: immediately dereferencing a reference
|
||||||
--> tests/ui/deref_addrof.rs:57:17
|
--> tests/ui/deref_addrof.rs:57:17
|
||||||
|
|
|
|
||||||
@ -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)
|
= 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
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user