-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 E0227 #92351
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
This error indicates that the compiler is unable to determine whether there is | ||
exactly one unique region in the set of derived region bounds. | ||
|
||
Example of erroneous code: | ||
|
||
```compile_fail,E0227 | ||
trait Foo<'foo>: 'foo {} | ||
trait Bar<'bar>: 'bar {} | ||
|
||
trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {} | ||
|
||
struct Baz<'foo, 'bar> { | ||
baz: dyn FooBar<'foo, 'bar>, | ||
} | ||
``` | ||
|
||
Here, `baz` can have either `'foo` or `'bar` lifetimes. | ||
|
||
To resolve this error, provide an explicit lifetime: | ||
|
||
```rust | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: You don't need to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's nice to have syntax highlighting in vim while editing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like I said, not a blocker. We generally don't add it but it's fine to have it here. |
||
trait Foo<'foo>: 'foo {} | ||
trait Bar<'bar>: 'bar {} | ||
|
||
trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {} | ||
|
||
struct Baz<'foo, 'bar, 'baz> | ||
where | ||
'baz: 'foo + 'bar, | ||
{ | ||
obj: dyn FooBar<'foo, 'bar> + 'baz, | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
trait Foo<'foo>: 'foo {} | ||
trait Bar<'bar>: 'bar {} | ||
|
||
trait FooBar<'foo, 'bar>: Foo<'foo> + Bar<'bar> {} | ||
|
||
struct Baz<'foo, 'bar> { | ||
baz: dyn FooBar<'foo, 'bar>, | ||
//~^ ERROR ambiguous lifetime bound, explicit lifetime bound required | ||
} | ||
|
||
fn main() { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
error[E0227]: ambiguous lifetime bound, explicit lifetime bound required | ||
--> $DIR/E0227.rs:7:10 | ||
| | ||
LL | baz: dyn FooBar<'foo, 'bar>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0227`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We try to provide a small description of the error first, and then provide more explanations after the erroneous code example. However in this case I'm not sure how to word it... If you have an idea, please go for it, otherwise I'll just approve as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the only reason why I haven't included a small description is because I can't think of one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it's fine. I'll approve the PR once the CI passed. Thanks for working on this!