Skip to content

"unexpected ambiguity: CanonicalQueryInput" with conflicting associated type specifiers #146371

Open

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:

(Edit: #146371 (comment))

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

Activity

  1. added
    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.
    C-bugCategory: This is a bug.
    on Sep 9, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    A-impossible-boundsArea: Issues related to have impossible trait bounds in scope (impossible predicates)
    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.
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Sep 9, 2025
  3. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Sep 9, 2025
  4. fmease commented on Sep 9, 2025

    @fmease
    Member

    Regression in nightly-2024-11-27

    This can't be. I've just tried nightly-2024-11-01 (to see what the output used to look like) and it also reproduces.
    Maybe it's flip-flopping?


    Edit: As a matter of fact, the regression didn't occur in nightly-2024-11-27; nightly-2024-11-26, nightly-2024-11-27, nightly-2024-11-28 all ICE for me (in check or build). I'm not sure what your bisect-rustc invocation looked like.

  5. added
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Sep 9, 2025
  6. fmease commented on Sep 9, 2025

    @fmease
    Member

    Smaller (no const blocks, etc.):

    trait Trait { type Assoc; }
    
    fn conjure<T>() -> T { loop {} }
    
    fn get_assoc<T: Trait>() -> impl Sized { conjure::<T::Assoc>() }
    
    fn foo<T: Trait<Assoc = i32> + Trait<Assoc = i64>>() { get_assoc::<T>(); }

    Without conjure but with assoc fn:

    trait Trait { type Assoc; fn make() -> Self::Assoc; }
    
    fn get_assoc<T: Trait>() -> impl Sized { T::make() }
    
    fn foo<T: Trait<Assoc = i32> + Trait<Assoc = i64>>() { get_assoc::<T>(); }
  7. added
    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    on Sep 9, 2025
  8. fmease commented on Sep 9, 2025

    @fmease
    Member

    Since cargo-bisect-rustc is acting up for me for some reason (maybe my commit range is too large?), I'll be manually bisecting for a bit.

    Local lower bound (PASS): 1.63 (2022-08-08)
    Local upper bound (ICE): 1.64 (2022-09-19)

  9. fmease commented on Sep 10, 2025

    @fmease
    Member

    searched toolchains nightly-2022-06-24 through nightly-2022-08-05


    Regression in nightly-2022-07-16


    looking for regression commit between 2022-07-15 and 2022-07-16
    fetching (via remote github) commits from max(c2f428d, 2022-07-13) to 23e21bd
    ending github query because we found starting sha: c2f428d
    get_commits_between returning commits, len: 9
    commit[0] 2022-07-14: Auto merge of #99252 - lqd:win-dwarf5, r=eddyb
    commit[1] 2022-07-14: Auto merge of #96544 - m-ysk:feature/issue-96358, r=cjgillot
    commit[2] 2022-07-15: Auto merge of #98203 - kckeiks:gather-body-owners-in-hir-item-queries, r=cjgillot
    commit[3] 2022-07-15: Auto merge of #97406 - aliemjay:verify-bounds-fix-master, r=oli-obk
    commit[4] 2022-07-15: Auto merge of #99267 - Dylan-DPC:rollup-d8l7y1o, r=Dylan-DPC
    commit[5] 2022-07-15: Auto merge of #99013 - RalfJung:dont-poison-my-places, r=oli-obk
    commit[6] 2022-07-15: Auto merge of #99278 - Dylan-DPC:rollup-fcln6st, r=Dylan-DPC
    commit[7] 2022-07-15: Auto merge of #99046 - nnethercote:final-derive-output-improvements, r=Mark-Simulacrum
    commit[8] 2022-07-15: Auto merge of #99015 - lcnr:fn-ctxt-no-more, r=compiler-errors

  10. fmease commented on Sep 10, 2025

    @fmease
    Member

    Maybe #97406 or #99015?

  11. added
    S-has-bisectionStatus: A bisection has been found for this issue
    and removed
    E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc
    on Sep 10, 2025
  12. lcnr commented on Sep 11, 2025

    @lcnr
    Contributor

    definitely #99015 😁 see 7808f69

    I would assume we've already got different issues where this ICEs? The underlying bug is older, we should either already error during HIR typeck or not normalize assuming there won't be errors afterwards

    trait Trait { type Assoc; fn make() -> Self::Assoc; }
    
    fn get_assoc<T: Trait>() -> impl Sized { T::make() }
    
    fn foo<T: Trait<Assoc = i32> + Trait<Assoc = i64>>() { get_assoc::<T>(); }

    this makes sense to me. proving T: Trait is easy while normalizing <T as Trait>::Assoc fails with ambiguity (as it should) 😁

    The reveal all pass shouldn't expect things to succeed if we're in an impossible env. I think we've already got stuff there which replaces MIR bodies with nothing if the env has any impossible where-clauses?

    It's just not possible to detect "is the given set of where-clauses inconsistent" in general 🤔

  13. changed the title [-]`unexpected ambiguity: CanonicalQueryInput` with conflicting associated type specifiers[/-] [+]"unexpected ambiguity: `CanonicalQueryInput`" with conflicting associated type specifiers[/+] on Sep 14, 2025
  14. apiraino commented on Sep 19, 2025

    @apiraino
    Contributor

    Assigning priority (discussion on Zulip).

    @rustbot label -I-prioritize +P-medium

  15. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Sep 19, 2025
  16. theemathas commented on Mar 21, 2026

    @theemathas
    Contributor

    A version of this which has actually-possible bounds (it ICEs on the old solver, but compiles with next-solver):

    trait Trait {
        type Assoc;
        fn make() -> Self::Assoc;
    }
    
    fn get_assoc<T: Trait>() -> impl Sized {
        T::make()
    }
    
    fn foo<T: Trait<Assoc = U> + Trait<Assoc = V>, U, V>() {
        get_assoc::<T>();
    }
    
    struct Thing;
    impl Trait for Thing {
        type Assoc = i32;
        fn make() -> i32 { 0 }
    }
    
    fn main() {
        foo::<Thing, i32, i32>();
    }
  17. removed
    A-impossible-boundsArea: Issues related to have impossible trait bounds in scope (impossible predicates)
    on Mar 21, 2026
  18. theemathas commented on Mar 21, 2026

    @theemathas
    Contributor

    A version that has actually-possible bounds, and ICEs on both the old solver and next-solver:

    trait Trait {
        type Assoc: Copy;
    }
    
    const fn get_assoc<T: Trait>() -> Option<impl Copy> {
        None::<T::Assoc>
    }
    
    fn foo<T: Trait<Assoc = U> + Trait<Assoc = V>, U, V>() {
        const { get_assoc::<T>(); }
    }
    
    struct Thing;
    impl Trait for Thing {
        type Assoc = i32;
    }
    
    fn main() {
        foo::<Thing, i32, i32>();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityS-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