|
|
@ -80,24 +80,18 @@ fn main() {
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
```text
|
|
|
|
<anon>:12:28: 12:32 error: `days` does not live long enough
|
|
|
|
error: `days` does not live long enough
|
|
|
|
<anon>:12 inspector = Inspector(&days);
|
|
|
|
--> <anon>:15:1
|
|
|
|
^~~~
|
|
|
|
|
|
|
|
|
<anon>:9:11: 15:2 note: reference must be valid for the block at 9:10...
|
|
|
|
12 | inspector = Inspector(&days);
|
|
|
|
<anon>:9 fn main() {
|
|
|
|
| ---- borrow occurs here
|
|
|
|
<anon>:10 let (inspector, days);
|
|
|
|
...
|
|
|
|
<anon>:11 days = Box::new(1);
|
|
|
|
15 | }
|
|
|
|
<anon>:12 inspector = Inspector(&days);
|
|
|
|
| ^ `days` dropped here while still borrowed
|
|
|
|
<anon>:13 // Let's say `days` happens to get dropped first.
|
|
|
|
|
|
|
|
|
<anon>:14 // Then when Inspector is dropped, it will try to read free'd memory!
|
|
|
|
= note: values in a scope are dropped in the opposite order they are created
|
|
|
|
...
|
|
|
|
|
|
|
|
<anon>:10:27: 15:2 note: ...but borrowed value is only valid for the block suffix following statement 0 at 10:26
|
|
|
|
error: aborting due to previous error
|
|
|
|
<anon>:10 let (inspector, days);
|
|
|
|
|
|
|
|
<anon>:11 days = Box::new(1);
|
|
|
|
|
|
|
|
<anon>:12 inspector = Inspector(&days);
|
|
|
|
|
|
|
|
<anon>:13 // Let's say `days` happens to get dropped first.
|
|
|
|
|
|
|
|
<anon>:14 // Then when Inspector is dropped, it will try to read free'd memory!
|
|
|
|
|
|
|
|
<anon>:15 }
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Implementing Drop lets the Inspector execute some arbitrary code during its
|
|
|
|
Implementing Drop lets the Inspector execute some arbitrary code during its
|
|
|
|