Skip to content

Commit b84d93b

Browse files
committed
---
yaml --- r: 208078 b: refs/heads/snap-stage3 c: 414dfb1 h: refs/heads/master v: v3
1 parent 8da96fb commit b84d93b

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 38a97becdf3e6a6157f6f7ec2d98ade8d8edc193
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6b292cd4c48f0876b4280dfdf0c38d474fe44330
4+
refs/heads/snap-stage3: 414dfb13df96a373c7fd37f6beb299e176675e0e
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/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)