Skip to content

Commit

Permalink
don't trigger needless_late_init when the first usage is in macro (#…
Browse files Browse the repository at this point in the history
…14053)

fix #13776

changelog: [`needless_late_init`]: don't trigger `needless_late_init`
when the first usage is in macro
  • Loading branch information
y21 authored Jan 22, 2025
2 parents d1b5fa2 + 26838f8 commit 396de57
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clippy_lints/src/needless_late_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ struct LocalAssign {

impl LocalAssign {
fn from_expr(expr: &Expr<'_>, span: Span) -> Option<Self> {
if expr.span.from_expansion() {
return None;
}

if let ExprKind::Assign(lhs, rhs, _) = expr.kind {
if lhs.span.from_expansion() {
return None;
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/needless_late_init.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions tests/ui/needless_late_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 396de57

Please sign in to comment.