# impl Trait Slice 0
## Goal
* Slice 0: To support some form of `type Foo = impl Trait`, both as a top-level item and in impls, on stable.
* Slice 1: ...
* Slice 2: ...
## Links
* [impl Trait implementation plan](https://hackmd.io/4dafnCiTSiOZJy_3u4ju0A)
* [impl Trait stabilization slice 0](https://hackmd.io/L-Z9KlqWTHiSq_YUtUnM0w)
## Open questions
### Q0: Inference strategy
* [MCP #325] proposed a new inference strategy.
[MCP #325]: https://github.com/rust-lang/compiler-team/issues/325
## Slice 0
### Description
Goal:
* Enable people to have a traits that return iterators/futures, at least in some cases where GATs aren't needed
Proposal:
* permit impl Trait in type aliases and associated types
* even if the `impl Trait` is not used directly but as a field of an aggregate, e.g. `(&str, impl Trait)` or `Foo<impl Trait>`
* forbid type alises containing impl Trait from appearing outside of "return position"
* remove the hack that prevents cycles errors when an associated type would be normalized to an opaque type
```rust
// OK, because Foo is used in Return Position
type Foo = impl Trait;
fn foo() -> Foo {
}
// OK, because `Self::Iter` (in the trait)
// is only used in return position?
impl IntoIterator for MyType {
type IntoIter = impl Iterator<Item = ...>;
type Item = u32;
fn into_iter(self) -> Self::IntoIter {
let x: Self::Iter = ...;
/// ^^^^^^^^^^ would get a cycle error from normalization
let y: <MyType as IntoIterator>::IntoIter;
// what about
}
}
```
Things to test:
* in argument position (should be disallowed)
### Work plan and time estimates
**Assumption:** We do not to resolve the "Inference Strategy" question for Slice 0.
Estimate:
* Write up a description of slice 0 (1 week)
* RFC or other form of proposal that describes
* What code is accepted
* What code is denied
* Expected use cases (maybe we get some help from tokio folks on this)
* Implement the new feature-gate for this subset (2 weeks)
* permit impl Trait in type aliases and associated types
* even if the `impl Trait` is not used directly but as a field of an aggregate, e.g. `(&str, impl Trait)` or `Foo<impl Trait>`
* forbid type alises containing impl Trait from appearing outside of "return position"
* remove the hack that prevents cycles errors when an associated type would be normalized to an opaque type
* Generate thorough test cases showing the behavior (1 week)
* Make tests showing a type alias impl Trait used in all possible positions, gettinge rrors as appropriate
* Make tests showing associated types with impl Trait
* Test type alias that includes
* multiple impl traits `type Foo = (impl Trait1, impl Trait2)` and show that it obeys key restrictions
* similarly associated types
* Some tests showing the expected use case patterns
* Some amount of other tests that we will uncover as we go from crater runs
* Write stabilization report (1 week)
* Unexpected complications
* Bugs uncovered during writing tests
* Managing regressions that arise later
* Probably 1-2 person-months of work, maybe 6 person-weeks