Skip to content

Commit 52c6e8f

Browse files
committed
---
yaml --- r: 210363 b: refs/heads/try c: 6b292cd h: refs/heads/master i: 210361: 4683000 210359: b902402 v: v3
1 parent f5fe2e5 commit 52c6e8f

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: 52e520e902cecc579910e6cabe1658720bfab132
5+
refs/heads/try: 6b292cd4c48f0876b4280dfdf0c38d474fe44330
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/librustc/diagnostics.rs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,73 @@ loop. Without a loop to break out of or continue in, no sensible action can be
368368
taken.
369369
"##,
370370

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+
371438
E0296: r##"
372439
This error indicates that the given recursion limit could not be parsed. Ensure
373440
that the value provided is a positive integer between quotes, like so:
@@ -515,7 +582,6 @@ register_diagnostics! {
515582
E0279, // requirement is not satisfied
516583
E0280, // requirement is not satisfied
517584
E0281, // type implements trait but other trait is required
518-
E0282, // unable to infer enough type information about
519585
E0283, // cannot resolve type
520586
E0284, // cannot resolve type
521587
E0285, // overflow evaluation builtin bounds

0 commit comments

Comments
 (0)