Skip to content

Add long error code explanation message for E0637 #68908

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

Merged
merged 15 commits into from
Feb 11, 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 @@ -353,6 +353,7 @@ E0631: include_str!("./error_codes/E0631.md"),
E0633: include_str!("./error_codes/E0633.md"),
E0635: include_str!("./error_codes/E0635.md"),
E0636: include_str!("./error_codes/E0636.md"),
E0637: include_str!("./error_codes/E0637.md"),
E0638: include_str!("./error_codes/E0638.md"),
E0639: include_str!("./error_codes/E0639.md"),
E0641: include_str!("./error_codes/E0641.md"),
Expand Down Expand Up @@ -584,7 +585,6 @@ E0746: include_str!("./error_codes/E0746.md"),
E0632, // cannot provide explicit generic arguments when `impl Trait` is
// used in argument position
E0634, // type has conflicting packed representaton hints
E0637, // "'_" is not a valid lifetime bound
E0640, // infer outlives requirements
// E0645, // trait aliases not finished
E0657, // `impl Trait` can only capture lifetimes bound at the fn level
Expand Down
32 changes: 32 additions & 0 deletions src/librustc_error_codes/error_codes/E0637.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
An underscore `_` character has been used as the identifier for a lifetime.

Erroneous example:
```compile_fail,E0106,E0637
fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
//^^ `'_` is a reserved lifetime name
if str1.len() > str2.len() {
str1
} else {
str2
}
}
```
`'_`, cannot be used as a lifetime identifier because it is a reserved for the
anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series
of lowercase letters such as `'foo`. For more information, see [the
book][bk-no]. For more information on using the anonymous lifetime in rust
nightly, see [the nightly book][bk-al].

Corrected example:
```
fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str {
if str1.len() > str2.len() {
str1
} else {
str2
}
}
```

[bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols
[bk-al]: https://doc.rust-lang.org/nightly/edition-guide/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ LL | #![feature(const_generics)]

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0637`.
1 change: 1 addition & 0 deletions src/test/ui/error-codes/E0637.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LL | impl<'a: '_> Bar<'a> {

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0106`.
Some errors have detailed explanations: E0106, E0637.
For more information about an error, try `rustc --explain E0106`.
1 change: 1 addition & 0 deletions src/test/ui/underscore-lifetime/in-binder.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ LL | fn foo<'_>() {

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ LL | fn foo2<'a>(_: &'a u8, y: &'a u8) -> &'a u8 { y }

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0106`.
Some errors have detailed explanations: E0106, E0637.
For more information about an error, try `rustc --explain E0106`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | impl<'b: '_> Foo<'b> for i32 {}

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | T: WithType<&u32>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | T: WithType<&u32>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | T: WithRegion<'_>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | T: WithRegion<'_>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | T: WithType<&u32>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | T: WithType<&u32>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | T: WithRegion<'_>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | T: WithRegion<'_>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0637`.
1 change: 1 addition & 0 deletions src/test/ui/underscore-lifetime/where-clauses.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ LL | impl<T: '_> Foo<'static> for Vec<T> {}

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0637`.