Suggest using 'static in assoc consts and suggest when multiple lts are needed

This commit is contained in:
Esteban Küber 2020-08-11 13:02:14 -07:00
parent becd479482
commit 6a3deb0ae0
5 changed files with 144 additions and 12 deletions

View file

@ -51,6 +51,15 @@ error[E0106]: missing lifetime specifiers
|
LL | buzz: Buzz,
| ^^^^ expected 2 lifetime parameters
|
help: consider introducing a named lifetime parameter
|
LL | struct Quux<'a> {
LL | baz: Baz,
LL |
LL |
LL | buzz: Buzz<'a, 'a>,
|
error: aborting due to 5 previous errors

View file

@ -1,5 +1,16 @@
trait ZstAssert: Sized {
const TYPE_NAME: &str = ""; //~ ERROR missing lifetime specifier
const A: &str = ""; //~ ERROR missing lifetime specifier
const B: S = S { s: &() }; //~ ERROR missing lifetime specifier
const C: &'_ str = ""; //~ ERROR missing lifetime specifier
const D: T = T { a: &(), b: &() }; //~ ERROR missing lifetime specifier
}
struct S<'a> {
s: &'a (),
}
struct T<'a, 'b> {
a: &'a (),
b: &'b (),
}
fn main() {}

View file

@ -1,15 +1,73 @@
error[E0106]: missing lifetime specifier
--> $DIR/missing-lifetime-in-assoc-const-type.rs:2:22
--> $DIR/missing-lifetime-in-assoc-const-type.rs:2:14
|
LL | const TYPE_NAME: &str = "";
| ^ expected named lifetime parameter
LL | const A: &str = "";
| ^ expected named lifetime parameter
|
help: consider using the `'static` lifetime
|
LL | const A: &'static str = "";
| ^^^^^^^
help: consider introducing a named lifetime parameter
|
LL | trait ZstAssert<'a>: Sized {
LL | const TYPE_NAME: &'a str = "";
LL | const A: &'a str = "";
|
error: aborting due to previous error
error[E0106]: missing lifetime specifier
--> $DIR/missing-lifetime-in-assoc-const-type.rs:3:14
|
LL | const B: S = S { s: &() };
| ^ expected named lifetime parameter
|
help: consider using the `'static` lifetime
|
LL | const B: S<'static> = S { s: &() };
| ^^^^^^^^^
help: consider introducing a named lifetime parameter
|
LL | trait ZstAssert<'a>: Sized {
LL | const A: &str = "";
LL | const B: S<'a> = S { s: &() };
|
error[E0106]: missing lifetime specifier
--> $DIR/missing-lifetime-in-assoc-const-type.rs:4:15
|
LL | const C: &'_ str = "";
| ^^ expected named lifetime parameter
|
help: consider using the `'static` lifetime
|
LL | const C: &'static str = "";
| ^^^^^^^
help: consider introducing a named lifetime parameter
|
LL | trait ZstAssert<'a>: Sized {
LL | const A: &str = "";
LL | const B: S = S { s: &() };
LL | const C: &'a str = "";
|
error[E0106]: missing lifetime specifiers
--> $DIR/missing-lifetime-in-assoc-const-type.rs:5:14
|
LL | const D: T = T { a: &(), b: &() };
| ^ expected 2 lifetime parameters
|
help: consider using the `'static` lifetime
|
LL | const D: T<'static, 'static> = T { a: &(), b: &() };
| ^^^^^^^^^^^^^^^^^^
help: consider introducing a named lifetime parameter
|
LL | trait ZstAssert<'a>: Sized {
LL | const A: &str = "";
LL | const B: S = S { s: &() };
LL | const C: &'_ str = "";
LL | const D: T<'a, 'a> = T { a: &(), b: &() };
|
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0106`.