Skip to content

Delayed bug on uhh nested associated types with implied traits? #149120

@purplesyringa

Description

@purplesyringa

Found while reducing #149081.

Code

fn f<T: WithAssoc<Assoc = ()>>(_ptr: &Wrapper<T>) {}

struct Wrapper<T: WithAssoc>(<T::Assoc as WithAssoc>::Assoc);

trait WithAssoc {
    type Assoc: WithAssoc;
}

Variation:

fn f<T: WithAssoc<Assoc = U>, U>(_ptr: &Wrapper<T>) {}

struct Wrapper<T: WithAssoc>(<T::Assoc as WithAssoc>::Assoc);

trait WithAssoc {
    type Assoc: WithAssoc;
}

Meta

stable 1.91.1, nightly, everything.

rustc --version --verbose:

rustc 1.93.0-nightly (3d461af2a 2025-11-18)
binary: rustc
commit-hash: 3d461af2a23456a2676aadb13b4253c87bdfe28d
commit-date: 2025-11-18
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5

Error output

First reproducer:

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: unexpected ambiguity: CanonicalQueryInput { canonical: Canonical { value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [Binder { value: ProjectionPredicate(AliasTerm { args: [T/#0], def_id: DefId(0:10 ~ playground[b2a3]::WithAssoc::Assoc), .. }, Term::Ty(())), bound_vars: [] }, Binder { value: TraitPredicate(<T as WithAssoc>, polarity:Positive), bound_vars: [] }, Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }] }, value: AliasTy { args: [Wrapper<T/#0>], def_id: DefId(2:2450 ~ core[3960]::ptr::metadata::Pointee::Metadata), .. } }, max_universe: U0, variables: [] }, typing_mode: PostAnalysis } Canonical { value: QueryResponse { var_values: CanonicalVarValues { var_values: [] }, region_constraints: QueryRegionConstraints { outlives: [], assumptions: [] }, certainty: Ambiguous, opaque_types: [], value: NormalizationResult { normalized_ty: ^0 } }, max_universe: U0, variables: [Ty { ui: U0, sub_root: 0 }] }
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/query/normalize.rs:288:30 - disabled backtrace

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.91.1 (ed61e7d7e 2025-11-07) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

Second reproducer:

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: unexpected ambiguity: CanonicalQueryInput { canonical: Canonical { value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [Binder { value: ProjectionPredicate(AliasTerm { args: [T/#0], def_id: DefId(0:11 ~ playground[b2a3]::WithAssoc::Assoc), .. }, Term::Ty(U/#1)), bound_vars: [] }, Binder { value: TraitPredicate(<T as WithAssoc>, polarity:Positive), bound_vars: [] }, Binder { value: TraitPredicate(<U as std::marker::Sized>, polarity:Positive), bound_vars: [] }, Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }] }, value: AliasTy { args: [Wrapper<T/#0>], def_id: DefId(2:2450 ~ core[3960]::ptr::metadata::Pointee::Metadata), .. } }, max_universe: U0, variables: [] }, typing_mode: PostAnalysis } Canonical { value: QueryResponse { var_values: CanonicalVarValues { var_values: [] }, region_constraints: QueryRegionConstraints { outlives: [], assumptions: [] }, certainty: Ambiguous, opaque_types: [], value: NormalizationResult { normalized_ty: ^0 } }, max_universe: U0, variables: [Ty { ui: U0, sub_root: 0 }] }
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/query/normalize.rs:288:30 - disabled backtrace

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.91.1 (ed61e7d7e 2025-11-07) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

@rustbot label +T-compiler +A-associated-items +A-trait-system +C-bug +I-ICE

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-trait-systemArea: Trait systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️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