File tree 1 file changed +12
-18
lines changed
1 file changed +12
-18
lines changed Original file line number Diff line number Diff line change @@ -80,24 +80,18 @@ fn main() {
80
80
```
81
81
82
82
``` text
83
- <anon>:12:28: 12:32 error: `days` does not live long enough
84
- <anon>:12 inspector = Inspector(&days);
85
- ^~~~
86
- <anon>:9:11: 15:2 note: reference must be valid for the block at 9:10...
87
- <anon>:9 fn main() {
88
- <anon>:10 let (inspector, days);
89
- <anon>:11 days = Box::new(1);
90
- <anon>:12 inspector = Inspector(&days);
91
- <anon>:13 // Let's say `days` happens to get dropped first.
92
- <anon>:14 // Then when Inspector is dropped, it will try to read free'd memory!
93
- ...
94
- <anon>:10:27: 15:2 note: ...but borrowed value is only valid for the block suffix following statement 0 at 10:26
95
- <anon>:10 let (inspector, days);
96
- <anon>:11 days = Box::new(1);
97
- <anon>:12 inspector = Inspector(&days);
98
- <anon>:13 // Let's say `days` happens to get dropped first.
99
- <anon>:14 // Then when Inspector is dropped, it will try to read free'd memory!
100
- <anon>:15 }
83
+ error: `days` does not live long enough
84
+ --> <anon>:15:1
85
+ |
86
+ 12 | inspector = Inspector(&days);
87
+ | ---- borrow occurs here
88
+ ...
89
+ 15 | }
90
+ | ^ `days` dropped here while still borrowed
91
+ |
92
+ = note: values in a scope are dropped in the opposite order they are created
93
+
94
+ error: aborting due to previous error
101
95
```
102
96
103
97
Implementing Drop lets the Inspector execute some arbitrary code during its
You can’t perform that action at this time.
0 commit comments