about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2020-05-14 18:21:51 +0200
committerGitHub <noreply@github.com>2020-05-14 18:21:51 +0200
commit746b8ca083395fbad72d2eb110157ae316e0d480 (patch)
tree073049fc4708641de3e934a37e2c998326770499 /src/librustc_error_codes/error_codes
parent96caa257c3c1cd597280b1c205ccca977268c5be (diff)
parent5320bd986b054d72522b29539278bfc5d576eabb (diff)
downloadrust-746b8ca083395fbad72d2eb110157ae316e0d480.tar.gz
rust-746b8ca083395fbad72d2eb110157ae316e0d480.zip
Rollup merge of #72127 - jademcgough:long-error-explanation-E0228, r=petrochenkov
add long error explanation for E0228

Add long explanation for the E0228 error code
Part of #61137

Let me know if this is wrong at all (or can be written more clearly), I'm still learning Rust.
Diffstat (limited to 'src/librustc_error_codes/error_codes')
-rw-r--r--src/librustc_error_codes/error_codes/E0228.md40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/librustc_error_codes/error_codes/E0228.md b/src/librustc_error_codes/error_codes/E0228.md
new file mode 100644
index 00000000000..3443a5ae863
--- /dev/null
+++ b/src/librustc_error_codes/error_codes/E0228.md
@@ -0,0 +1,40 @@
+The lifetime bound for this object type cannot be deduced from context and must
+be specified.
+
+Erroneous code example:
+
+```compile_fail,E0228
+trait Trait { }
+
+struct TwoBounds<'a, 'b, T: Sized + 'a + 'b> {
+    x: &'a i32,
+    y: &'b i32,
+    z: T,
+}
+
+type Foo<'a, 'b> = TwoBounds<'a, 'b, dyn Trait>;
+```
+
+When a trait object is used as a type argument of a generic type, Rust will try
+to infer its lifetime if unspecified. However, this isn't possible when the
+containing type has more than one lifetime bound.
+
+The above example can be resolved by either reducing the number of lifetime
+bounds to one or by making the trait object lifetime explicit, like so:
+
+```
+trait Trait { }
+
+struct TwoBounds<'a, 'b, T: Sized + 'a + 'b> {
+    x: &'a i32,
+    y: &'b i32,
+    z: T,
+}
+
+type Foo<'a, 'b> = TwoBounds<'a, 'b, dyn Trait + 'b>;
+```
+
+For more information, see [RFC 599] and its amendment [RFC 1156].
+
+[RFC 599]: https://github.com/rust-lang/rfcs/blob/master/text/0599-default-object-bound.md
+[RFC 1156]: https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md