Skip to content

unexpected ambiguity: CanonicalQueryInput with conflicting associated type specifiers #146371

@Jules-Bertholet

Description

@Jules-Bertholet

Code

pub trait Trait {
    type Assoc: Copy + 'static;
}

const fn conjure<T>() -> T {
    panic!()
}

const fn get_assoc<T: Trait>() -> impl Copy {
    conjure::<<T as Trait>::Assoc>()
}

pub fn foo<T: Trait<Assoc = i32> + Trait<Assoc = i64>>() {
    const {
        get_assoc::<T>();
    }
}

(slightly adapted from @theemathas's example here)

Meta

cargo bisect-rustc:

Regression in nightly-2024-11-27

Error output

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:4 ~ playground[81cc]::Trait::Assoc), .. }, Term::Ty(i64)), bound_vars: [] }, Binder { value: ProjectionPredicate(AliasTerm { args: [T/#0], def_id: DefId(0:4 ~ playground[81cc]::Trait::Assoc), .. }, Term::Ty(i32)), bound_vars: [] }, Binder { value: TraitPredicate(<T as Trait>, polarity:Positive), bound_vars: [] }, Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }] }, value: AliasTy { args: [T/#0], def_id: DefId(0:4 ~ playground[81cc]::Trait::Assoc), .. } }, max_universe: U0, variables: [] }, typing_mode: PostAnalysis } Canonical { value: QueryResponse { var_values: CanonicalVarValues { var_values: [] }, region_constraints: QueryRegionConstraints { outlives: [] }, certainty: Ambiguous, opaque_types: [], value: NormalizationResult { normalized_ty: ^0 } }, max_universe: U0, variables: [Ty(General(U0))] }
  |
  = 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.89.0 (29483883e 2025-08-04) 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 A-impossible-bounds T-types regression-from-stable-to-stable

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-impossible-boundsArea: Issues related to have impossible trait bounds in scope (impossible predicates)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️I-prioritizeIssue: Indicates that prioritization has been requested for this issue.S-has-bisectionStatus: A bisection has been found for this issueS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions