Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/rustc_mir_transform/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1243,9 +1243,12 @@ struct TransferFunction<'a, 'tcx> {
impl<'tcx> Visitor<'tcx> for TransferFunction<'_, 'tcx> {
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
match statement.kind {
// `ForLet(None)` fake read erroneously marks the just-assigned local as live.
// This defeats the purpose of the analysis for `let` bindings.
StatementKind::FakeRead(box (FakeReadCause::ForLet(None), _)) => return,
// `ForLet(None)` and `ForGuardBinding` fake reads erroneously mark the just-assigned
// locals as live. This defeats the purpose of the analysis for such bindings.
StatementKind::FakeRead(box (
FakeReadCause::ForLet(None) | FakeReadCause::ForGuardBinding,
_,
)) => return,
// Handle self-assignment by restricting the read/write they do.
StatementKind::Assign(box (ref dest, ref rvalue))
if self.self_assignment.contains(&location) =>
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/time_subtraction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, nice that this finds a real case in clippy.

(lhs, rhs)
},
_ => return,
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/lint/unused/match_with_guard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! The mere presence of a match guard should not deem bound variables "used".
//! Regression test for https://github.com/rust-lang/rust/issues/151983
//@ check-pass
#![warn(unused)]
fn main() {
match Some(42) {
Some(unused) if true => (), //~WARN unused variable: `unused`
_ => (),
}
}
15 changes: 15 additions & 0 deletions tests/ui/lint/unused/match_with_guard.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
warning: unused variable: `unused`
--> $DIR/match_with_guard.rs:7:14
|
LL | Some(unused) if true => (),
| ^^^^^^ help: if this is intentional, prefix it with an underscore: `_unused`
|
note: the lint level is defined here
--> $DIR/match_with_guard.rs:4:9
|
LL | #![warn(unused)]
| ^^^^^^
= note: `#[warn(unused_variables)]` implied by `#[warn(unused)]`

warning: 1 warning emitted

Loading