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
Closed

NLL: Reject partial init of uninitialized record (struct or tuple) #54986

pnkfelix opened this issue Oct 11, 2018 · 1 comment
Assignees
Labels
A-NLL Area: Non-lexical lifetimes (NLL) NLL-sound Working towards the "invalid code does not compile" goal

Comments

@pnkfelix
Copy link
Member

pnkfelix 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 Area: Non-lexical lifetimes (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 Working towards the "invalid code does not compile" goal label Oct 16, 2018
@pnkfelix
Copy link
Member Author

pnkfelix 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
…#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
… 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
…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
davidtwco added a commit to davidtwco/rust that referenced this issue Nov 3, 2018
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
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-sound Working towards the "invalid code does not compile" goal
Projects
None yet
Development

No branches or pull requests

1 participant