Skip to content

Commit 201a262

Browse files
committed
Revised error long description
1 parent 4a1c6ce commit 201a262

File tree

1 file changed

+20
-8
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+20
-8
lines changed
Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1-
The underscore `_` character has been used as the identifier for a lifetime.
1+
2+
An underscore `_` character or a numeric literal `u8`, `i32`, `f64`, etc has
3+
been used as the identifier for a lifetime.
24

35
Erroneous code example:
46
```
5-
fn some_function<'_>(x: &'_ str, y: &'_ str) -> &'_ str {
7+
fn some_function<'_>(string1: &'_ str, string2: &'_ str) -> &'_ str {
8+
//Some code
9+
}
10+
```
11+
or Erroneous code example 2:
12+
```
13+
fn some_function<'u8>(string1: &'u8 str, string2: &'u8 str) -> &'u8 str {
614
//Some code
715
}
816
```
917

10-
Lifetimes are named with 'ident, where ident is the name of the
11-
lifetime or loop. The `_` character, which represents the ignore pattern,
12-
cannot be used because it is a reserved lifetime name.
13-
To fix this, use a single lowercase letter as the
14-
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).
18+
Lifetimes are named with `'ident`, where ident is the name of the lifetime or
19+
loop. The `_` character, which represents the ignore pattern, cannot be used
20+
as the identifier because it is a reserved lifetime name. Numeric literals are
21+
also invalid lifetime identifiers and will cause this error to be thrown. To fix
22+
this, use a series of lowercase letters as the lifetime identifier. Often a
23+
single lowercase letter, such as `'a`, is sufficient. For more information, see
24+
[the book][bk-no].
1525

1626
Corrected code example:
1727
```
18-
fn some_function<'a>(x: &'a str, y: &'a str) -> &'a str {
28+
fn some_function<'a>(string1: &'a str, string2: &'a str) -> &'a str {
1929
//Some code
2030
}
2131
```
2232

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

0 commit comments

Comments
 (0)