@@ -1347,6 +1347,39 @@ struct Foo<T: 'static> {
1347
1347
```
1348
1348
"## ,
1349
1349
1350
+ E0312 : r##"
1351
+ Reference's lifetime of borrowed content doesn't match the expected lifetime.
1352
+
1353
+ Erroneous code example:
1354
+
1355
+ ```compile_fail,E0312
1356
+ pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'static str {
1357
+ if maybestr.is_none() {
1358
+ "(none)"
1359
+ } else {
1360
+ let s: &'a str = maybestr.as_ref().unwrap();
1361
+ s // Invalid lifetime!
1362
+ }
1363
+ }
1364
+ ```
1365
+
1366
+ To fix this error, either lessen the expected lifetime or find a way to not have
1367
+ to use this reference outside of its current scope (by running the code directly
1368
+ in the same block for example?):
1369
+
1370
+ ```
1371
+ // In this case, we can fix the issue by switching from "static" lifetime to 'a
1372
+ pub fn opt_str<'a>(maybestr: &'a Option<String>) -> &'a str {
1373
+ if maybestr.is_none() {
1374
+ "(none)"
1375
+ } else {
1376
+ let s: &'a str = maybestr.as_ref().unwrap();
1377
+ s // Ok!
1378
+ }
1379
+ }
1380
+ ```
1381
+ "## ,
1382
+
1350
1383
E0317 : r##"
1351
1384
This error occurs when an `if` expression without an `else` block is used in a
1352
1385
context where a type other than `()` is expected, for example a `let`
@@ -2202,7 +2235,6 @@ static X: u32 = 42;
2202
2235
// E0304, // expected signed integer constant
2203
2236
// E0305, // expected constant
2204
2237
E0311 , // thing may not live long enough
2205
- E0312 , // lifetime of reference outlives lifetime of borrowed content
2206
2238
E0313 , // lifetime of borrowed pointer outlives lifetime of captured
2207
2239
// variable
2208
2240
E0314 , // closure outlives stack frame
0 commit comments