Skip to content

Commit 396de57

Browse files
authored
don't trigger needless_late_init when the first usage is in macro (rust-lang#14053)
fix rust-lang#13776 changelog: [`needless_late_init`]: don't trigger `needless_late_init` when the first usage is in macro
2 parents d1b5fa2 + 26838f8 commit 396de57

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

clippy_lints/src/needless_late_init.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ struct LocalAssign {
107107

108108
impl LocalAssign {
109109
fn from_expr(expr: &Expr<'_>, span: Span) -> Option<Self> {
110+
if expr.span.from_expansion() {
111+
return None;
112+
}
113+
110114
if let ExprKind::Assign(lhs, rhs, _) = expr.kind {
111115
if lhs.span.from_expansion() {
112116
return None;

tests/ui/needless_late_init.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,14 @@ fn issue8911() -> u32 {
270270

271271
3
272272
}
273+
274+
macro_rules! issue13776_mac {
275+
($var:expr, $val:literal) => {
276+
$var = $val;
277+
};
278+
}
279+
280+
fn issue13776() {
281+
let x;
282+
issue13776_mac!(x, 10); // should not lint
283+
}

tests/ui/needless_late_init.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,14 @@ fn issue8911() -> u32 {
270270

271271
3
272272
}
273+
274+
macro_rules! issue13776_mac {
275+
($var:expr, $val:literal) => {
276+
$var = $val;
277+
};
278+
}
279+
280+
fn issue13776() {
281+
let x;
282+
issue13776_mac!(x, 10); // should not lint
283+
}

0 commit comments

Comments
 (0)