File tree 2 files changed +14
-8
lines changed
src/librustc_error_codes/error_codes
2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 1
1
You tried to use a type which doesn't implement some trait in a place which
2
- expected that trait. Erroneous code example:
2
+ expected that trait.
3
+
4
+ Erroneous code example:
3
5
4
6
``` compile_fail,E0277
5
7
// here we declare the Foo trait with a bar method
Original file line number Diff line number Diff line change
1
+ The compiler could not infer a type and asked for a type annotation.
2
+
3
+ Erroneous code example:
4
+
5
+ ``` compile_fail,E0282
6
+ let x = "hello".chars().rev().collect();
7
+ ```
8
+
1
9
This error indicates that type inference did not result in one unique possible
2
10
type, and extra information is required. In most cases this can be provided
3
11
by adding a type annotation. Sometimes you need to specify a generic type
@@ -8,13 +16,9 @@ parameter with a `FromIterator` bound, which for a `char` iterator is
8
16
implemented by ` Vec ` and ` String ` among others. Consider the following snippet
9
17
that reverses the characters of a string:
10
18
11
- ``` compile_fail,E0282
12
- let x = "hello".chars().rev().collect();
13
- ```
14
-
15
- In this case, the compiler cannot infer what the type of ` x ` should be:
16
- ` Vec<char> ` and ` String ` are both suitable candidates. To specify which type to
17
- use, you can use a type annotation on ` x ` :
19
+ In the first code example, the compiler cannot infer what the type of ` x ` should
20
+ be: ` Vec<char> ` and ` String ` are both suitable candidates. To specify which type
21
+ to use, you can use a type annotation on ` x ` :
18
22
19
23
```
20
24
let x: Vec<char> = "hello".chars().rev().collect();
You can’t perform that action at this time.
0 commit comments