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
  • Loading branch information
lapla-cogito committed Jan 22, 2025
1 parent 2280b8a commit 26838f8
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 26838f8

Please sign in to comment.