|
|
@ -265,7 +265,7 @@ enough into the place expecting something long-lived.
|
|
|
|
|
|
|
|
|
|
|
|
Here it is:
|
|
|
|
Here it is:
|
|
|
|
|
|
|
|
|
|
|
|
```rust,ignore
|
|
|
|
```rust,compile_fail
|
|
|
|
fn evil_feeder<T>(input: &mut T, val: T) {
|
|
|
|
fn evil_feeder<T>(input: &mut T, val: T) {
|
|
|
|
*input = val;
|
|
|
|
*input = val;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -285,15 +285,16 @@ And what do we get when we run this?
|
|
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
```text
|
|
|
|
error[E0597]: `spike` does not live long enough
|
|
|
|
error[E0597]: `spike` does not live long enough
|
|
|
|
--> src/main.rs:9:32
|
|
|
|
--> src/main.rs:9:31
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 | let spike_str: &str = &spike;
|
|
|
|
6 | let mut mr_snuggles: &'static str = "meow! :3"; // mr. snuggles forever!!
|
|
|
|
| ^^^^^ borrowed value does not live long enough
|
|
|
|
| ------------ type annotation requires that `spike` is borrowed for `'static`
|
|
|
|
10 | evil_feeder(&mut mr_snuggles, spike_str);
|
|
|
|
...
|
|
|
|
|
|
|
|
9 | let spike_str: &str = &spike; // Only lives for the block
|
|
|
|
|
|
|
|
| ^^^^^^ borrowed value does not live long enough
|
|
|
|
|
|
|
|
10 | evil_feeder(&mut mr_snuggles, spike_str); // EVIL!
|
|
|
|
11 | }
|
|
|
|
11 | }
|
|
|
|
| - borrowed value only lives until here
|
|
|
|
| - `spike` dropped here while still borrowed
|
|
|
|
|
|
|
|
|
|
|
|
|
= note: borrowed value must be valid for the static lifetime...
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
Good, it doesn't compile! Let's break down what's happening here in detail.
|
|
|
|
Good, it doesn't compile! Let's break down what's happening here in detail.
|
|
|
|