Revised error long description

This commit is contained in:
Josh White 2020-02-06 16:07:35 -05:00
parent 4a1c6ce235
commit 201a262ac4

View file

@ -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