Skip to content

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

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

Closed

Conversation

pnkfelix
Copy link
Member

@pnkfelix pnkfelix commented Feb 4, 2015

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.

  • (I am not particularly thrilled with how I implemented the code that distinguishes these two cases in borrowck::gather_loans::gather_moves, and welcome suggestions on ways to do it without accessing the ast_map, but preferably also without changing the expr_use_visitor API.)

This addresses RFC PR 533: rust-lang/rfcs#533 (which is not yet merged).

[breaking-change]

Now this is no longer legal: `fn foo(arr: [D; 5]) -> D { arr[2] }`,
unless `D` implements `Copy`.

This "move out-from" restriction only applies to `expr[i]`, and not
destructuring bind (e.g. `f([a, b, c]: Array) { ... }`).

See discussion on RFC PR 533.

[breaking-change]
…[i]`.

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 individual elements.

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).
@rust-highfive
Copy link
Contributor

r? @nikomatsakis

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

@pnkfelix
Copy link
Member Author

pnkfelix commented Feb 4, 2015

(closing for now; I will attempt to try a mem_categorization based approach as @nikomatsakis suggests.)

@pnkfelix pnkfelix closed this Feb 4, 2015
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]
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.

3 participants