@@ -3989,6 +3989,46 @@ let s = Simba { mother: 1, father: 0 }; // ok!
3989
3989
```
3990
3990
"## ,
3991
3991
3992
+ E0562 : r##"
3993
+ Abstract return types (written `impl Trait` for some trait `Trait`) are only
3994
+ allowed as function return types.
3995
+
3996
+ Erroneous code example:
3997
+
3998
+ ```compile_fail,E0562
3999
+ #![feature(conservative_impl_trait)]
4000
+
4001
+ fn main() {
4002
+ let count_to_ten: impl Iterator<Item=usize> = 0..10;
4003
+ // error: `impl Trait` not allowed outside of function and inherent method
4004
+ // return types
4005
+ for i in count_to_ten {
4006
+ println!("{}", i);
4007
+ }
4008
+ }
4009
+ ```
4010
+
4011
+ Make sure `impl Trait` only appears in return-type position.
4012
+
4013
+ ```
4014
+ #![feature(conservative_impl_trait)]
4015
+
4016
+ fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
4017
+ 0..n
4018
+ }
4019
+
4020
+ fn main() {
4021
+ for i in count_to_n(10) { // ok!
4022
+ println!("{}", i);
4023
+ }
4024
+ }
4025
+ ```
4026
+
4027
+ See [RFC 1522] for more details.
4028
+
4029
+ [RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
4030
+ "## ,
4031
+
3992
4032
E0570 : r##"
3993
4033
The requested ABI is unsupported by the current target.
3994
4034
@@ -4591,8 +4631,6 @@ register_diagnostics! {
4591
4631
E0436 , // functional record update requires a struct
4592
4632
E0521 , // redundant default implementations of trait
4593
4633
E0533 , // `{}` does not name a unit variant, unit struct or a constant
4594
- E0562 , // `impl Trait` not allowed outside of function
4595
- // and inherent method return types
4596
4634
E0563 , // cannot determine a type for this `impl Trait`: {}
4597
4635
E0564 , // only named lifetimes are allowed in `impl Trait`,
4598
4636
// but `{}` was found in the type `{}`
0 commit comments