@@ -368,6 +368,73 @@ loop. Without a loop to break out of or continue in, no sensible action can be
368
368
taken.
369
369
"## ,
370
370
371
+ E0282 : r##"
372
+ This error indicates that type inference did not result in one unique possible
373
+ type, and extra information is required. In most cases this can be provided
374
+ by adding a type annotation. Sometimes you need to specify a generic type
375
+ parameter manually.
376
+
377
+ A common example is the `collect` method on `Iterator`. It has a generic type
378
+ parameter with a `FromIterator` bound, which is implemented by `Vec` and
379
+ `VecDeque` among others. Consider the following snippet:
380
+
381
+ ```
382
+ let x = (1_i32 .. 10).collect();
383
+ ```
384
+
385
+ In this case, the compiler cannot infer what the type of `x` should be:
386
+ `Vec<i32>` and `VecDeque<i32>` are both suitable candidates. To specify which
387
+ type to use, you can use a type annotation on `x`:
388
+
389
+ ```
390
+ let x: Vec<i32> = (1_i32 .. 10).collect();
391
+ ```
392
+
393
+ It is not necessary to annotate the full type, once the ambiguity is resolved,
394
+ the compiler can infer the rest:
395
+
396
+ ```
397
+ let x: Vec<_> = (1_i32 .. 10).collect();
398
+ ```
399
+
400
+ Another way to provide the compiler with enough information, is to specify the
401
+ generic type parameter:
402
+
403
+ ```
404
+ let x = (1_i32 .. 10).collect::<Vec<i32>>();
405
+ ```
406
+
407
+ Again, you need not specify the full type if the compiler can infer it:
408
+
409
+ ```
410
+ let x = (1_i32 .. 10).collect::<Vec<_>>();
411
+ ```
412
+
413
+ Apart from a method or function with a generic type parameter, this error can
414
+ occur when a type parameter of a struct or trait cannot be inferred. In that
415
+ case it is not always possible to use a type annotation, because all candidates
416
+ have the same return type. For instance:
417
+
418
+ ```
419
+ struct Foo<T> {
420
+ // Some fields omitted.
421
+ }
422
+
423
+ impl<T> Foo<T> {
424
+ fn bar() -> i32 {
425
+ 0
426
+ }
427
+
428
+ fn baz() {
429
+ let number = Foo::bar();
430
+ }
431
+ }
432
+ ```
433
+
434
+ This will fail because the compiler does not know which instance of `Foo` to
435
+ call `bar` on. Change `Foo::bar()` to `Foo::<T>::bar()` to resolve the error.
436
+ "## ,
437
+
371
438
E0296 : r##"
372
439
This error indicates that the given recursion limit could not be parsed. Ensure
373
440
that the value provided is a positive integer between quotes, like so:
@@ -515,7 +582,6 @@ register_diagnostics! {
515
582
E0279 , // requirement is not satisfied
516
583
E0280 , // requirement is not satisfied
517
584
E0281 , // type implements trait but other trait is required
518
- E0282 , // unable to infer enough type information about
519
585
E0283 , // cannot resolve type
520
586
E0284 , // cannot resolve type
521
587
E0285 , // overflow evaluation builtin bounds
0 commit comments