Auto merge of #4487 - JohnTitor:deref-addrof-external-macro, r=flip1995
Don't check across macro boundary in `deref_addrof` Fixes #4289 changelog: Allow `deref_addrof` in macros
This commit is contained in:
commit
98a25241cc
@ -1,4 +1,4 @@
|
|||||||
use crate::utils::{snippet_with_applicability, span_lint_and_sugg};
|
use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||||
@ -38,6 +38,7 @@ impl EarlyLintPass for DerefAddrOf {
|
|||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node;
|
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node;
|
||||||
if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node;
|
if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node;
|
||||||
|
if !in_macro(addrof_target.span);
|
||||||
then {
|
then {
|
||||||
let mut applicability = Applicability::MachineApplicable;
|
let mut applicability = Applicability::MachineApplicable;
|
||||||
span_lint_and_sugg(
|
span_lint_and_sugg(
|
||||||
|
10
tests/ui/deref_addrof_macro.rs
Normal file
10
tests/ui/deref_addrof_macro.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
macro_rules! m {
|
||||||
|
($($x:tt),*) => { &[$(($x, stringify!(x)),)*] };
|
||||||
|
}
|
||||||
|
|
||||||
|
#[warn(clippy::deref_addrof)]
|
||||||
|
fn f() -> [(i32, &'static str); 3] {
|
||||||
|
*m![1, 2, 3] // should be fine
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user