Skip to content

Commit b7c0e46

Browse files
Add long error explanation for E0623
1 parent e8b190a commit b7c0e46

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/librustc/error_codes.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,49 @@ fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
18961896
```
18971897
"##,
18981898

1899+
E0623: r##"
1900+
A lifetime didn't match what was expected.
1901+
1902+
Erroneous code example:
1903+
1904+
```compile_fail,E0623
1905+
struct Foo<'a> {
1906+
x: &'a isize,
1907+
}
1908+
1909+
fn bar<'short, 'long>(c: Foo<'short>, l: &'long isize) {
1910+
let _: Foo<'long> = c; // error!
1911+
}
1912+
```
1913+
1914+
In this example, we tried to set a value with an incompatible lifetime to
1915+
another one (`'long` != `'short`). We can solve this issue in two different
1916+
ways: either we make `'short` lives longer than `'long`:
1917+
1918+
```
1919+
struct Foo<'a> {
1920+
x: &'a isize,
1921+
}
1922+
1923+
// we set 'short to outlive 'long
1924+
fn bar<'short: 'long, 'long>(c: Foo<'short>, l: &'long isize) {
1925+
let _: Foo<'long> = c; // ok!
1926+
}
1927+
```
1928+
1929+
Or we use only one lifetime:
1930+
1931+
```
1932+
struct Foo<'a> {
1933+
x: &'a isize,
1934+
}
1935+
1936+
fn bar<'short>(c: Foo<'short>, l: &'short isize) {
1937+
let _: Foo<'short> = c; // ok!
1938+
}
1939+
```
1940+
"##,
1941+
18991942
E0635: r##"
19001943
The `#![feature]` attribute specified an unknown feature.
19011944
@@ -2329,7 +2372,6 @@ the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
23292372
E0488, // lifetime of variable does not enclose its declaration
23302373
E0489, // type/lifetime parameter not in scope here
23312374
E0490, // a value of type `..` is borrowed for too long
2332-
E0623, // lifetime mismatch where both parameters are anonymous regions
23332375
E0628, // generators cannot have explicit parameters
23342376
E0631, // type mismatch in closure arguments
23352377
E0637, // "'_" is not a valid lifetime bound

0 commit comments

Comments
 (0)