Skip to content

Commit 1177d06

Browse files
Clean up E0277 and E0282 explanations
1 parent 320ada6 commit 1177d06

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/librustc_error_codes/error_codes/E0277.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
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:
35

46
```compile_fail,E0277
57
// here we declare the Foo trait with a bar method

src/librustc_error_codes/error_codes/E0282.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
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+
19
This error indicates that type inference did not result in one unique possible
210
type, and extra information is required. In most cases this can be provided
311
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
816
implemented by `Vec` and `String` among others. Consider the following snippet
917
that 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
```
2024
let x: Vec<char> = "hello".chars().rev().collect();

0 commit comments

Comments
 (0)