We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5e2f37f commit f09e2ccCopy full SHA for f09e2cc
src/librustc/diagnostics.rs
@@ -1236,6 +1236,23 @@ struct Foo<'a, T: 'a> {
1236
foo: &'a T
1237
}
1238
```
1239
+
1240
+To see why this is important, consider the case where `T` is itself a reference
1241
+(e.g., `T = &str`). If we don't include the restriction that `T: 'a`, the
1242
+following code would be perfectly legal:
1243
1244
+```compile_fail,E0309
1245
+struct Foo<'a, T> {
1246
+ foo: &'a T
1247
+}
1248
1249
+fn main() {
1250
+ let v = "42".to_string();
1251
+ let f = Foo{foo: &v};
1252
+ drop(v);
1253
+ println!("{}", f.foo); // but we've already dropped v!
1254
1255
+```
1256
"##,
1257
1258
E0310: r##"
0 commit comments