-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.F-bindings_after_at`#![feature(bindings_after_at)]``#![feature(bindings_after_at)]`T-langRelevant to the language teamRelevant to the language team
Description
The following code (playground link) attempts to move a struct while using a sub-binding to copy one of its fields:
#![feature(bindings_after_at)]
struct NonCopyStruct {
copy_field: u32,
}
fn foo(x: NonCopyStruct) {
let y @ NonCopyStruct { copy_field: z } = x;
}
On nightly, it produces two errors:
error[E0007]: cannot bind by-move with sub-bindings
--> src/lib.rs:8:9
|
8 | let y @ NonCopyStruct { copy_field: z } = x;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0382]: use of moved value: `x`
--> src/lib.rs:8:41
|
7 | fn foo(x: NonCopyStruct) {
| - move occurs because `x` has type `NonCopyStruct`, which does not implement the `Copy` trait
8 | let y @ NonCopyStruct { copy_field: z } = x;
| --------------------------------^--
| | |
| | value used here after move
However, it would be sound to allow this, since it's equivalent to copying the field before or after moving the struct.
(There are no errors if the struct does implement Copy
.)
Metadata
Metadata
Assignees
Labels
A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-borrow-checkerArea: The borrow checkerArea: The borrow checkerC-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.F-bindings_after_at`#![feature(bindings_after_at)]``#![feature(bindings_after_at)]`T-langRelevant to the language teamRelevant to the language team