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

Mention that you're not allowed to partially move Drop types #1902

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Mention that you're not allowed to partially move Drop types
  • Loading branch information
josephcsible committed Dec 16, 2024
commit d2f9fb15856db1a67b22547e5cc8cfcc4210d9ba
14 changes: 13 additions & 1 deletion src/scope/move/partial_move.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ this will result in a _partial move_ of the variable, which means
that parts of the variable will be moved while other parts stay. In
such a case, the parent variable cannot be used afterwards as a
whole, however the parts that are only referenced (and not moved)
can still be used.
can still be used. Note that types that implement the
[`Drop` trait][droptrait] cannot be partially moved from, because
its `drop` method would use it afterwards as a whole.


```rust,editable
fn main() {
Expand All @@ -16,6 +19,14 @@ fn main() {
age: Box<u8>,
}

// Error! cannot move out of a type which implements the `Drop` trait
//impl Drop for Person {
// fn drop(&mut self) {
// println!("Dropping the person struct {:?}", self)
// }
//}
// TODO ^ Try uncommenting these lines

let person = Person {
name: String::from("Alice"),
age: Box::new(20),
Expand Down Expand Up @@ -47,4 +58,5 @@ not be required as the definition of `age` would copy the data from

[destructuring][destructuring]

[droptrait]: ../../trait/drop.md
[destructuring]: ../../flow_control/match/destructuring.md
Loading