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: Reject partial init of uninitialized record (struct or tuple) #54986

Closed
pnkfelix opened this issue Oct 11, 2018 · 1 comment

Comments

Projects
None yet
1 participant
@pnkfelix
Copy link
Member

commented Oct 11, 2018

Spawned off of #21232

In the short term, we want to reject code like this:

struct S { x: u32, y: u32 }
fn main() { let mut s: S; s.x = 10; }

See #54987 for the long-term goal.

@pnkfelix pnkfelix changed the title Reject partial init of uninitialized record (struct or tuple) NLL: Reject partial init of uninitialized record (struct or tuple) Oct 11, 2018

@pnkfelix pnkfelix added the A-NLL label Oct 11, 2018

@pnkfelix pnkfelix self-assigned this Oct 16, 2018

@pnkfelix pnkfelix added this to the Edition 2018 RC 2 milestone Oct 16, 2018

@pnkfelix pnkfelix added the NLL-sound label Oct 16, 2018

@pnkfelix

This comment has been minimized.

Copy link
Member Author

commented Oct 16, 2018

The PR #54941 should address this. (Its still marked WIP but that should change soon.)

pnkfelix added a commit to pnkfelix/rust that referenced this issue Oct 16, 2018

Make us error consistently in issue rust-lang#21232, to fix rust-lang…
…#54986.

Treat attempt to partially intialize local `l` as uses of a `mut` in `let mut l;`, to fix rust-lang#54499.

pnkfelix added a commit to pnkfelix/rust that referenced this issue Oct 16, 2018

Don't complain re missing `mut` on attempt to partially initialize an…
… uninitialized struct.

Under the semantics of rust-lang#54986 (our short term plan), the partial
initialization itself will signal an error. We don't need to add noise
to the output by also complaining about `mut`. (In particular, the
user may well revise their code in a way that does not require `mut`.)

pnkfelix added a commit to pnkfelix/rust that referenced this issue Oct 16, 2018

bors added a commit that referenced this issue Oct 17, 2018

Auto merge of #54941 - pnkfelix:issue-21232-reject-partial-reinit, r=…
…nikomatsakis

reject partial init and reinit of uninitialized data

Reject partial initialization of uninitialized structured types (i.e. structs and tuples) and also reject partial *reinitialization* of such types.

Fix #54986

Fix #54499

cc #21232

@bors bors closed this in #54941 Oct 17, 2018

davidtwco added a commit to davidtwco/rust that referenced this issue Nov 3, 2018

Unions reinitialized after assignment into field.
This commit 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 rust-lang#21232, rust-lang#54499, rust-lang#54986).

bors added a commit that referenced this issue Nov 11, 2018

Auto merge of #55657 - davidtwco:issue-55651, r=pnkfelix
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

bors added a commit that referenced this issue Nov 11, 2018

Auto merge of #55657 - davidtwco:issue-55651, r=pnkfelix
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
You can’t perform that action at this time.