File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
src/librustc_error_codes/error_codes Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff line change 11You 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:
35
46``` compile_fail,E0277
57// 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+
19This error indicates that type inference did not result in one unique possible
210type, and extra information is required. In most cases this can be provided
311by 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
816implemented by ` Vec ` and ` String ` among others. Consider the following snippet
917that reverses the characters of a string:
1018
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 ` :
1822
1923```
2024let x: Vec<char> = "hello".chars().rev().collect();
You can’t perform that action at this time.
0 commit comments