Skip to content

Commit 98205af

Browse files
Add E0036 error explanation
1 parent 2f56839 commit 98205af

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 47 additions & 0 deletions
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

0 commit comments

Comments
 (0)