Skip to content

Commit 066a77c

Browse files
committed
---
yaml --- r: 210364 b: refs/heads/try c: 414dfb1 h: refs/heads/master v: v3
1 parent 52c6e8f commit 066a77c

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
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: 6b292cd4c48f0876b4280dfdf0c38d474fe44330
5+
refs/heads/try: 414dfb13df96a373c7fd37f6beb299e176675e0e
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: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,39 +375,40 @@ by adding a type annotation. Sometimes you need to specify a generic type
375375
parameter manually.
376376
377377
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:
378+
parameter with a `FromIterator` bound, which for a `char` iterator is
379+
implemented by `Vec` and `String` among others. Consider the following snippet
380+
that reverses the characters of a string:
380381
381382
```
382-
let x = (1_i32 .. 10).collect();
383+
let x = "hello".chars().rev().collect();
383384
```
384385
385386
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`:
387+
`Vec<char>` and `String` are both suitable candidates. To specify which type to
388+
use, you can use a type annotation on `x`:
388389
389390
```
390-
let x: Vec<i32> = (1_i32 .. 10).collect();
391+
let x: Vec<char> = "hello".chars().rev().collect();
391392
```
392393
393-
It is not necessary to annotate the full type, once the ambiguity is resolved,
394+
It is not necessary to annotate the full type. Once the ambiguity is resolved,
394395
the compiler can infer the rest:
395396
396397
```
397-
let x: Vec<_> = (1_i32 .. 10).collect();
398+
let x: Vec<_> = "hello".chars().rev().collect();
398399
```
399400
400401
Another way to provide the compiler with enough information, is to specify the
401402
generic type parameter:
402403
403404
```
404-
let x = (1_i32 .. 10).collect::<Vec<i32>>();
405+
let x = "hello".chars().rev().collect::<Vec<char>>();
405406
```
406407
407408
Again, you need not specify the full type if the compiler can infer it:
408409
409410
```
410-
let x = (1_i32 .. 10).collect::<Vec<_>>();
411+
let x = "hello".chars().rev().collect::<Vec<_>>();
411412
```
412413
413414
Apart from a method or function with a generic type parameter, this error can

0 commit comments

Comments
 (0)