Skip to content

Commit 86b5623

Browse files
committed
minor edits in response to feedback
1 parent b47f3c8 commit 86b5623

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/design_notes/eager_drop.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,21 @@ In other words, it's useful to have the _destructor_ occurring at a known time (
4141

4242
### Today's drop rules are, however, a source of confusion
4343

44-
The `let _guard = foo` pattern can be easily confused with `let _ = foo`. `let guard = foo; ...; drop(guard);` has the advantage of explicitness, so does something like `foo.with(|guard| ...)`
45-
46-
Temporary rules interact with `match` in ways that surprise people:
44+
The fact that `let _ = foo` drops `foo` immediately is a known source of confusion, along with the lifetimes of temporaries in `match` statements and the like:
4745

4846
```rust=
4947
match foo.lock().data.copy_out() {
5048
...
5149
} // lock released here!
5250
```
5351

54-
Temporary rules interact poorly with unsafe code today, e.g. `CString::new().as_ptr()` is a known footgun. Would this change help? Or perhaps just change the footguns around. (The change as _written_ would not help here, because the temporary would be dropped probably _even earlier_.)
52+
The `let _guard = foo` pattern is probably what prople want, but it's not necessarily obvious to readers when the destructor runs.
53+
54+
`let guard = foo; ...; drop(guard);` has the advantage of explicitness, so does something like `foo.with(|guard| ...)`
55+
56+
### Clarify for unsafe code can be quite important
57+
58+
There are known footguns today with the timing of destructors and unsafe code. For example, `CString::new().as_ptr()` is a common thing people try to do that does not work. Eager destructors would enable more motion, which might exacerbate the problem.
5559

5660
## Alternatives
5761

0 commit comments

Comments
 (0)