Fix missing unused_variables lint when using a match guard

Within a binding pattern match guard, only real reads of a bound local
impact its liveness analysis - not the fake read that is injected.
This commit is contained in:
Alan Egerton 2026-02-02 09:38:07 +00:00
parent cdee2fbff5
commit 267f40dbb4

View file

@ -85,7 +85,7 @@ impl LateLintPass<'_> for UncheckedTimeSubtraction {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) {
let (lhs, rhs) = match expr.kind {
ExprKind::Binary(op, lhs, rhs) if matches!(op.node, BinOpKind::Sub,) => (lhs, rhs),
ExprKind::MethodCall(fn_name, lhs, [rhs], _) if cx.ty_based_def(expr).is_diag_item(cx, sym::sub) => {
ExprKind::MethodCall(_, lhs, [rhs], _) if cx.ty_based_def(expr).is_diag_item(cx, sym::sub) => {
(lhs, rhs)
},
_ => return,