Skip to content

Commit 222e127

Browse files
Add E0036 error explanation
1 parent 7a13b93 commit 222e127

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/librustc_typeck/diagnostics.rs

+47-1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,53 @@ Reference:
211211
http://doc.rust-lang.org/reference.html#trait-objects
212212
"##,
213213

214+
E0036: r##"
215+
This error occurred when you pass too many or not enough type parameters to a
216+
method. Example:
217+
218+
```
219+
struct Test;
220+
221+
impl Test {
222+
fn method<T>(&self, v: &[T]) -> usize {
223+
v.len()
224+
}
225+
}
226+
227+
fn main() {
228+
let x = Test;
229+
let v = &[0i32];
230+
231+
x.method::<i32, i32>(v); // error: only one type parameter is expected!
232+
}
233+
```
234+
235+
To fix it, just specify a correct number of type parameters:
236+
237+
```
238+
struct Test;
239+
240+
impl Test {
241+
fn method<T>(&self, v: &[T]) -> usize {
242+
v.len()
243+
}
244+
}
245+
246+
fn main() {
247+
let x = Test;
248+
let v = &[0i32];
249+
250+
x.method::<i32>(v); // OK, we're good!
251+
}
252+
```
253+
254+
Please note on the last example that we could have called `method` like this:
255+
256+
```
257+
x.method(v);
258+
```
259+
"##,
260+
214261
E0040: r##"
215262
It is not allowed to manually call destructors in Rust. It is also not
216263
necessary to do this since `drop` is called automatically whenever a value goes
@@ -1322,7 +1369,6 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
13221369
register_diagnostics! {
13231370
E0034, // multiple applicable methods in scope
13241371
E0035, // does not take type parameters
1325-
E0036, // incorrect number of type parameters given for this method
13261372
E0044, // foreign items may not have type parameters
13271373
E0045, // variadic function must have C calling convention
13281374
E0068,

0 commit comments

Comments
 (0)