Skip to content

Commit 0d74311

Browse files
Add E0088 error explanation
1 parent 6c88a28 commit 0d74311

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,51 @@ The number of supplied parameters much exactly match the number of defined type
934934
parameters.
935935
"##,
936936

937+
E0088: r##"
938+
You gave too many lifetime parameters. Erroneous code example:
939+
940+
```
941+
fn f() {}
942+
943+
fn main() {
944+
f::<'static>() // error: too many lifetime parameters provided
945+
}
946+
```
947+
948+
Please check you give the right number of lifetime parameters. Example:
949+
950+
```
951+
fn f() {}
952+
953+
fn main() {
954+
f() // ok!
955+
}
956+
```
957+
958+
It's also important to note that the Rust compiler can generally
959+
determine the lifetime by itself. Example:
960+
961+
```
962+
struct Foo {
963+
value: String
964+
}
965+
966+
impl Foo {
967+
// it can be written like this
968+
fn get_value<'a>(&'a self) -> &'a str { &self.value }
969+
// but the compiler works fine with this too:
970+
fn without_lifetime(&self) -> &str { &self.value }
971+
}
972+
973+
fn main() {
974+
let f = Foo { value: "hello".to_owned() };
975+
976+
println!("{}", f.get_value());
977+
println!("{}", f.without_lifetime());
978+
}
979+
```
980+
"##,
981+
937982
E0089: r##"
938983
Not enough type parameters were supplied for a function. For example:
939984
@@ -960,13 +1005,14 @@ fn main() {
9601005
"##,
9611006

9621007
E0091: r##"
963-
You gave an unnecessary type parameter. Erroneous code example:
1008+
You gave an unnecessary type parameter in a type alias. Erroneous code
1009+
example:
9641010
9651011
```
9661012
type Foo<T> = u32; // error: type parameter `T` is unused
9671013
```
9681014
969-
Please check you didn't write to many type parameter. Example:
1015+
Please check you didn't write too many type parameters. Example:
9701016
9711017
```
9721018
type Foo = u32; // ok!
@@ -1599,7 +1645,6 @@ register_diagnostics! {
15991645
E0077,
16001646
E0085,
16011647
E0086,
1602-
E0088,
16031648
E0090,
16041649
E0092,
16051650
E0093,

0 commit comments

Comments
 (0)