Skip to content

Commit

Permalink
Expand E0309 explanation with motivating example
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhoo committed Dec 12, 2016
1 parent 5e2f37f commit f09e2cc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,23 @@ struct Foo<'a, T: 'a> {
foo: &'a T
}
```
To see why this is important, consider the case where `T` is itself a reference
(e.g., `T = &str`). If we don't include the restriction that `T: 'a`, the
following code would be perfectly legal:
```compile_fail,E0309
struct Foo<'a, T> {
foo: &'a T
}
fn main() {
let v = "42".to_string();
let f = Foo{foo: &v};
drop(v);
println!("{}", f.foo); // but we've already dropped v!
}
```
"##,

E0310: r##"
Expand Down

0 comments on commit f09e2cc

Please sign in to comment.