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

cannot move into irrefutable slice patterns with multiple elements #26736

Closed
oli-obk opened this issue Jul 2, 2015 · 6 comments · Fixed by #59114
Closed

cannot move into irrefutable slice patterns with multiple elements #26736

oli-obk opened this issue Jul 2, 2015 · 6 comments · Fixed by #59114
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. NLL-fixed-by-NLL Bugs fixed, but only when NLL is enabled.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Jul 2, 2015

let arr = [Box::new(1), Box::new(2), Box::new(3)];
let [a, b, c] = arr;

fails with

<anon>:5:13: 5:14 error: use of moved value: `arr[..]` [E0382]
<anon>:5     let [a, b, c] = arr;
                     ^
<anon>:5:10: 5:11 note: `arr[..]` moved here because it has type `Box<i32>`, which is moved by default
<anon>:5     let [a, b, c] = arr;
                  ^
<anon>:5:10: 5:11 help: use `ref` to override

while the following work fine:

let arr = [Box::new(1)];
let [a] = arr;
enum Dummy<T> {
    Val([T; 2]),
}
let arr = [Box::new(1), Box::new(2)];
let Dummy::Val([a, b]) = Dummy::Val(arr);
@arielb1
Copy link
Contributor

arielb1 commented Jul 2, 2015

Slice patterns are broken.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 2, 2015

yes they are, is there any consensus on whether to report bugs and fix it or simply rewrite it from scratch?

@steveklabnik
Copy link
Member

Triage; no change on slice patterns

@mikhail-m1
Copy link
Contributor

works with -Z borrowck=mir, hope it will be soon by default

@ZoeyR
Copy link

ZoeyR commented May 11, 2018

This is still happening on stable as of the 1.26 release. This may cause confusion for people trying to use slice patterns since the release notes show an example of them. The only way the release notes get away with it is because they use numbers which are Copy.

@andersk
Copy link
Contributor

andersk commented Jul 17, 2018

These work fine as parameter patterns, so here’s an annoying but functional workaround while we’re waiting for MIR borrowck:

let arr = [Box::new(1), Box::new(2), Box::new(3)];
let (a, b, c) = (|[a, b, c]: [Box<i32>; 3]| (a, b, c))(arr);

@Mark-Simulacrum Mark-Simulacrum added the NLL-fixed-by-NLL Bugs fixed, but only when NLL is enabled. label Jul 29, 2018
bors added a commit that referenced this issue Mar 11, 2019
Enable NLL migrate mode on the 2015 edition

Blocked on #58739

## What is in this PR?

* Remove the `-Zborrowck=ast` flag option from rustc.
* The default in the 2015 edition is now `-Zborrowck=migrate`.
* The 2018 edition default is unchanged: it's still `-Zborrowck=migrate`.
* Enable the `-Ztwo-phase-borrows` flag on all editions.
* Remove most dead code that handled these options.
* Update tests for the above changes.

## What is *not* in this PR?

These are left for future PRs

* Use `-Zborrowck=mir` in NLL compare mode tests
* Remove the `-Zborrowck=compare` option
* Remove the `-Ztwo-phase-borrows` flag. It's kept so that perf.rlo has time to stop using it (cc @Mark-Simulacrum)
* Remove MIR typeck as its own MIR pass - it's now run by NLL.
* Enabling `-Zborrowck=mir` by default

Soundness issues that are fixed by NLL will stay open until full NLL is emitting hard errors. However, these diagnostics and completeness issues can now be closed:

Closes #18330
Closes #22323
Closes #23591
Closes #26736
Closes #27487
Closes #28092
Closes #28970
Closes #29733
Closes #30104
Closes #38915
Closes #39908
Closes #43407
Closes #47524
Closes #48540
Closes #49073
Closes #52614
Closes #55085
Closes #56093
Closes #56496
Closes #57804

cc #43234

r? @pnkfelix
cc @rust-lang/lang
cc @rust-lang/wg-compiler-nll
bors added a commit that referenced this issue Apr 22, 2019
Enable NLL migrate mode on the 2015 edition

## What is in this PR?

* Remove the `-Zborrowck=ast` flag option from rustc.
* The default in the 2015 edition is now `-Zborrowck=migrate`.
* The 2018 edition default is unchanged: it's still `-Zborrowck=migrate`.
* Enable two-phase borrows (currently toggled via the `-Ztwo-phase-borrows` flag) on all editions.
* Remove most dead code that handled these options.
* Update tests for the above changes.

## What is *not* in this PR?

These are left for future PRs

* Use `-Zborrowck=mir` in NLL compare mode tests (#56993)
* Remove the `-Zborrowck=compare` option (#59193)
* Remove the `-Ztwo-phase-borrows` flag. It's kept, as a flag that does nothing so that perf.rlo has time to stop using it (cc @Mark-Simulacrum)
* Remove MIR typeck as its own MIR pass - it's now run by NLL.
* Enabling `-Zborrowck=mir` by default (#58781)
* Replace `allow_bind_by_move_patterns_with_guards` and `check_for_mutation_in_guard_via_ast_walk` with just using the feature gate. (#59192)

Soundness issues that are fixed by NLL will stay open until full NLL is emitting hard errors. However, these diagnostics and completeness issues can now be closed:

Closes #18330
Closes #22323
Closes #23591
Closes #26736
Closes #27487
Closes #28092
Closes #28970
Closes #29733
Closes #30104
Closes #38915
Closes #39908
Closes #43407
Closes #47524
Closes #48540
Closes #49073
Closes #52614
Closes #55085
Closes #56093
Closes #56496
Closes #57804

cc #43234

r? @pnkfelix
cc @rust-lang/lang
cc @rust-lang/wg-compiler-nll
bors added a commit that referenced this issue Apr 22, 2019
Enable NLL migrate mode on the 2015 edition

## What is in this PR?

* Remove the `-Zborrowck=ast` flag option from rustc.
* The default in the 2015 edition is now `-Zborrowck=migrate`.
* The 2018 edition default is unchanged: it's still `-Zborrowck=migrate`.
* Enable two-phase borrows (currently toggled via the `-Ztwo-phase-borrows` flag) on all editions.
* Remove most dead code that handled these options.
* Update tests for the above changes.

## What is *not* in this PR?

These are left for future PRs

* Use `-Zborrowck=mir` in NLL compare mode tests (#56993)
* Remove the `-Zborrowck=compare` option (#59193)
* Remove the `-Ztwo-phase-borrows` flag. It's kept, as a flag that does nothing so that perf.rlo has time to stop using it (cc @Mark-Simulacrum)
* Remove MIR typeck as its own MIR pass - it's now run by NLL.
* Enabling `-Zborrowck=mir` by default (#58781)
* Replace `allow_bind_by_move_patterns_with_guards` and `check_for_mutation_in_guard_via_ast_walk` with just using the feature gate. (#59192)

Soundness issues that are fixed by NLL will stay open until full NLL is emitting hard errors. However, these diagnostics and completeness issues can now be closed:

Closes #18330
Closes #22323
Closes #23591
Closes #26736
Closes #27487
Closes #28092
Closes #28970
Closes #29733
Closes #30104
Closes #38915
Closes #39908
Closes #43407
Closes #47524
Closes #48540
Closes #49073
Closes #52614
Closes #55085
Closes #56093
Closes #56496
Closes #57804

cc #43234

r? @pnkfelix
cc @rust-lang/lang
cc @rust-lang/wg-compiler-nll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-borrow-checker Area: The borrow checker C-bug Category: This is a bug. NLL-fixed-by-NLL Bugs fixed, but only when NLL is enabled.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
@andersk @steveklabnik @oli-obk @arielb1 @Mark-Simulacrum @mikhail-m1 @ZoeyR and others