Don't suggest collapsible_match guard when condition mutates pattern binding#16869
Open
JasmineLCY wants to merge 1 commit intorust-lang:masterfrom
Open
Don't suggest collapsible_match guard when condition mutates pattern binding#16869JasmineLCY wants to merge 1 commit intorust-lang:masterfrom
collapsible_match guard when condition mutates pattern binding#16869JasmineLCY wants to merge 1 commit intorust-lang:masterfrom
Conversation
…n binding When `mutated_variables` returns `None` (cannot determine mutations), `pat_bindings_moved_or_mutated` silently ignored the result instead of conservatively bailing out. This caused the lint to suggest match guards for expressions that require mutable access to pattern bindings, which is forbidden in guards. Fixes rust-lang#16864
Collaborator
|
r? @llogiq rustbot has assigned @llogiq. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Collaborator
|
Member
|
Please claim the issue you want to fix so that nobody works on it as well, and remove the issue number from the commit message as indicated in #16869 (comment) |
Author
|
Apologies for the delayed response. Will claim the issue and fix the commit message. |
llogiq
approved these changes
Apr 24, 2026
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
mutated_variablesreturnsNone(cannot determine mutations),pat_bindings_moved_or_mutatedsilently ignored the result instead of conservatively bailing out. This caused the lint to suggest match guards for expressions that require mutable access to pattern bindings, which is forbidden in guards — variables are immutable in pattern guards.The fix changes the
if let Some(mutated)tolet Some(mutated) ... else { return true }, matching the existing conservative bail-out forExprUseVisitorerrors a few lines above.Fixes #16864
changelog: Fix [
collapsible_match] suggesting a match guard when the condition mutates a pattern bindingDrafted with AI assistance. Reviewed, tested, and verified by me.