]> git.proxmox.com Git - rustc.git/blob - src/librustc_error_codes/error_codes/E0637.md
New upstream version 1.45.0+dfsg1
[rustc.git] / src / librustc_error_codes / error_codes / E0637.md
1 An underscore `_` character has been used as the identifier for a lifetime.
2
3 Erroneous code example:
4
5 ```compile_fail,E0106,E0637
6 fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
7 //^^ `'_` is a reserved lifetime name
8 if str1.len() > str2.len() {
9 str1
10 } else {
11 str2
12 }
13 }
14 ```
15
16 `'_`, cannot be used as a lifetime identifier because it is a reserved for the
17 anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series
18 of lowercase letters such as `'foo`. For more information, see [the
19 book][bk-no]. For more information on using the anonymous lifetime in rust
20 nightly, see [the nightly book][bk-al].
21
22 Corrected example:
23
24 ```
25 fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str {
26 if str1.len() > str2.len() {
27 str1
28 } else {
29 str2
30 }
31 }
32 ```
33
34 [bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols
35 [bk-al]: https://doc.rust-lang.org/nightly/edition-guide/rust-2018/ownership-and-lifetimes/the-anonymous-lifetime.html