Skip to content

failure to normalize associated types in supertraits #61083

@nikomatsakis

Description

@nikomatsakis

This example does not compile, but I believe it ought to (playground):

use std::vec::Vec;

trait Foo<T> { }

trait Bar<T: Iterator>: Foo<T::Item> { }

fn a(x: &(impl Foo<u32> + ?Sized)) {
    
}

fn b(y: &dyn Bar<std::vec::IntoIter<u32>>) {
    a(y)
}

fn main() {
    
}

we get the error:

error[E0277]: the trait bound `dyn Bar<std::vec::IntoIter<u32>>: Foo<u32>` is not satisfied
  --> src/main.rs:12:5
   |
12 |     a(y)
   |     ^ the trait `Foo<u32>` is not implemented for `dyn Bar<std::vec::IntoIter<u32>>`
   |
note: required by `a`
  --> src/main.rs:7:1
   |
7  | fn a(x: &(impl Foo<u32> + ?Sized)) {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Note that changing b like so compiles (playground):

fn b(y: &(impl Bar<std::vec::IntoIter<u32>> + ?Sized)) { }

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemE-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcE-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions