add long error explanation for E0228
This commit is contained in:
parent
99cb9ccb9c
commit
5320bd986b
@ -120,6 +120,7 @@ E0223: include_str!("./error_codes/E0223.md"),
|
||||
E0224: include_str!("./error_codes/E0224.md"),
|
||||
E0225: include_str!("./error_codes/E0225.md"),
|
||||
E0226: include_str!("./error_codes/E0226.md"),
|
||||
E0228: include_str!("./error_codes/E0228.md"),
|
||||
E0229: include_str!("./error_codes/E0229.md"),
|
||||
E0230: include_str!("./error_codes/E0230.md"),
|
||||
E0231: include_str!("./error_codes/E0231.md"),
|
||||
@ -482,7 +483,6 @@ E0753: include_str!("./error_codes/E0753.md"),
|
||||
// E0218, // no associated type defined
|
||||
// E0219, // associated type defined in higher-ranked supertrait
|
||||
E0227, // ambiguous lifetime bound, explicit lifetime bound required
|
||||
E0228, // explicit lifetime bound required
|
||||
// E0233,
|
||||
// E0234,
|
||||
// E0235, // structure constructor specifies a structure of type but
|
||||
|
40
src/librustc_error_codes/error_codes/E0228.md
Normal file
40
src/librustc_error_codes/error_codes/E0228.md
Normal file
@ -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
|
@ -18,3 +18,4 @@ LL | fn f(t: &Ref2<dyn Test>) {
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0228`.
|
||||
|
@ -6,3 +6,4 @@ LL | fn bar<'a>(x: &'a str) -> &'a dyn Foo<'a, Item = dyn Bar> { &() }
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0228`.
|
||||
|
@ -6,3 +6,4 @@ LL | fn bar<'a>(x: &'a str) -> &'a dyn Foo<'a, Item = dyn Bar> { &() }
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0228`.
|
||||
|
@ -6,3 +6,4 @@ LL | fn bar(x: &str) -> &dyn Foo<Item = dyn Bar> { &() }
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0228`.
|
||||
|
@ -252,5 +252,5 @@ LL | static f: RefCell<HashMap<i32, Vec<Vec<&Tar<'static, i32>>>>> = RefCell
|
||||
|
||||
error: aborting due to 28 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0106, E0107.
|
||||
Some errors have detailed explanations: E0106, E0107, E0228.
|
||||
For more information about an error, try `rustc --explain E0106`.
|
||||
|
@ -18,4 +18,5 @@ LL | x: Box<dyn Debug + '_>,
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0106`.
|
||||
Some errors have detailed explanations: E0106, E0228.
|
||||
For more information about an error, try `rustc --explain E0106`.
|
||||
|
Loading…
Reference in New Issue
Block a user