Skip to content

failure to normalize associated types in supertraits #61083

Closed

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)) { }

Activity

  1. added
    A-associated-itemsArea: Associated items (types, constants & functions)
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 23, 2019
  2. nikomatsakis commented on May 23, 2019

    @nikomatsakis
    ContributorAuthor

    The problem seems to be here:

    let upcast_trait_refs = util::supertraits(self.tcx(), poly_trait_ref)
    .filter(|upcast_trait_ref| {
    self.infcx.probe(|_| {
    let upcast_trait_ref = upcast_trait_ref.clone();
    self.match_poly_trait_ref(obligation, upcast_trait_ref)
    .is_ok()
    })
    })
    .count();

    util::supertraits yields up unnormalized trait references, in particular.

  3. istankovic commented on Oct 20, 2023

    @istankovic
    Contributor

    The example compiles with 1.73.

  4. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    T-typesRelevant to the types team, which will review and decide on the PR/issue.
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Sep 18, 2025
  5. fmease commented on Sep 18, 2025

    @fmease
    Member

    Might or might not need a regression test. Bisecting to the PR that fixed it might clear that up.

  6. lukaslueg commented on Oct 2, 2025

    @lukaslueg
    Contributor

    Compiles since nightly-2024-11-27

    get_commits_between returning commits, len: 4
    commit[0] 2024-11-25: Auto merge of #133247 - GuillaumeGomez:reduce-integer-display-impl, r=workingjubilee
    commit[1] 2024-11-26: Auto merge of #133465 - ehuss:update-cargo, r=ehuss
    commit[2] 2024-11-26: Auto merge of #132894 - frank-king:feature/where-refactor, r=cjgillot
    commit[3] 2024-11-26: Auto merge of #133500 - GuillaumeGomez:rollup-4vcthwo, r=GuillaumeGomez

  7. zakrad commented on Jul 30, 2026

    @zakrad
    Contributor

    @rustbot claim

  8. added 3 commits that reference this issue on Aug 3, 2026
    dfd6095
    f5227ad
    24b0a99
  9. added 2 commits that reference this issue on Aug 4, 2026
    2acbc71
    57abac3
  10. added a commit that references this issue on Aug 4, 2026
    f761cab
  11. added a commit that references this issue on Aug 4, 2026
    cb8e629
  12. added a commit that references this issue on Aug 5, 2026
    f5070cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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