Skip to content

Commit 0933975

Browse files
authoredDec 18, 2024
Merge pull request rust-lang#1902 from josephcsible/partial-move-drop
Mention that you're not allowed to partially move Drop types
2 parents 7640633 + d2f9fb1 commit 0933975

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed
 

‎src/scope/move/partial_move.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ this will result in a _partial move_ of the variable, which means
66
that parts of the variable will be moved while other parts stay. In
77
such a case, the parent variable cannot be used afterwards as a
88
whole, however the parts that are only referenced (and not moved)
9-
can still be used.
9+
can still be used. Note that types that implement the
10+
[`Drop` trait][droptrait] cannot be partially moved from, because
11+
its `drop` method would use it afterwards as a whole.
12+
1013

1114
```rust,editable
1215
fn main() {
@@ -16,6 +19,14 @@ fn main() {
1619
age: Box<u8>,
1720
}
1821
22+
// Error! cannot move out of a type which implements the `Drop` trait
23+
//impl Drop for Person {
24+
// fn drop(&mut self) {
25+
// println!("Dropping the person struct {:?}", self)
26+
// }
27+
//}
28+
// TODO ^ Try uncommenting these lines
29+
1930
let person = Person {
2031
name: String::from("Alice"),
2132
age: Box::new(20),
@@ -47,4 +58,5 @@ not be required as the definition of `age` would copy the data from
4758

4859
[destructuring][destructuring]
4960

61+
[droptrait]: ../../trait/drop.md
5062
[destructuring]: ../../flow_control/match/destructuring.md

0 commit comments

Comments
 (0)