Skip to content

Commit 4bbb58d

Browse files
gaurikholkarnikomatsakis
authored andcommitted
remove error code description
1 parent 9e4649e commit 4bbb58d

File tree

1 file changed

+1
-68
lines changed

1 file changed

+1
-68
lines changed

src/librustc/diagnostics.rs

+1-68
Original file line numberDiff line numberDiff line change
@@ -1351,74 +1351,6 @@ struct Foo<T: 'static> {
13511351
```
13521352
"##,
13531353

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-
14221354
E0317: r##"
14231355
This error occurs when an `if` expression without an `else` block is used in a
14241356
context where a type other than `()` is expected, for example a `let`
@@ -2028,6 +1960,7 @@ register_diagnostics! {
20281960
// E0304, // expected signed integer constant
20291961
// E0305, // expected constant
20301962
E0311, // thing may not live long enough
1963+
E0312, // lifetime of reference outlives lifetime of borrowed content
20311964
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
20321965
E0314, // closure outlives stack frame
20331966
E0315, // cannot invoke closure outside of its lifetime

0 commit comments

Comments
 (0)