Skip to content

Restrictions on moves into and out-from fixed-length arrays. #21971

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

Merged
merged 5 commits into from
Feb 7, 2015

Conversation

pnkfelix
Copy link
Member

@pnkfelix pnkfelix commented Feb 5, 2015

Revised version of PR #21930.

Restrictions on moves into and out-from fixed-length arrays.

(There was only one use of this "feature" in the compiler source.)

Note 1: the change to the error message in tests/compile-fail/borrowck-use-in-index-lvalue.rs, where we now report that *w is uninitialized (rather than w), was unintended fallout from the implementation strategy used here. The change appears harmless to me, but I welcome advice on how to bring back the old message, which was slightly cleaner (i.e. less unintelligible) since that the syntactic form *w does not actually appear in the source text.

Note 2: the move out-from restriction to only apply to expr[i], and not destructuring bind (e.g. f([a, b, c]: Array) { ... }) since the latter is compatible with nonzeroing drop, AFAICT.

[breaking-change]

@rust-highfive
Copy link
Contributor

r? @pcwalton

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

r? @nikomatsakis

@nikomatsakis
Copy link
Contributor

@pnkfelix r+ modulo nits.

@pnkfelix pnkfelix force-pushed the fsk-restrict-fixdsz-array-moves branch from 31c7fff to 0e60c27 Compare February 5, 2015 22:03
@pnkfelix
Copy link
Member Author

pnkfelix commented Feb 6, 2015

@bors r=nikomatsakis 0e60c27

@bors
Copy link
Collaborator

bors commented Feb 7, 2015

⌛ Testing commit 0e60c27 with merge d347b18...

@bors
Copy link
Collaborator

bors commented Feb 7, 2015

💔 Test failed - auto-win-32-nopt-t

No longer legal: `fn foo(a: [D; 5]) { drop(a); a[2] = D::new(); }`;
one must first initialize the entirety of `a` before assigning to its
individual elements.

No longer legal: `fn foo(arr: [D; 5]) -> D { arr[2] }`, unless `D`
implements `Copy`. This "move out-from" restriction only affects
`expr[i]`, and not destructuring (e.g. `f([a, b, c]: Array) { ... }`).

uses mem_categorization to distinguish destructuring-bind from array
indexing.

See discussion on RFC PR 533.

[breaking-change]
Note that the change to the error message in
borrowck-use-in-index-lvalue.rs, where we report that `*w` is
uninitialized rather than `w`, was unintended fallout from the
implementation strategy used here.

The change appears harmless to me, but I welcome advice on how to
bring back the old message, which was slightly cleaner (i.e. less
unintelligible).

----

drive-by: revise compile-fail/borrowck-vec-pattern-move-tail to make
it really clear that there is a conflict that must be signaled.

(A hypothetical future version of Rust might be able to accept the
prior version of the code, since the previously updated index was not
actually aliased.)
@pnkfelix pnkfelix force-pushed the fsk-restrict-fixdsz-array-moves branch from 0e60c27 to 4583272 Compare February 7, 2015 12:44
@pnkfelix
Copy link
Member Author

pnkfelix commented Feb 7, 2015

@bors r=nikomatsakis 4583272

@bors
Copy link
Collaborator

bors commented Feb 7, 2015

⌛ Testing commit 4583272 with merge 8661b3d...

bors added a commit that referenced this pull request Feb 7, 2015
…komatsakis

Revised version of PR #21930.

Restrictions on moves into and out-from fixed-length arrays.

(There was only one use of this "feature" in the compiler source.)

Note 1: the change to the error message in tests/compile-fail/borrowck-use-in-index-lvalue.rs, where we now report that *w is uninitialized (rather than w), was unintended fallout from the implementation strategy used here. The change appears harmless to me, but I welcome advice on how to bring back the old message, which was slightly cleaner (i.e. less unintelligible) since that the syntactic form *w does not actually appear in the source text.

Note 2: the move out-from restriction to only apply to expr[i], and not destructuring bind (e.g. f([a, b, c]: Array) { ... }) since the latter is compatible with nonzeroing drop, AFAICT.

[breaking-change]
@bors
Copy link
Collaborator

bors commented Feb 7, 2015

@bors bors merged commit 4583272 into rust-lang:master Feb 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants