-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way
Description
Summary
let dbtx_ref = match db_tx {
Some(ref mut db_tx) => Some(db_tx),
None => dbtx.as_deref_mut(),
};
The suggestion says let dbtx_ref = db_tx.as_mut();
which is not accurate. It should've been let dbtx_ref = db_tx.as_mut().or_else(|| /* whatever's in the None branch if not None */)
Lint Name
match_as_ref
Reproducer
I tried this code:
<code>
let dbtx_ref = match db_tx {
Some(ref mut db_tx) => Some(db_tx),
None => dbtx.as_deref_mut(),
};
</code>
I saw this happen:
<output>
let dbtx_ref = db_tx.as_mut();
</output>
I expected to see this happen:
<output>
let dbtx_ref = db_tx.as_mut().or(dbtx.as_deref_mut());
</output>
Version
rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: aarch64-apple-darwin
release: 1.85.1
LLVM version: 19.1.7
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-bugIssue: The suggestion compiles but changes the code to behave in an unintended wayIssue: The suggestion compiles but changes the code to behave in an unintended way