mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 14:31:55 +00:00
Allow deref_addrof in macros
This commit is contained in:
parent
a3fcaee562
commit
9a5b996228
@ -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 rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
||||
use rustc::{declare_lint_pass, declare_tool_lint};
|
||||
@ -38,6 +38,7 @@ impl EarlyLintPass for DerefAddrOf {
|
||||
if_chain! {
|
||||
if let ExprKind::Unary(UnOp::Deref, ref deref_target) = e.node;
|
||||
if let ExprKind::AddrOf(_, ref addrof_target) = without_parens(deref_target).node;
|
||||
if !in_macro(addrof_target.span);
|
||||
then {
|
||||
let mut applicability = Applicability::MachineApplicable;
|
||||
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