Skip to content

Nightly regression in resolving trait impl with generic associated types #117646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cpubot opened this issue Nov 6, 2023 · 1 comment
Closed
Labels
C-bug Category: This is a bug.

Comments

@cpubot
Copy link

cpubot commented Nov 6, 2023

I tried this code:

trait MyIterator {
    type Item;
}

impl<T> MyIterator for Box<T>
where
    T: ?Sized + MyIterator,
{
    type Item = T::Item;
}

trait TraitWithIterator {
    type Iter<T>: MyIterator<Item = T>;
}

struct MyStruct;

impl TraitWithIterator for MyStruct {
    type Iter<T> = Box<dyn MyIterator<Item = T>>;
}

I expected to see this happen: Box<dyn MyIterator<Item = T>> is recognized as a valid instance of MyIterator<Item = T>, given the implementation of MyIterator for Box<T>.

The code compiles without issue on stable and nightly up to nightly-2023-11-03.

On nightly nightly-2023-11-04, it results in the following compiler error:

error[E0277]: the trait bound `(dyn MyIterator<Item = T> + 'static): MyIterator` is not satisfied
   --> src/lib.rs:301:20
    |
301 |     type Iter<T> = Box<dyn MyIterator<Item = T>>;
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `MyIterator` is not implemented for `(dyn MyIterator<Item = T> + 'static)`
    |
    = help: the trait `MyIterator` is implemented for `std::boxed::Box<T>`
note: required for `std::boxed::Box<(dyn MyIterator<Item = T> + 'static)>` to implement `MyIterator`
   --> src/lib.rs:287:9
    |
287 | impl<T> MyIterator for Box<T>
    |         ^^^^^^^^^^     ^^^^^^
288 | where
289 |     T: ?Sized + MyIterator,
    |                 ---------- unsatisfied trait bound introduced here
note: required by a bound in `TraitWithIterator::Iter`
   --> src/lib.rs:295:30
    |
295 |     type Iter<T>: MyIterator<Item = T>;
    |                              ^^^^^^^^ required by this bound in `TraitWithIterator::Iter`

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (1bb6553b9 2023-11-03)
binary: rustc
commit-hash: 1bb6553b967b69eed9ed8147e78b4f65cfc48e11
commit-date: 2023-11-03
host: aarch64-apple-darwin
release: 1.75.0-nightly
LLVM version: 17.0.4
@cpubot cpubot added the C-bug Category: This is a bug. label Nov 6, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 6, 2023
@lqd
Copy link
Member

lqd commented Nov 7, 2023

Thanks for opening an issue. I believe this to be similar to #117602 (or a duplicate) which is already fixed on master by #117610. The example doesn't trigger an error on master, and that fix should be available in tomorrow's nightly.
I'll close this issue as already fixed, but feel free to reopen if it happens again after updating to the next nightlies.

@lqd lqd closed this as completed Nov 7, 2023
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants