diff options
| author | Zack M. Davis <code@zackmdavis.net> | 2017-06-20 16:23:59 -0700 |
|---|---|---|
| committer | Zack M. Davis <code@zackmdavis.net> | 2017-06-20 16:36:20 -0700 |
| commit | 43b9cb3c1db2d1906e62966fd92aee0f1cdff7b3 (patch) | |
| tree | 5d1a01dd075afcb4c14930562ebd2251ff8d6c83 | |
| parent | 29bce6e220f6fd2292d13d65fe503af7bf4852b7 (diff) | |
| download | rust-43b9cb3c1db2d1906e62966fd92aee0f1cdff7b3.tar.gz rust-43b9cb3c1db2d1906e62966fd92aee0f1cdff7b3.zip | |
add extended information for E0562; impl Trait can only be a return type
| -rw-r--r-- | src/librustc_typeck/diagnostics.rs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index f72af2084f0..b9513ec1556 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -3938,6 +3938,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. @@ -4287,8 +4327,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 `{}` |
