File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ // Regression test for #57979. This situation is meant to be an error.
2+ // As noted in the issue thread, we decided to forbid nested impl
3+ // trait of this kind:
4+ //
5+ // ```rust
6+ // fn foo() -> impl Foo<impl Bar> { .. }
7+ // ```
8+ //
9+ // Basically there are two hidden variables here, let's call them `X`
10+ // and `Y`, and we must prove that:
11+ //
12+ // ```
13+ // X: Foo<Y>
14+ // Y: Bar
15+ // ```
16+ //
17+ // However, the user is only giving us the return type `X`. It's true
18+ // that in some cases, we can infer `Y` from `X`, because `X` only
19+ // implements `Foo` for one type (and indeed the compiler does
20+ // inference of this kind), but I do recall that we intended to forbid
21+ // this -- in part because such inference is fragile, and there is not
22+ // necessarily a way for the user to be more explicit should the
23+ // inference fail (so you could get stuck with no way to port your
24+ // code forward if, for example, more impls are added to an existing
25+ // type).
26+ //
27+ // The same seems to apply in this situation. Here there are three impl traits, so we have
28+ //
29+ // ```
30+ // X: IntoIterator<Item = Y>
31+ // Y: Borrow<Data<Z>>
32+ // Z: AsRef<[u8]>
33+ // ```
34+
35+ use std:: borrow:: Borrow ;
36+
37+ pub struct Data < TBody > ( TBody ) ;
38+
39+ pub fn collect ( _: impl IntoIterator < Item = impl Borrow < Data < impl AsRef < [ u8 ] > > > > ) {
40+ //~^ ERROR
41+ unimplemented ! ( )
42+ }
You can’t perform that action at this time.
0 commit comments