Skip to content

Commit 8b77f86

Browse files
committed
performed --bless of 15 ui tests affected
1 parent 78df446 commit 8b77f86

16 files changed

+67
-21
lines changed
Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,62 @@
1-
An underscore `_` character or a numeric literal `u8`, `i32`, `f64`, etc has
2-
been used as the identifier for a lifetime.
1+
An underscore `_` character has been used as the identifier for a lifetime,
2+
or a const generic has been borrowed without an explicit lifetime.
33

4-
Erroneous code example 1:
4+
Erroneous example with an underscore:
55
```
6-
fn some_function<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
7-
//Some code
8-
}
6+
fn foo<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {}
7+
// ^^ `'_` is a reserved lifetime name
8+
```
9+
Lifetimes are named with `'ident`, where ident is the name of the lifetime or
10+
loop. The `_` character, which represents the ignore pattern, cannot be used
11+
as the identifier because it is a reserved lifetime name. To fix
12+
this, use a lowercase letter, or a series of lowercase letters as the lifetime
13+
identifier. Often a single lowercase letter, such as `'a`, is sufficient. For
14+
more information, see
15+
[the book][bk-no].
16+
17+
Corrected underscore example:
18+
```
19+
fn <'a>(str1: &'a str, str2: &'a str) -> &'a str {}
920
```
10-
or Erroneous code example 2:
21+
22+
Erroneous example with const generic:
1123
```
12-
fn some_function<'u8>(str1: &'u8 str, str2: &'u8 str) -> &'u8 str {
13-
//Some code
24+
struct A<const N: &u8>;
25+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
26+
trait B {}
27+
28+
impl<const N: &u8> A<N> {
29+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
30+
fn foo<const M: &u8>(&self) {}
31+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
32+
}
33+
34+
impl<const N: &u8> B for A<N> {}
35+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
36+
37+
fn bar<const N: &u8>() {}
38+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
1439
}
1540
```
1641

17-
Lifetimes are named with `'ident`, where ident is the name of the lifetime or
18-
loop. The `_` character, which represents the ignore pattern, cannot be used
19-
as the identifier because it is a reserved lifetime name. Numeric literals are
20-
also invalid lifetime identifiers and will cause this error to be thrown. To fix
21-
this, use a series of lowercase letters as the lifetime identifier. Often a
22-
single lowercase letter, such as `'a`, is sufficient. For more information, see
23-
[the book][bk-no].
42+
Const generics cannot be borrowed without specifying a lifetime.The
43+
compiler handles memory allocation of constants differently than that of
44+
variables and it cannot infer the lifetime of the borrowed constant.
45+
To fix this, explicitly specify a lifetime for the const generic.
2446

25-
Corrected code example:
47+
Corrected const generic example:
2648
```
27-
fn some_function<'a>(str1: &'a str, str2: &'a str) -> &'a str {
28-
//Some code
49+
struct A<const N: &'a u8>;
50+
51+
trait B {}
52+
53+
impl<const N: &'a u8> A<N> {
54+
fn foo<const M: &'a u8>(&self) {}
55+
}
56+
57+
impl<const N: &'a u8> B for A<N> {}
58+
59+
fn bar<const N: &'a u8>() {}
2960
}
3061
```
3162
[bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols

src/test/ui/const-generics/const-param-elided-lifetime.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ LL | #![feature(const_generics)]
3838

3939
error: aborting due to 5 previous errors
4040

41+
For more information about this error, try `rustc --explain E0637`.

src/test/ui/error-codes/E0637.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ LL | impl<'a: '_> Bar<'a> {
1818

1919
error: aborting due to 3 previous errors
2020

21+
For more information about this error, try `rustc --explain E0637`.

src/test/ui/generics/issue-65285-incorrect-explicit-lifetime-name-needed.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}
1818

1919
error: aborting due to 3 previous errors
2020

21-
For more information about this error, try `rustc --explain E0106`.
21+
Some errors have detailed explanations: E0106, E0637.
22+
For more information about an error, try `rustc --explain E0106`.

src/test/ui/underscore-lifetime/in-binder.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@ LL | fn foo<'_>() {
3636

3737
error: aborting due to 6 previous errors
3838

39+
For more information about this error, try `rustc --explain E0637`.

src/test/ui/underscore-lifetime/underscore-lifetime-binders.stderr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ LL | fn foo2<'a>(_: &'a u8, y: &'a u8) -> &'a u8 { y }
3838

3939
error: aborting due to 5 previous errors
4040

41-
For more information about this error, try `rustc --explain E0106`.
41+
Some errors have detailed explanations: E0106, E0637.
42+
For more information about an error, try `rustc --explain E0106`.

src/test/ui/underscore-lifetime/underscore-outlives-bounds.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | impl<'b: '_> Foo<'b> for i32 {}
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0637`.

src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2015.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | T: WithType<&u32>
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0637`.

src/test/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2018.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | T: WithType<&u32>
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0637`.

src/test/ui/underscore-lifetime/where-clause-inherent-impl-underscore.rust2015.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ LL | T: WithRegion<'_>
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0637`.

0 commit comments

Comments
 (0)