Skip to content

Commit c775e28

Browse files
committed
---
yaml --- r: 216667 b: refs/heads/stable c: 414dfb1 h: refs/heads/master i: 216665: 1b013c5 216663: f8c1593 v: v3
1 parent a1bdf1d commit c775e28

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
@@ -29,5 +29,5 @@ refs/heads/tmp: 378a370ff2057afeb1eae86eb6e78c476866a4a6
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: a5286998df566e736b32f6795bfc3803bdaf453d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 6b292cd4c48f0876b4280dfdf0c38d474fe44330
32+
refs/heads/stable: 414dfb13df96a373c7fd37f6beb299e176675e0e
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375

branches/stable/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)