Skip to content

Commit bcfb3b5

Browse files
committed
Mark on example compile_fail
1 parent 5d7bec0 commit bcfb3b5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/subtyping.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ enough into the place expecting something long-lived.
265265

266266
Here it is:
267267

268-
```rust,ignore
268+
```rust,compile_fail
269269
fn evil_feeder<T>(input: &mut T, val: T) {
270270
*input = val;
271271
}
@@ -285,15 +285,16 @@ And what do we get when we run this?
285285

286286
```text
287287
error[E0597]: `spike` does not live long enough
288-
--> src/main.rs:9:32
288+
--> src/main.rs:9:31
289289
|
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!
293296
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
297298
```
298299

299300
Good, it doesn't compile! Let's break down what's happening here in detail.

0 commit comments

Comments
 (0)