]> git.lizzy.rs Git - rust.git/commitdiff
move E0623 into the new error code format
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 13 Nov 2019 17:01:19 +0000 (18:01 +0100)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Thu, 14 Nov 2019 12:05:56 +0000 (13:05 +0100)
src/librustc_error_codes/error_codes.rs
src/librustc_error_codes/error_codes/E0623.md [new file with mode: 0644]

index 23ea48d4b72ba57ec4259315814f84da5782e156..e8d5499ac58bd35d6223a419df9ac3d916c6a835 100644 (file)
 E0620: include_str!("./error_codes/E0620.md"),
 E0621: include_str!("./error_codes/E0621.md"),
 E0622: include_str!("./error_codes/E0622.md"),
+E0623: include_str!("./error_codes/E0623.md"),
 E0624: include_str!("./error_codes/E0624.md"),
 E0626: include_str!("./error_codes/E0626.md"),
 E0633: include_str!("./error_codes/E0633.md"),
 //  E0611, // merged into E0616
 //  E0612, // merged into E0609
 //  E0613, // Removed (merged with E0609)
-    E0623, // lifetime mismatch where both parameters are anonymous regions
     E0625, // thread-local statics cannot be accessed at compile-time
     E0627, // yield statement outside of generator literal
     E0628, // generators cannot have explicit parameters
diff --git a/src/librustc_error_codes/error_codes/E0623.md b/src/librustc_error_codes/error_codes/E0623.md
new file mode 100644 (file)
index 0000000..1290edd
--- /dev/null
@@ -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!
+}
+```