From 26838f8552bcb6bf38a10b56d0548580bf82c706 Mon Sep 17 00:00:00 2001 From: lapla-cogito Date: Wed, 22 Jan 2025 04:55:42 +0900 Subject: [PATCH] don't trigger `needless_late_init` when the first usage is in macro --- clippy_lints/src/needless_late_init.rs | 4 ++++ tests/ui/needless_late_init.fixed | 11 +++++++++++ tests/ui/needless_late_init.rs | 11 +++++++++++ 3 files changed, 26 insertions(+) diff --git a/clippy_lints/src/needless_late_init.rs b/clippy_lints/src/needless_late_init.rs index a67addea9486..dca3c0b10cdb 100644 --- a/clippy_lints/src/needless_late_init.rs +++ b/clippy_lints/src/needless_late_init.rs @@ -107,6 +107,10 @@ struct LocalAssign { impl LocalAssign { fn from_expr(expr: &Expr<'_>, span: Span) -> Option { + if expr.span.from_expansion() { + return None; + } + if let ExprKind::Assign(lhs, rhs, _) = expr.kind { if lhs.span.from_expansion() { return None; diff --git a/tests/ui/needless_late_init.fixed b/tests/ui/needless_late_init.fixed index 6db870490445..b4bd53ce7bf7 100644 --- a/tests/ui/needless_late_init.fixed +++ b/tests/ui/needless_late_init.fixed @@ -270,3 +270,14 @@ fn issue8911() -> u32 { 3 } + +macro_rules! issue13776_mac { + ($var:expr, $val:literal) => { + $var = $val; + }; +} + +fn issue13776() { + let x; + issue13776_mac!(x, 10); // should not lint +} diff --git a/tests/ui/needless_late_init.rs b/tests/ui/needless_late_init.rs index c1e86212a08b..e25483625a68 100644 --- a/tests/ui/needless_late_init.rs +++ b/tests/ui/needless_late_init.rs @@ -270,3 +270,14 @@ fn issue8911() -> u32 { 3 } + +macro_rules! issue13776_mac { + ($var:expr, $val:literal) => { + $var = $val; + }; +} + +fn issue13776() { + let x; + issue13776_mac!(x, 10); // should not lint +}