Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up E0277 and E0282 explanations #68958

Merged
merged 1 commit into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0277.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
You tried to use a type which doesn't implement some trait in a place which
expected that trait. Erroneous code example:
expected that trait.

Erroneous code example:

```compile_fail,E0277
// here we declare the Foo trait with a bar method
Expand Down
18 changes: 11 additions & 7 deletions src/librustc_error_codes/error_codes/E0282.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
The compiler could not infer a type and asked for a type annotation.

Erroneous code example:

```compile_fail,E0282
let x = "hello".chars().rev().collect();
```

This error indicates that type inference did not result in one unique possible
type, and extra information is required. In most cases this can be provided
by adding a type annotation. Sometimes you need to specify a generic type
Expand All @@ -8,13 +16,9 @@ parameter with a `FromIterator` bound, which for a `char` iterator is
implemented by `Vec` and `String` among others. Consider the following snippet
that reverses the characters of a string:

```compile_fail,E0282
let x = "hello".chars().rev().collect();
```

In this case, the compiler cannot infer what the type of `x` should be:
`Vec<char>` and `String` are both suitable candidates. To specify which type to
use, you can use a type annotation on `x`:
In the first code example, the compiler cannot infer what the type of `x` should
be: `Vec<char>` and `String` are both suitable candidates. To specify which type
to use, you can use a type annotation on `x`:

```
let x: Vec<char> = "hello".chars().rev().collect();
Expand Down