Skip to content

Commit

Permalink
Rollup merge of rust-lang#42787 - zackmdavis:explain_E0562, r=Guillau…
Browse files Browse the repository at this point in the history
…meGomez

add extended information for E0562; impl Trait can only be a return type

r? @GuillaumeGomez
  • Loading branch information
Mark-Simulacrum authored Jun 22, 2017
2 parents 34d22cb + 43b9cb3 commit 7eac85d
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3989,6 +3989,46 @@ let s = Simba { mother: 1, father: 0 }; // ok!
```
"##,

E0562: r##"
Abstract return types (written `impl Trait` for some trait `Trait`) are only
allowed as function return types.
Erroneous code example:
```compile_fail,E0562
#![feature(conservative_impl_trait)]
fn main() {
let count_to_ten: impl Iterator<Item=usize> = 0..10;
// error: `impl Trait` not allowed outside of function and inherent method
// return types
for i in count_to_ten {
println!("{}", i);
}
}
```
Make sure `impl Trait` only appears in return-type position.
```
#![feature(conservative_impl_trait)]
fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
0..n
}
fn main() {
for i in count_to_n(10) { // ok!
println!("{}", i);
}
}
```
See [RFC 1522] for more details.
[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
"##,

E0570: r##"
The requested ABI is unsupported by the current target.
Expand Down Expand Up @@ -4338,8 +4378,6 @@ register_diagnostics! {
E0436, // functional record update requires a struct
E0521, // redundant default implementations of trait
E0533, // `{}` does not name a unit variant, unit struct or a constant
E0562, // `impl Trait` not allowed outside of function
// and inherent method return types
E0563, // cannot determine a type for this `impl Trait`: {}
E0564, // only named lifetimes are allowed in `impl Trait`,
// but `{}` was found in the type `{}`
Expand Down

0 comments on commit 7eac85d

Please sign in to comment.