Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Handle patterns within closures with the feature gate enabled #24

Closed
arora-aman opened this issue Nov 13, 2020 · 3 comments · Fixed by rust-lang/rust#82536
Closed

Handle patterns within closures with the feature gate enabled #24

arora-aman opened this issue Nov 13, 2020 · 3 comments · Fixed by rust-lang/rust#82536
Assignees
Labels
bug Something isn't working
Projects

Comments

@arora-aman
Copy link
Member

arora-aman commented Nov 13, 2020

When capture_disjoint_fields is enabled we see that the compiler ICEs when closure contains something like

let x = 10;
let tup = (1, 2);
let p = Point { x: 10, y: 20 };

let c = || {
    let _ = x;
    let Point { x, y } = p; // 1
    let (_, _) = tup; // 2
};

The problem here is that in case 1 p[0] and p[1] are captured, but when we build MIR we need to get information about the initializer which is p in this case which is missing since p itself isn't captured.

The issue with 2 is that since nothing from tup is used, nothing is captured. Nothing will be read when MIR is built either, but to build MIR we need access to tup, which we don't have.

Ensure ui/closures/2229_closure_analysis/wild_patterns passes

@arora-aman arora-aman added this to To-do in RFC-2229 via automation Nov 13, 2020
@arora-aman arora-aman changed the title Handle let _ = x within closures with the feature gate enabled Handle Wildcard pattern within closures with the feature gate enabled Dec 2, 2020
@arora-aman arora-aman self-assigned this Dec 4, 2020
@arora-aman arora-aman added the bug Something isn't working label Dec 4, 2020
@arora-aman arora-aman changed the title Handle Wildcard pattern within closures with the feature gate enabled Handle patterns within closures with the feature gate enabled Dec 4, 2020
@roxelo
Copy link
Member

roxelo commented Jan 5, 2021

Once this is implemented, also modify the following test so the closure body is:

let SingleVariant::Point(ref mut x, _) = point;
*x += 1;

@roxelo roxelo moved this from To-do to In progress in RFC-2229 Jan 5, 2021
@roxelo roxelo self-assigned this Jan 5, 2021
@arora-aman
Copy link
Member Author

arora-aman commented Jan 15, 2021

Iniital ideas: https://hackmd.io/fgc31ECfQnaxfP9DmjgVNw?view

@arora-aman
Copy link
Member Author

More detailed ideas using fake reads for "upvars": https://hackmd.io/fgc31ECfQnaxfP9DmjgVNw

@roxelo roxelo moved this from In progress to In review in RFC-2229 Feb 25, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Mar 16, 2021
…=nikomatsakis

2229: Handle patterns within closures correctly when `capture_disjoint_fields` is enabled

This PR fixes several issues related to handling patterns within closures when `capture_disjoint_fields` is enabled.
1. Matching is always considered a use of the place, even with `_` patterns
2. Compiler ICE when capturing fields in closures through `let` assignments

To do so, we

- Introduced new Fake Reads
- Delayed use of `Place` in favor of `PlaceBuilder`
- Ensured that `PlaceBuilder` can be resolved before attempting to extract `Place` in any of the pattern matching code

Closes rust-lang/project-rfc-2229/issues/27
Closes rust-lang/project-rfc-2229/issues/24
r? `@nikomatsakis`
@roxelo roxelo moved this from In review to Done in RFC-2229 Mar 16, 2021
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Mar 25, 2021
…akis

2229: Handle patterns within closures correctly when `capture_disjoint_fields` is enabled

This PR fixes several issues related to handling patterns within closures when `capture_disjoint_fields` is enabled.
1. Matching is always considered a use of the place, even with `_` patterns
2. Compiler ICE when capturing fields in closures through `let` assignments

To do so, we

- Introduced new Fake Reads
- Delayed use of `Place` in favor of `PlaceBuilder`
- Ensured that `PlaceBuilder` can be resolved before attempting to extract `Place` in any of the pattern matching code

Closes rust-lang/project-rfc-2229/issues/27
Closes rust-lang/project-rfc-2229/issues/24
r? `@nikomatsakis`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
RFC-2229
  
Done
3 participants