Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add long error explanation for E0228 #72127

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/librustc_error_codes/error_codes/E0228.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
2 changes: 1 addition & 1 deletion src/test/ui/suggestions/missing-lifetime-specifier.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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`.