Skip to content
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

NLL Diagnostic Review 3: Unions not reinitialized after assignment into field #55651

Closed
davidtwco opened this issue Nov 3, 2018 · 3 comments · Fixed by #55657
Closed

NLL Diagnostic Review 3: Unions not reinitialized after assignment into field #55651

davidtwco opened this issue Nov 3, 2018 · 3 comments · Fixed by #55657
Assignees
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-complete Working towards the "valid code works" goal NLL-diagnostics Working towards the "diagnostic parity" goal P-high High priority

Comments

@davidtwco
Copy link
Member

davidtwco commented Nov 3, 2018

@pnkfelix's review comments:

ui/borrowck/borrowck-union-move-assign.nll.stderr rejecting sound uses of unions; it reports 3 errors when only one expected. We should make a run-pass test from the two cases we expect to accept.

For the record, here's the relevant part of the test in question (play):

#![feature(untagged_unions)]
struct A;
struct B;
union U {
    a: A,
    b: B,
}
fn main() {
    unsafe {
        {
            let mut u = U { a: A };
            let _a = u.a;
            u.a = A;
            let _a = u.a; // OK
        }
        {
            let mut u = U { a: A };
            let _a = u.a;
            u.b = B;
            let _a = u.a; // OK
        }
    }
}
@davidtwco davidtwco self-assigned this Nov 3, 2018
@davidtwco davidtwco added A-NLL Area: Non-lexical lifetimes (NLL) NLL-diagnostics Working towards the "diagnostic parity" goal NLL-sound Working towards the "invalid code does not compile" goal labels Nov 3, 2018
@davidtwco davidtwco changed the title NLL Diagnostic Review #3: Unions not reinitialized after assignment into field NLL Diagnostic Review 3: Unions not reinitialized after assignment into field Nov 3, 2018
@pnkfelix
Copy link
Member

pnkfelix commented Nov 3, 2018

This should be NLL-complete, not NLL-sound, right?

@davidtwco davidtwco added NLL-complete Working towards the "valid code works" goal and removed NLL-sound Working towards the "invalid code does not compile" goal labels Nov 3, 2018
@davidtwco
Copy link
Member Author

@pnkfelix Yeah, it should. My bad.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 6, 2018

triage: P-high, not not Release milestone. This issue is bad enough for fix quickly, but there's no reason to beta-backport (as I explained on the PR itself here #55657 (comment) )

@pnkfelix pnkfelix added the P-high High priority label Nov 6, 2018
bors added a commit that referenced this issue Nov 11, 2018
NLL Diagnostic Review 3: Unions not reinitialized after assignment into field

Fixes #55651, #55652.

This PR makes two changes:

First, it updates the dataflow builder to add an init for the place
containing a union if there is an assignment into the field of
that union.

Second, it stops a "use of uninitialized" error occuring when there is an
assignment into the field of an uninitialized union that was previously
initialized. Making this assignment would re-initialize the union, as
tested in `src/test/ui/borrowck/borrowck-union-move-assign.nll.stderr`.
The check for previous initialization ensures that we do not start
supporting partial initialization yet (cc #21232, #54499, #54986).

This PR also fixes #55652 which was marked as requiring investigation
as the changes in this PR add an error that was previously missing
(and mentioned in the review comments) and confirms that the error
that was present is correct and a result of earlier partial
initialization changes in NLL.

r? @pnkfelix (due to earlier work with partial initialization)
cc @nikomatsakis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-complete Working towards the "valid code works" goal NLL-diagnostics Working towards the "diagnostic parity" goal P-high High priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants