File tree 1 file changed +4
-1
lines changed
src/librustc_error_codes/error_codes
1 file changed +4
-1
lines changed Original file line number Diff line number Diff line change 1
1
An underscore ` _ ` character has been used as the identifier for a lifetime.
2
2
3
- Erroneous example:
3
+ Erroneous code example:
4
+
4
5
``` compile_fail,E0106,E0637
5
6
fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
6
7
//^^ `'_` is a reserved lifetime name
@@ -11,13 +12,15 @@ fn longest<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
11
12
}
12
13
}
13
14
```
15
+
14
16
` '_ ` , cannot be used as a lifetime identifier because it is a reserved for the
15
17
anonymous lifetime. To fix this, use a lowercase letter such as 'a, or a series
16
18
of lowercase letters such as ` 'foo ` . For more information, see [ the
17
19
book] [ bk-no ] . For more information on using the anonymous lifetime in rust
18
20
nightly, see [ the nightly book] [ bk-al ] .
19
21
20
22
Corrected example:
23
+
21
24
```
22
25
fn longest<'a>(str1: &'a str, str2: &'a str) -> &'a str {
23
26
if str1.len() > str2.len() {
You can’t perform that action at this time.
0 commit comments