Skip to content

Commit 0fd7306

Browse files
authored
Lifetimes: explain how to fix destructor example
1 parent 37b6170 commit 0fd7306

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/lifetimes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ data.push(4);
261261
// Here, the destructor is run and therefore this'll fail to compile.
262262
```
263263

264+
One way to convince the compiler that `x` is no longer valid is by using `drop(x)` before `data.push(4)`.
265+
264266
Furthermore, there might be multiple possible last uses of the borrow, for
265267
example in each branch of a condition.
266268

0 commit comments

Comments
 (0)