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

Struct Update/ Functional record update syntax error #32

Closed
arora-aman opened this issue Dec 4, 2020 · 1 comment · Fixed by rust-lang/rust#81291
Closed

Struct Update/ Functional record update syntax error #32

arora-aman opened this issue Dec 4, 2020 · 1 comment · Fixed by rust-lang/rust#81291
Assignees
Labels
bug Something isn't working

Comments

@arora-aman
Copy link
Member

arora-aman commented Dec 4, 2020

struct X {
    a : String,
    b : String,
    c : String,
}

impl X {
    fn from_other_X(o: Self) -> Self {
        let c = || {
            X { a: "".into(), ..o }
        };
        c()
    }
}

The closure captures o.b, and o.c. But in MIR we expect to see *o which causes issues

@arora-aman arora-aman added the bug Something isn't working label Dec 4, 2020
@arora-aman
Copy link
Member Author

@roxelo roxelo self-assigned this Jan 5, 2021
@arora-aman arora-aman assigned null-sleep and unassigned roxelo Jan 19, 2021
henryboisdequin added a commit to henryboisdequin/rust that referenced this issue Jan 29, 2021
…ional-record-update-syntax-error, r=nikomatsakis

Support FRU pattern with `[feature(capture_disjoint_fields)]`

In case of a functional record update syntax for creating a structure, `ExprUseVisitor` to only detect the precise use of some of the field in the `..x` part of the syntax. However, when we start building MIR, we
1. First, build the place for `x`
2. and then, add precise field projections so that only some parts of `x` end up getting read.

When `capture_disjoint_fields` is enabled, and FRU is used within a closure `x` won't be completely captured, and therefore the first step will fail. This PR updates `mir_build` to create a place builder in the first step and then create place from the builder only after applying the field projection.

Closes rust-lang/project-rfc-2229#32
r? `@nikomatsakis`
@nikomatsakis nikomatsakis added this to the Feature complete milestone Feb 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants