Skip to content

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

Closed

Description

@cpubot

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

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 6, 2023
  2. lqd commented on Nov 7, 2023

    @lqd
    Member

    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.

  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions