-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
fix: fix the capture behavior of if let in closures
#154210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Embers-of-the-Fire
wants to merge
5
commits into
rust-lang:main
Choose a base branch
from
Embers-of-the-Fire:feat/if-let-no-full-capture
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7be157a
test: cover current if let closure capture behavior
Embers-of-the-Fire 66777ad
fix: drop eager if let scrutinee borrow during capture analysis
Embers-of-the-Fire e38954c
test(ui): add regression for if-let closure capture size
Embers-of-the-Fire 4d78fd1
feat: remove callback param for walk_local method
Embers-of-the-Fire 60dd108
test: add if let test for partial capture
Embers-of-the-Fire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
54 changes: 54 additions & 0 deletions
54
tests/ui/closures/2229_closure_analysis/if-let-patterns-capture-analysis.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| //@ edition:2021 | ||
|
|
||
| #![feature(rustc_attrs)] | ||
| #![feature(stmt_expr_attributes)] | ||
| #![allow(irrefutable_let_patterns)] | ||
|
|
||
| enum SingleVariant { | ||
| Pair(i32, String), | ||
| } | ||
|
|
||
| fn if_let_closure() { | ||
| let variant = SingleVariant::Pair(1, "hello".into()); | ||
|
|
||
| let c = #[rustc_capture_analysis] | ||
| || { | ||
| //~^ ERROR First Pass analysis includes: | ||
| //~| ERROR Min Capture analysis includes: | ||
| if let SingleVariant::Pair(ref n, s) = variant { | ||
| //~^ NOTE: Capturing variant[(0, 0)] -> Immutable | ||
| //~| NOTE: Capturing variant[(1, 0)] -> ByValue | ||
| //~| NOTE: Min Capture variant[(0, 0)] -> Immutable | ||
| //~| NOTE: Min Capture variant[(1, 0)] -> ByValue | ||
| let _ = (n, s); | ||
| } | ||
| }; | ||
|
|
||
| c(); | ||
| } | ||
|
|
||
| fn match_closure() { | ||
| let variant = SingleVariant::Pair(1, "hello".into()); | ||
|
|
||
| let c = #[rustc_capture_analysis] | ||
| || { | ||
| //~^ ERROR First Pass analysis includes: | ||
| //~| ERROR Min Capture analysis includes: | ||
| match variant { | ||
| //~^ NOTE: Capturing variant[(0, 0)] -> Immutable | ||
| //~| NOTE: Capturing variant[(1, 0)] -> ByValue | ||
| //~| NOTE: Min Capture variant[(0, 0)] -> Immutable | ||
| //~| NOTE: Min Capture variant[(1, 0)] -> ByValue | ||
| SingleVariant::Pair(ref n, s) => { | ||
| let _ = (n, s); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| c(); | ||
| } | ||
|
|
||
| fn main() { | ||
| if_let_closure(); | ||
| match_closure(); | ||
| } |
90 changes: 90 additions & 0 deletions
90
tests/ui/closures/2229_closure_analysis/if-let-patterns-capture-analysis.stderr
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| error: First Pass analysis includes: | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:15:5 | ||
| | | ||
| LL | / || { | ||
| LL | | | ||
| LL | | | ||
| LL | | if let SingleVariant::Pair(ref n, s) = variant { | ||
| ... | | ||
| LL | | }; | ||
| | |_____^ | ||
| | | ||
| note: Capturing variant[(0, 0)] -> Immutable | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:18:48 | ||
| | | ||
| LL | if let SingleVariant::Pair(ref n, s) = variant { | ||
| | ^^^^^^^ | ||
| note: Capturing variant[(1, 0)] -> ByValue | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:18:48 | ||
| | | ||
| LL | if let SingleVariant::Pair(ref n, s) = variant { | ||
| | ^^^^^^^ | ||
|
|
||
| error: Min Capture analysis includes: | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:15:5 | ||
| | | ||
| LL | / || { | ||
| LL | | | ||
| LL | | | ||
| LL | | if let SingleVariant::Pair(ref n, s) = variant { | ||
| ... | | ||
| LL | | }; | ||
| | |_____^ | ||
| | | ||
| note: Min Capture variant[(0, 0)] -> Immutable | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:18:48 | ||
| | | ||
| LL | if let SingleVariant::Pair(ref n, s) = variant { | ||
| | ^^^^^^^ | ||
| note: Min Capture variant[(1, 0)] -> ByValue | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:18:48 | ||
| | | ||
| LL | if let SingleVariant::Pair(ref n, s) = variant { | ||
| | ^^^^^^^ | ||
|
|
||
| error: First Pass analysis includes: | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:34:5 | ||
| | | ||
| LL | / || { | ||
| LL | | | ||
| LL | | | ||
| LL | | match variant { | ||
| ... | | ||
| LL | | }; | ||
| | |_____^ | ||
| | | ||
| note: Capturing variant[(0, 0)] -> Immutable | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:37:15 | ||
| | | ||
| LL | match variant { | ||
| | ^^^^^^^ | ||
| note: Capturing variant[(1, 0)] -> ByValue | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:37:15 | ||
| | | ||
| LL | match variant { | ||
| | ^^^^^^^ | ||
|
|
||
| error: Min Capture analysis includes: | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:34:5 | ||
| | | ||
| LL | / || { | ||
| LL | | | ||
| LL | | | ||
| LL | | match variant { | ||
| ... | | ||
| LL | | }; | ||
| | |_____^ | ||
| | | ||
| note: Min Capture variant[(0, 0)] -> Immutable | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:37:15 | ||
| | | ||
| LL | match variant { | ||
| | ^^^^^^^ | ||
| note: Min Capture variant[(1, 0)] -> ByValue | ||
| --> $DIR/if-let-patterns-capture-analysis.rs:37:15 | ||
| | | ||
| LL | match variant { | ||
| | ^^^^^^^ | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.