- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)C-bugCategory: This is a bug.Category: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleF-associated_type_bounds`#![feature(associated_type_bounds)]``#![feature(associated_type_bounds)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
Follow up of #61738.
These two particular cases could not be refactored due to an ambiguity issue:
rust/src/libcore/iter/adapters/flatten.rs
Lines 70 to 76 in 2d1a551
| impl<I: DoubleEndedIterator, U, F> DoubleEndedIterator for FlatMap<I, U, F> | |
| where F: FnMut(I::Item) -> U, | |
| U: IntoIterator, | |
| U::IntoIter: DoubleEndedIterator | |
| { | |
| #[inline] | |
| fn next_back(&mut self) -> Option<U::Item> { self.inner.next_back() } | 
With #![feature(associated_type_bounds)]
impl<I: DoubleEndedIterator, U, F> DoubleEndedIterator for FlatMap<I, U, F>
where
    F: FnMut(I::Item) -> U,
    U: IntoIterator<IntoIter: DoubleEndedIterator>,
{
    #[inline]
    fn next_back(&mut self) -> Option<U::Item> { self.inner.next_back() }Result (line numbers are off):
error[E0221]: ambiguous associated type `Item` in bounds of `U`
   --> src/libcore/iter/adapters/flatten.rs:77:39
    |
77  |     fn next_back(&mut self) -> Option<U::Item> { self.inner.next_back() }
    |                                       ^^^^^^^ ambiguous associated type `Item`
    |
   ::: src/libcore/iter/traits/iterator.rs:94:5
    |
94  |     type Item;
    |     ---------- ambiguous `Item` from `iter::traits::iterator::Iterator`
    |
   ::: src/libcore/iter/traits/collect.rs:211:5
    |
211 |     type Item;
    |     ---------- ambiguous `Item` from `iter::traits::collect::IntoIterator`
rust/src/libcore/iter/adapters/flatten.rs
Lines 107 to 110 in 2d1a551
| pub struct Flatten<I: Iterator> | |
| where I::Item: IntoIterator { | |
| inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>, | |
| } | 
With #![feature(associated_type_bounds)]
pub struct Flatten<I: Iterator<Item: IntoIterator>> {
    inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>,
}Result (line numbers are off):
error[E0221]: ambiguous associated type `Item` in bounds of `I`
   --> src/libcore/iter/adapters/flatten.rs:112:30
    |
112 |     inner: FlattenCompat<I, <I::Item as IntoIterator>::IntoIter>,
    |                              ^^^^^^^ ambiguous associated type `Item`
    |
   ::: src/libcore/iter/traits/collect.rs:211:5
    |
211 |     type Item;
    |     ---------- ambiguous `Item` from `iter::traits::collect::IntoIterator`
    |
   ::: src/libcore/iter/traits/iterator.rs:94:5
    |
94  |     type Item;
    |     ---------- ambiguous `Item` from `iter::traits::iterator::Iterator`
Metadata
Metadata
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)C-bugCategory: This is a bug.Category: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleF-associated_type_bounds`#![feature(associated_type_bounds)]``#![feature(associated_type_bounds)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.