@@ -211,6 +211,150 @@ Reference:
211211http://doc.rust-lang.org/reference.html#trait-objects
212212"## ,
213213
214+ E0034 : r##"
215+ The compiler doesn't know what method to call because more than one method
216+ has the same prototype. Example:
217+
218+ ```
219+ struct Test;
220+
221+ trait Trait1 {
222+ fn foo();
223+ }
224+
225+ trait Trait2 {
226+ fn foo();
227+ }
228+
229+ impl Trait1 for Test { fn foo() {} }
230+ impl Trait2 for Test { fn foo() {} }
231+
232+ fn main() {
233+ Test::foo() // error, which foo() to call?
234+ }
235+ ```
236+
237+ To avoid this error, you have to keep only one of them and remove the others.
238+ So let's take our example and fix it:
239+
240+ ```
241+ struct Test;
242+
243+ trait Trait1 {
244+ fn foo();
245+ }
246+
247+ impl Trait1 for Test { fn foo() {} }
248+
249+ fn main() {
250+ Test::foo() // and now that's good!
251+ }
252+ ```
253+
254+ However, a better solution would be using fully explicit naming of type and
255+ trait:
256+
257+ ```
258+ struct Test;
259+
260+ trait Trait1 {
261+ fn foo();
262+ }
263+
264+ trait Trait2 {
265+ fn foo();
266+ }
267+
268+ impl Trait1 for Test { fn foo() {} }
269+ impl Trait2 for Test { fn foo() {} }
270+
271+ fn main() {
272+ <Test as Trait1>::foo()
273+ }
274+ ```
275+ "## ,
276+
277+ E0035 : r##"
278+ You tried to give a type parameter where it wasn't needed. Bad example:
279+
280+ ```
281+ struct Test;
282+
283+ impl Test {
284+ fn method(&self) {}
285+ }
286+
287+ fn main() {
288+ let x = Test;
289+
290+ x.method::<i32>(); // Error: Test::method doesn't need type parameter!
291+ }
292+ ```
293+
294+ To fix this error, just remove the type parameter:
295+
296+ ```
297+ struct Test;
298+
299+ impl Test {
300+ fn method(&self) {}
301+ }
302+
303+ fn main() {
304+ let x = Test;
305+
306+ x.method(); // OK, we're good!
307+ }
308+ ```
309+ "## ,
310+
311+ E0036 : r##"
312+ This error occurrs when you pass too many or not enough type parameters to
313+ a method. Example:
314+
315+ ```
316+ struct Test;
317+
318+ impl Test {
319+ fn method<T>(&self, v: &[T]) -> usize {
320+ v.len()
321+ }
322+ }
323+
324+ fn main() {
325+ let x = Test;
326+ let v = &[0i32];
327+
328+ x.method::<i32, i32>(v); // error: only one type parameter is expected!
329+ }
330+ ```
331+
332+ To fix it, just specify a correct number of type parameters:
333+
334+ ```
335+ struct Test;
336+
337+ impl Test {
338+ fn method<T>(&self, v: &[T]) -> usize {
339+ v.len()
340+ }
341+ }
342+
343+ fn main() {
344+ let x = Test;
345+ let v = &[0i32];
346+
347+ x.method::<i32>(v); // OK, we're good!
348+ }
349+ ```
350+
351+ Please note on the last example that we could have called `method` like this:
352+
353+ ```
354+ x.method(v);
355+ ```
356+ "## ,
357+
214358E0040 : r##"
215359It is not allowed to manually call destructors in Rust. It is also not
216360necessary to do this since `drop` is called automatically whenever a value goes
@@ -1320,9 +1464,6 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust
13201464}
13211465
13221466register_diagnostics ! {
1323- E0034 , // multiple applicable methods in scope
1324- E0035 , // does not take type parameters
1325- E0036 , // incorrect number of type parameters given for this method
13261467 E0044 , // foreign items may not have type parameters
13271468 E0045 , // variadic function must have C calling convention
13281469 E0068 ,
0 commit comments