rust-lang / rust-lang/rust

Delayed bug on uhh nested associated types with implied traits?

Open
#149,120 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-associated-items A-trait-system C-bug fixed-by-next-solver I-ICE T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the two Rust reproductions in the issue and inspect the delayed-bug path at compiler/rustc_trait_selection/src/traits/query/normalize.rs:288. Compare how nested associated types and implied traits produce the ambiguous normalization result. Done means both examples no longer produce an internal compiler error or delayed-bug report, with regression coverage for the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.