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 E0227 #92351

Merged
merged 1 commit into from
Dec 29, 2021
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 compiler/rustc_error_codes/src/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"),
E0227: include_str!("./error_codes/E0227.md"),
E0228: include_str!("./error_codes/E0228.md"),
E0229: include_str!("./error_codes/E0229.md"),
E0230: include_str!("./error_codes/E0230.md"),
Expand Down Expand Up @@ -530,7 +531,6 @@ E0786: include_str!("./error_codes/E0786.md"),
// E0217, // ambiguous associated type, defined in multiple supertraits
// E0218, // no associated type defined
// E0219, // associated type defined in higher-ranked supertrait
E0227, // ambiguous lifetime bound, explicit lifetime bound required
// E0233,
// E0234,
// E0235, // structure constructor specifies a structure of type but
Expand Down
33 changes: 33 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0227.md
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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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!

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: You don't need to add rust, it's the default. It's not a blocker for the PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to have syntax highlighting in vim while editing .md files.

Copy link
Member

Choose a reason for hiding this comment

The 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,
}
```
12 changes: 12 additions & 0 deletions src/test/ui/error-codes/E0227.rs
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() {
}
9 changes: 9 additions & 0 deletions src/test/ui/error-codes/E0227.stderr
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`.
4 changes: 2 additions & 2 deletions src/tools/tidy/src/error_codes_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use regex::Regex;

// A few of those error codes can't be tested but all the others can and *should* be tested!
const EXEMPTED_FROM_TEST: &[&str] = &[
"E0227", "E0279", "E0280", "E0313", "E0377", "E0461", "E0462", "E0465", "E0476", "E0514",
"E0519", "E0523", "E0554", "E0640", "E0717", "E0729",
"E0279", "E0280", "E0313", "E0377", "E0461", "E0462", "E0465", "E0476", "E0514", "E0519",
"E0523", "E0554", "E0640", "E0717", "E0729",
];

// Some error codes don't have any tests apparently...
Expand Down