@@ -1351,74 +1351,6 @@ struct Foo<T: 'static> {
1351
1351
```
1352
1352
"## ,
1353
1353
1354
- E0312 : r##"
1355
- A lifetime of reference outlives lifetime of borrowed content.
1356
-
1357
- Erroneous code example:
1358
-
1359
- ```compile_fail,E0312
1360
- fn make_child<'tree, 'human>(
1361
- x: &'human i32,
1362
- y: &'tree i32
1363
- ) -> &'human i32 {
1364
- if x > y
1365
- { x }
1366
- else
1367
- { y }
1368
- // error: lifetime of reference outlives lifetime of borrowed content
1369
- }
1370
- ```
1371
-
1372
- The function declares that it returns a reference with the `'human`
1373
- lifetime, but it may return data with the `'tree` lifetime. As neither
1374
- lifetime is declared longer than the other, this results in an
1375
- error. Sometimes, this error is because the function *body* is
1376
- incorrect -- that is, maybe you did not *mean* to return data from
1377
- `y`. In that case, you should fix the function body.
1378
-
1379
- Often, however, the body is correct. In that case, the function
1380
- signature needs to be altered to match the body, so that the caller
1381
- understands that data from either `x` or `y` may be returned. The
1382
- simplest way to do this is to give both function parameters the *same*
1383
- named lifetime:
1384
-
1385
- ```
1386
- fn make_child<'human>(
1387
- x: &'human i32,
1388
- y: &'human i32
1389
- ) -> &'human i32 {
1390
- if x > y
1391
- { x }
1392
- else
1393
- { y } // ok!
1394
- }
1395
- ```
1396
-
1397
- However, in some cases, you may prefer to explicitly declare that one lifetime
1398
- outlives another using a `where` clause:
1399
-
1400
- ```
1401
- fn make_child<'tree, 'human>(
1402
- x: &'human i32,
1403
- y: &'tree i32
1404
- ) -> &'human i32
1405
- where
1406
- 'tree: 'human
1407
- {
1408
- if x > y
1409
- { x }
1410
- else
1411
- { y } // ok!
1412
- }
1413
- ```
1414
-
1415
- Here, the where clause `'tree: 'human` can be read as "the lifetime
1416
- 'tree outlives the lifetime 'human" -- meaning, references with the
1417
- `'tree` lifetime live *at least as long as* references with the
1418
- `'human` lifetime. Therefore, it is safe to return data with lifetime
1419
- `'tree` when data with the lifetime `'human` is needed.
1420
- "## ,
1421
-
1422
1354
E0317 : r##"
1423
1355
This error occurs when an `if` expression without an `else` block is used in a
1424
1356
context where a type other than `()` is expected, for example a `let`
@@ -2028,6 +1960,7 @@ register_diagnostics! {
2028
1960
// E0304, // expected signed integer constant
2029
1961
// E0305, // expected constant
2030
1962
E0311 , // thing may not live long enough
1963
+ E0312 , // lifetime of reference outlives lifetime of borrowed content
2031
1964
E0313 , // lifetime of borrowed pointer outlives lifetime of captured variable
2032
1965
E0314 , // closure outlives stack frame
2033
1966
E0315 , // cannot invoke closure outside of its lifetime
0 commit comments