File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -265,7 +265,7 @@ enough into the place expecting something long-lived.
265
265
266
266
Here it is:
267
267
268
- ``` rust,ignore
268
+ ``` rust,compile_fail
269
269
fn evil_feeder<T>(input: &mut T, val: T) {
270
270
*input = val;
271
271
}
@@ -285,15 +285,16 @@ And what do we get when we run this?
285
285
286
286
``` text
287
287
error[E0597]: `spike` does not live long enough
288
- --> src/main.rs:9:32
288
+ --> src/main.rs:9:31
289
289
|
290
- 9 | let spike_str: &str = &spike;
291
- | ^^^^^ borrowed value does not live long enough
292
- 10 | evil_feeder(&mut mr_snuggles, spike_str);
290
+ 6 | let mut mr_snuggles: &'static str = "meow! :3"; // mr. snuggles forever!!
291
+ | ------------ type annotation requires that `spike` is borrowed for `'static`
292
+ ...
293
+ 9 | let spike_str: &str = &spike; // Only lives for the block
294
+ | ^^^^^^ borrowed value does not live long enough
295
+ 10 | evil_feeder(&mut mr_snuggles, spike_str); // EVIL!
293
296
11 | }
294
- | - borrowed value only lives until here
295
- |
296
- = note: borrowed value must be valid for the static lifetime...
297
+ | - `spike` dropped here while still borrowed
297
298
```
298
299
299
300
Good, it doesn't compile! Let's break down what's happening here in detail.
You can’t perform that action at this time.
0 commit comments