@@ -3938,6 +3938,46 @@ let s = Simba { mother: 1, father: 0 }; // ok!
3938
3938
```
3939
3939
"## ,
3940
3940
3941
+ E0562 : r##"
3942
+ Abstract return types (written `impl Trait` for some trait `Trait`) are only
3943
+ allowed as function return types.
3944
+
3945
+ Erroneous code example:
3946
+
3947
+ ```compile_fail,E0562
3948
+ #![feature(conservative_impl_trait)]
3949
+
3950
+ fn main() {
3951
+ let count_to_ten: impl Iterator<Item=usize> = 0..10;
3952
+ // error: `impl Trait` not allowed outside of function and inherent method
3953
+ // return types
3954
+ for i in count_to_ten {
3955
+ println!("{}", i);
3956
+ }
3957
+ }
3958
+ ```
3959
+
3960
+ Make sure `impl Trait` only appears in return-type position.
3961
+
3962
+ ```
3963
+ #![feature(conservative_impl_trait)]
3964
+
3965
+ fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
3966
+ 0..n
3967
+ }
3968
+
3969
+ fn main() {
3970
+ for i in count_to_n(10) { // ok!
3971
+ println!("{}", i);
3972
+ }
3973
+ }
3974
+ ```
3975
+
3976
+ See [RFC 1522] for more details.
3977
+
3978
+ [RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
3979
+ "## ,
3980
+
3941
3981
E0570 : r##"
3942
3982
The requested ABI is unsupported by the current target.
3943
3983
@@ -4287,8 +4327,6 @@ register_diagnostics! {
4287
4327
E0436 , // functional record update requires a struct
4288
4328
E0521 , // redundant default implementations of trait
4289
4329
E0533 , // `{}` does not name a unit variant, unit struct or a constant
4290
- E0562 , // `impl Trait` not allowed outside of function
4291
- // and inherent method return types
4292
4330
E0563 , // cannot determine a type for this `impl Trait`: {}
4293
4331
E0564 , // only named lifetimes are allowed in `impl Trait`,
4294
4332
// but `{}` was found in the type `{}`
0 commit comments