Skip to content

Commit

Permalink
Revised error long description
Browse files Browse the repository at this point in the history
  • Loading branch information
jwhite927 committed Feb 6, 2020
1 parent 4a1c6ce commit 201a262
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/librustc_error_codes/error_codes/E0637.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
The underscore `_` character has been used as the identifier for a lifetime.

An underscore `_` character or a numeric literal `u8`, `i32`, `f64`, etc has
been used as the identifier for a lifetime.

Erroneous code example:
```
fn some_function<'_>(x: &'_ str, y: &'_ str) -> &'_ str {
fn some_function<'_>(string1: &'_ str, string2: &'_ str) -> &'_ str {
//Some code
}
```
or Erroneous code example 2:
```
fn some_function<'u8>(string1: &'u8 str, string2: &'u8 str) -> &'u8 str {
//Some code
}
```

Lifetimes are named with 'ident, where ident is the name of the
lifetime or loop. The `_` character, which represents the ignore pattern,
cannot be used because it is a reserved lifetime name.
To fix this, use a single lowercase letter as the
lifetime identifier, such as `'a`. For more information, see [The Rust Book](https://doc.rust-lang.org/stable/book/appendix-02-operators.html#non-operator-symbols).
Lifetimes are named with `'ident`, where ident is the name of the lifetime or
loop. The `_` character, which represents the ignore pattern, cannot be used
as the identifier because it is a reserved lifetime name. Numeric literals are
also invalid lifetime identifiers and will cause this error to be thrown. To fix
this, use a series of lowercase letters as the lifetime identifier. Often a
single lowercase letter, such as `'a`, is sufficient. For more information, see
[the book][bk-no].

Corrected code example:
```
fn some_function<'a>(x: &'a str, y: &'a str) -> &'a str {
fn some_function<'a>(string1: &'a str, string2: &'a str) -> &'a str {
//Some code
}
```

[bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols

0 comments on commit 201a262

Please sign in to comment.