You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0000-return-position-impl-trait-in-traits.md
+34-2Lines changed: 34 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -251,8 +251,6 @@ where `T_0 + ... + T_m` are bounds, for any impl of that trait to be valid, the
251
251
252
252
[^refine]: `#[refine]` was added in [RFC 3245: Refined trait implementations](https://rust-lang.github.io/rfcs/3245-refined-impls.html). This feature is not yet stable. Examples in this RFC requiring the use of `#[refine]` will not work until that feature is stabilized.
253
253
254
-
Additionally, using `-> impl Trait` notation in an impl is only legal if the trait also uses that notation.
255
-
256
254
```rust
257
255
traitNewIntoIterator {
258
256
typeItem;
@@ -294,6 +292,23 @@ impl NewIntoIterator for Vec<u32> {
294
292
}
295
293
```
296
294
295
+
Additionally, using `-> impl Trait` notation in an impl is only legal if the trait also uses that notation. Each occurrence of `impl Trait` in an impl must unify with an occurrence of `impl Trait` in the trait.
An interesting consequence of auto trait leakage is that a trait is allowed to specify an auto trait in its return type bounds, but the impl does not have to _repeat_ that auto trait in its signature, as long as its return type actually implements the required bound. For example:
298
313
299
314
```rust
@@ -680,3 +695,20 @@ trait NewIntoIterator {
680
695
The only problem remaining is with `#[refine]`. If an existing implementation refined its return value of an RPITIT method, we would need the existing `#[refine]` attribute to stand in for an overriding of the associated type default.
681
696
682
697
Whatever rules we decide to make this work, they will interact with some ongoing discussions of proposals for `#[defines]` or `#[defined_by]` attributes on `type_alias_impl_trait`. We therefore leave the details of this to a future RFC.
698
+
699
+
### Adding new occurrences of `impl Trait` in refinements
0 commit comments