Avoid invalid if_then_some_else_none suggestions in try blocks - #17623
Open
eviaaaaa wants to merge 1 commit into
Open
Avoid invalid if_then_some_else_none suggestions in try blocks#17623eviaaaaa wants to merge 1 commit into
if_then_some_else_none suggestions in try blocks#17623eviaaaaa wants to merge 1 commit into
Conversation
Collaborator
|
Thanks for the pull request, and welcome! You should hear from one of our reviewers after this PR gets at least 2 reviews from the community. Please see the contribution instructions for more information. |
CommanderStorm
suggested changes
Aug 25, 2026
Author
|
@CommanderStorm Thanks for the review. I addressed all four points in 6631233, and CI is green. Could you take another look when you have a chance? Extracted the nested logic into |
CommanderStorm
approved these changes
Aug 26, 2026
Contributor
|
make sure to squash them into one commit 😉 |
Avoid invalid suggestions when `?` targets a try block outside the code moved into the closure. Group the UI tests, use lint expectations and black_box, and extract the try-break analysis for readability. Co-authored-by: Frank Elsinga <frank.elsinga@tum.de>
eviaaaaa
force-pushed
the
fix/if-then-some-try-suggestion
branch
from
August 26, 2026 06:17
6631233 to
542d0be
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
if_then_some_else_nonerewrites anifexpression tobool::then, it moves theSomebranch into a new closure. A?whose residualbreaktargets an enclosing try block cannot move into that closure: the generated code instead tries to use?from a closure returning the inner value, and fails to compile.The previous guard handled explicit
returnandyield, but a?inside a try block lowers toMatchSource::TryDesugarwith a residualBreak, so the lint still emitted a machine-applicable suggestion.This change inspects that residual break destination. The lint is suppressed only when the destination is outside the expression being moved. A nested
try { ... }moves together with theSomebranch, so its?remains valid and the suggestion is still emitted.fixes #17596
The regression matrix was run against the unmodified lint first: direct and statement-form
?cases produced unexpected diagnostics, and compiling the exact suggestion failed withE0277because the new closure did not returnResult,Option, or anotherFromResidualtype.The UI coverage includes:
?targeting the enclosing try block;?as positive controls;UI/rustfix coverage was added for both enclosing and nested try contexts; the relevant UI tests and
clippy_lintstest suite pass.changelog: [
if_then_some_else_none]: avoid suggestions that move?out of its enclosing try context