-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.L-unused_assignmentsLint: unused_assignmentsLint: unused_assignmentsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Code
#[deny(unused_assignments)]
fn main() {
let mut x = 1;
catch(|| {
x = 2; // <-
panic!();
});
dbg!(x);
}
fn catch<F: FnOnce()>(f: F) {
if let Ok(true) = std::fs::exists("may_or_may_not_call_f") {
_ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(f));
}
}Current output
error: value assigned to `x` is never read
--> src/main.rs:5:9
|
5 | x = 2; // <-
| ^^^^^
|
= help: maybe it is overwritten before being read?
note: the lint level is defined here
--> src/main.rs:1:8
|
1 | #[deny(unused_assignments)]
| ^^^^^^^^^^^^^^^^^^Desired output
<no error or warning>Rationale and extra context
This issue only exists if there is a panic!() inside the closure, otherwise no warning is emitted.
The initial value and the assigned value are all useful depending on if catch calls the closure. Neither of them should be considered "unused".
Other cases
Rust Version
1.95.0-nightly (2026-02-02 f60a0f1bcc5a2a6dd8eb)
(reproduced on playground nightly)Anything else?
The false positive only exists since 1.92.0 and the same code does not warn on 1.91.0.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.L-unused_assignmentsLint: unused_assignmentsLint: unused_assignmentsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.