performed --bless of 15 ui tests affected
This commit is contained in:
parent
78df44655a
commit
8b77f8688e
|
@ -1,31 +1,62 @@
|
|||
An underscore `_` character or a numeric literal `u8`, `i32`, `f64`, etc has
|
||||
been used as the identifier for a lifetime.
|
||||
An underscore `_` character has been used as the identifier for a lifetime,
|
||||
or a const generic has been borrowed without an explicit lifetime.
|
||||
|
||||
Erroneous code example 1:
|
||||
Erroneous example with an underscore:
|
||||
```
|
||||
fn some_function<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {
|
||||
//Some code
|
||||
}
|
||||
fn foo<'_>(str1: &'_ str, str2: &'_ str) -> &'_ str {}
|
||||
// ^^ `'_` is a reserved lifetime name
|
||||
```
|
||||
or Erroneous code example 2:
|
||||
```
|
||||
fn some_function<'u8>(str1: &'u8 str, str2: &'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
|
||||
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
|
||||
as the identifier because it is a reserved lifetime name. To fix
|
||||
this, use a lowercase letter, or 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:
|
||||
Corrected underscore example:
|
||||
```
|
||||
fn some_function<'a>(str1: &'a str, str2: &'a str) -> &'a str {
|
||||
//Some code
|
||||
fn <'a>(str1: &'a str, str2: &'a str) -> &'a str {}
|
||||
```
|
||||
|
||||
Erroneous example with const generic:
|
||||
```
|
||||
struct A<const N: &u8>;
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
trait B {}
|
||||
|
||||
impl<const N: &u8> A<N> {
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
fn foo<const M: &u8>(&self) {}
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
}
|
||||
|
||||
impl<const N: &u8> B for A<N> {}
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
|
||||
fn bar<const N: &u8>() {}
|
||||
//~^ ERROR `&` without an explicit lifetime name cannot be used here
|
||||
}
|
||||
```
|
||||
|
||||
Const generics cannot be borrowed without specifying a lifetime.The
|
||||
compiler handles memory allocation of constants differently than that of
|
||||
variables and it cannot infer the lifetime of the borrowed constant.
|
||||
To fix this, explicitly specify a lifetime for the const generic.
|
||||
|
||||
Corrected const generic example:
|
||||
```
|
||||
struct A<const N: &'a u8>;
|
||||
|
||||
trait B {}
|
||||
|
||||
impl<const N: &'a u8> A<N> {
|
||||
fn foo<const M: &'a u8>(&self) {}
|
||||
}
|
||||
|
||||
impl<const N: &'a u8> B for A<N> {}
|
||||
|
||||
fn bar<const N: &'a u8>() {}
|
||||
}
|
||||
```
|
||||
[bk-no]: https://doc.rust-lang.org/book/appendix-02-operators.html#non-operator-symbols
|
||||
|
|
|
@ -38,3 +38,4 @@ LL | #![feature(const_generics)]
|
|||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -18,3 +18,4 @@ LL | impl<'a: '_> Bar<'a> {
|
|||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -18,4 +18,5 @@ LL | fn bar<'b, L: X<&'b Nested<i32>>>(){}
|
|||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0106`.
|
||||
Some errors have detailed explanations: E0106, E0637.
|
||||
For more information about an error, try `rustc --explain E0106`.
|
||||
|
|
|
@ -36,3 +36,4 @@ LL | fn foo<'_>() {
|
|||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -38,4 +38,5 @@ LL | fn foo2<'a>(_: &'a u8, y: &'a u8) -> &'a u8 { y }
|
|||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0106`.
|
||||
Some errors have detailed explanations: E0106, E0637.
|
||||
For more information about an error, try `rustc --explain E0106`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | impl<'b: '_> Foo<'b> for i32 {}
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | T: WithType<&u32>
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | T: WithType<&u32>
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | T: WithRegion<'_>
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | T: WithRegion<'_>
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | T: WithType<&u32>
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | T: WithType<&u32>
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | T: WithRegion<'_>
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -6,3 +6,4 @@ LL | T: WithRegion<'_>
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
|
@ -12,3 +12,4 @@ LL | impl<T: '_> Foo<'static> for Vec<T> {}
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0637`.
|
||||
|
|
Loading…
Reference in New Issue