diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-11-13 18:01:19 +0100 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2019-11-14 13:05:56 +0100 |
| commit | 411f94c3b903abe548574c9de8e939a28cd86afc (patch) | |
| tree | 2dd6cb46629a3716aa731d2970082d4761b0f3ff /src/librustc_error_codes/error_codes | |
| parent | 356da40db5ad56ed9efbf6c2757422a9fd2fd3d2 (diff) | |
| download | rust-411f94c3b903abe548574c9de8e939a28cd86afc.tar.gz rust-411f94c3b903abe548574c9de8e939a28cd86afc.zip | |
move E0623 into the new error code format
Diffstat (limited to 'src/librustc_error_codes/error_codes')
| -rw-r--r-- | src/librustc_error_codes/error_codes/E0623.md | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/librustc_error_codes/error_codes/E0623.md b/src/librustc_error_codes/error_codes/E0623.md new file mode 100644 index 00000000000..1290edd0a0e --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0623.md @@ -0,0 +1,41 @@ +A lifetime didn't match what was expected. + +Erroneous code example: + +```compile_fail,E0623 +struct Foo<'a> { + x: &'a isize, +} + +fn bar<'short, 'long>(c: Foo<'short>, l: &'long isize) { + let _: Foo<'long> = c; // error! +} +``` + +In this example, we tried to set a value with an incompatible lifetime to +another one (`'long` is unrelated to `'short`). We can solve this issue in +two different ways: + +Either we make `'short` live at least as long as `'long`: + +``` +struct Foo<'a> { + x: &'a isize, +} + +// we set 'short to live at least as long as 'long +fn bar<'short: 'long, 'long>(c: Foo<'short>, l: &'long isize) { + let _: Foo<'long> = c; // ok! +} +``` + +Or we use only one lifetime: + +``` +struct Foo<'a> { + x: &'a isize, +} +fn bar<'short>(c: Foo<'short>, l: &'short isize) { + let _: Foo<'short> = c; // ok! +} +``` |
