Skip to content

ICE :coherence: impl was matchable against Binder but now it is not, otherwise hang #125014

Open
@matthiaskrgr

Description

@matthiaskrgr

This one is a bit special because without coherence, it looks like rustc just hangs and with coherence, we ICE.
Not sure which is better though 😆

Code

#![feature(specialization)]

trait Foo {}

impl Foo for <u16 as Assoc>::Output {}

impl Foo for u32 {}

trait Assoc {
    type Output;
}
impl Output for u32 {}
impl Assoc for <u16 as Assoc>::Output {
    default type Output = bool;
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (6e1d94708 2024-05-10)
binary: rustc
commit-hash: 6e1d94708a0a4a35ca7e46c6cac98adf62fe800e
commit-date: 2024-05-10
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

rustc 2.rs -Znext-solver=coherence

Error output

error[E0405]: cannot find trait `Output` in this scope
  --> 2.rs:12:6
   |
12 | impl Output for u32 {}
   |      ^^^^^^ not found in this scope

warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
 --> 2.rs:1:12
  |
1 | #![feature(specialization)]
  |            ^^^^^^^^^^^^^^
  |
  = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
  = help: consider using `min_specialization` instead, which is more stable and complete
  = note: `#[warn(incomplete_features)]` on by default

error[E0601]: `main` function not found in crate `2`
  --> 2.rs:15:2
   |
15 | }
   |  ^ consider adding a `main` function to `2.rs`

error[E0119]: conflicting implementations of trait `Foo` for type `<u16 as Assoc>::Output`
 --> 2.rs:7:1
  |
5 | impl Foo for <u16 as Assoc>::Output {}
  | ----------------------------------- first implementation here
6 |
7 | impl Foo for u32 {}
  | ^^^^^^^^^^^^^^^^ conflicting implementation for `<u16 as Assoc>::Output`
Backtrace


error: internal compiler error: compiler/rustc_trait_selection/src/traits/select/mod.rs:2484:17: impl DefId(0:9 ~ 2[eac6]::{impl#3}) was matchable against Binder { value: TraitPredicate(<u16 as Assoc>, polarity:Positive), bound_vars: [] } but now is not

thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/select/mod.rs:2484:17:
Box<dyn Any>
stack backtrace:
   0:     0x70d6652fec45 - std::backtrace_rs::backtrace::libunwind::trace::h076b7d335d3f5d8e
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x70d6652fec45 - std::backtrace_rs::backtrace::trace_unsynchronized::h690cc670e4b53e26
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x70d6652fec45 - std::sys_common::backtrace::_print_fmt::h1c4819ca31a9a7e4
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x70d6652fec45 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h80477bfb9d3c4c0e
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x70d66534de0b - core::fmt::rt::Argument::fmt::h15c65d56ade59385
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/core/src/fmt/rt.rs:165:63
   5:     0x70d66534de0b - core::fmt::write::haea2d0f40af65206
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/core/src/fmt/mod.rs:1157:21
   6:     0x70d6652f398f - std::io::Write::write_fmt::h3669847656ea0615
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/io/mod.rs:1835:15
   7:     0x70d6652fea1e - std::sys_common::backtrace::_print::ha73eb023eb111e4d
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x70d6652fea1e - std::sys_common::backtrace::print::hbff52728084c2b90
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x70d665301389 - std::panicking::default_hook::{{closure}}::h0d17646ea03cf057
  10:     0x70d6653010cd - std::panicking::default_hook::h40601e5e85aa667a
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/panicking.rs:298:9
  11:     0x70d661cceab0 - std[420967f48346b39c]::panicking::update_hook::<alloc[478b9a7ca3809208]::boxed::Box<rustc_driver_impl[9e6d636adc327e66]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x70d665301a86 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hd12a80ecb6b6cfe8
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/alloc/src/boxed.rs:2036:9
  13:     0x70d665301a86 - std::panicking::rust_panic_with_hook::h33d302c7fc861cff
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/panicking.rs:799:13
  14:     0x70d661cfead4 - std[420967f48346b39c]::panicking::begin_panic::<rustc_errors[45d68b0688aaeb54]::ExplicitBug>::{closure#0}
  15:     0x70d661cfb476 - std[420967f48346b39c]::sys_common::backtrace::__rust_end_short_backtrace::<std[420967f48346b39c]::panicking::begin_panic<rustc_errors[45d68b0688aaeb54]::ExplicitBug>::{closure#0}, !>
  16:     0x70d661cf6a26 - std[420967f48346b39c]::panicking::begin_panic::<rustc_errors[45d68b0688aaeb54]::ExplicitBug>
  17:     0x70d661d07c61 - <rustc_errors[45d68b0688aaeb54]::diagnostic::BugAbort as rustc_errors[45d68b0688aaeb54]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x70d6621bee9c - rustc_middle[b29a689460622aa4]::util::bug::opt_span_bug_fmt::<rustc_span[7f36b8f4ab5c669f]::span_encoding::Span>::{closure#0}
  19:     0x70d6621a387a - rustc_middle[b29a689460622aa4]::ty::context::tls::with_opt::<rustc_middle[b29a689460622aa4]::util::bug::opt_span_bug_fmt<rustc_span[7f36b8f4ab5c669f]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x70d6621a371b - rustc_middle[b29a689460622aa4]::ty::context::tls::with_context_opt::<rustc_middle[b29a689460622aa4]::ty::context::tls::with_opt<rustc_middle[b29a689460622aa4]::util::bug::opt_span_bug_fmt<rustc_span[7f36b8f4ab5c669f]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x70d660498d20 - rustc_middle[b29a689460622aa4]::util::bug::bug_fmt
  22:     0x70d6637ab30e - <rustc_trait_selection[6d54a2dd8c1020d6]::traits::select::SelectionContext>::confirm_candidate
  23:     0x70d66356f516 - <rustc_trait_selection[6d54a2dd8c1020d6]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
  24:     0x70d663566dc0 - <rustc_trait_selection[6d54a2dd8c1020d6]::traits::select::SelectionContext>::evaluate_root_obligation
  25:     0x70d66356538b - rustc_traits[8c7b2acb6abdc47]::evaluate_obligation::evaluate_obligation
  26:     0x70d663564d29 - rustc_query_impl[afd3850f0842b024]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[afd3850f0842b024]::query_impl::evaluate_obligation::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 2usize]>>
  27:     0x70d663564292 - rustc_query_system[6b56706b6a133fc0]::query::plumbing::try_execute_query::<rustc_query_impl[afd3850f0842b024]::DynamicConfig<rustc_query_system[6b56706b6a133fc0]::query::caches::DefaultCache<rustc_type_ir[f4c1b7e92dc1a1]::canonical::Canonical<rustc_middle[b29a689460622aa4]::ty::context::TyCtxt, rustc_middle[b29a689460622aa4]::ty::ParamEnvAnd<rustc_middle[b29a689460622aa4]::ty::predicate::Predicate>>, rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 2usize]>>, false, false, false>, rustc_query_impl[afd3850f0842b024]::plumbing::QueryCtxt, false>
  28:     0x70d663563eda - rustc_query_impl[afd3850f0842b024]::query_impl::evaluate_obligation::get_query_non_incr::__rust_end_short_backtrace
  29:     0x70d65fc962fb - <rustc_trait_selection[6d54a2dd8c1020d6]::traits::fulfill::FulfillProcessor as rustc_data_structures[fdcc01f8f4e370e]::obligation_forest::ObligationProcessor>::process_obligation
  30:     0x70d66300d6e3 - <rustc_data_structures[fdcc01f8f4e370e]::obligation_forest::ObligationForest<rustc_trait_selection[6d54a2dd8c1020d6]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[6d54a2dd8c1020d6]::traits::fulfill::FulfillProcessor>
  31:     0x70d6633f7e7a - <rustc_trait_selection[6d54a2dd8c1020d6]::traits::engine::ObligationCtxt>::assumed_wf_types
  32:     0x70d663654ea7 - rustc_hir_analysis[4c558df9982554fc]::check::wfcheck::check_well_formed
  33:     0x70d663653b9d - rustc_query_impl[afd3850f0842b024]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[afd3850f0842b024]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 1usize]>>
  34:     0x70d663653340 - rustc_query_system[6b56706b6a133fc0]::query::plumbing::try_execute_query::<rustc_query_impl[afd3850f0842b024]::DynamicConfig<rustc_query_system[6b56706b6a133fc0]::query::caches::VecCache<rustc_hir[e33a67695c771d92]::hir_id::OwnerId, rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[afd3850f0842b024]::plumbing::QueryCtxt, false>
  35:     0x70d6636530bf - rustc_query_impl[afd3850f0842b024]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  36:     0x70d663650ff7 - rustc_hir_analysis[4c558df9982554fc]::check::wfcheck::check_mod_type_wf
  37:     0x70d663650e1f - rustc_query_impl[afd3850f0842b024]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[afd3850f0842b024]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 1usize]>>
  38:     0x70d663aeda70 - rustc_query_system[6b56706b6a133fc0]::query::plumbing::try_execute_query::<rustc_query_impl[afd3850f0842b024]::DynamicConfig<rustc_query_system[6b56706b6a133fc0]::query::caches::DefaultCache<rustc_span[7f36b8f4ab5c669f]::def_id::LocalModDefId, rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[afd3850f0842b024]::plumbing::QueryCtxt, false>
  39:     0x70d663aed81b - rustc_query_impl[afd3850f0842b024]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  40:     0x70d66338fc46 - rustc_hir_analysis[4c558df9982554fc]::check_crate
  41:     0x70d663385f07 - rustc_interface[d156b119c0ee28cb]::passes::analysis
  42:     0x70d663385a55 - rustc_query_impl[afd3850f0842b024]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[afd3850f0842b024]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 1usize]>>
  43:     0x70d663dcb565 - rustc_query_system[6b56706b6a133fc0]::query::plumbing::try_execute_query::<rustc_query_impl[afd3850f0842b024]::DynamicConfig<rustc_query_system[6b56706b6a133fc0]::query::caches::SingleCache<rustc_middle[b29a689460622aa4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[afd3850f0842b024]::plumbing::QueryCtxt, false>
  44:     0x70d663dcb2c9 - rustc_query_impl[afd3850f0842b024]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  45:     0x70d663c0324e - rustc_interface[d156b119c0ee28cb]::interface::run_compiler::<core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>, rustc_driver_impl[9e6d636adc327e66]::run_compiler::{closure#0}>::{closure#1}
  46:     0x70d663bdfe09 - std[420967f48346b39c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[d156b119c0ee28cb]::util::run_in_thread_with_globals<rustc_interface[d156b119c0ee28cb]::util::run_in_thread_pool_with_globals<rustc_interface[d156b119c0ee28cb]::interface::run_compiler<core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>, rustc_driver_impl[9e6d636adc327e66]::run_compiler::{closure#0}>::{closure#1}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#0}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>
  47:     0x70d663bdfbb6 - <<std[420967f48346b39c]::thread::Builder>::spawn_unchecked_<rustc_interface[d156b119c0ee28cb]::util::run_in_thread_with_globals<rustc_interface[d156b119c0ee28cb]::util::run_in_thread_pool_with_globals<rustc_interface[d156b119c0ee28cb]::interface::run_compiler<core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>, rustc_driver_impl[9e6d636adc327e66]::run_compiler::{closure#0}>::{closure#1}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#0}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[554a336f897370d5]::result::Result<(), rustc_span[7f36b8f4ab5c669f]::ErrorGuaranteed>>::{closure#2} as core[554a336f897370d5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x70d66530b8cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h56757e55bbcfa856
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/alloc/src/boxed.rs:2022:9
  49:     0x70d66530b8cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf230e264012c630a
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/alloc/src/boxed.rs:2022:9
  50:     0x70d66530b8cb - std::sys::pal::unix::thread::Thread::new::thread_start::hfcc46c6a7fe0b042
                               at /rustc/6e1d94708a0a4a35ca7e46c6cac98adf62fe800e/library/std/src/sys/pal/unix/thread.rs:108:17
  51:     0x70d65eaa955a - <unknown>
  52:     0x70d65eb26a3c - <unknown>
  53:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/im/rustc-ice-2024-05-11T13_50_03-227107.txt` to your bug report

note: compiler flags: -Z next-solver=coherence

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `u16: Assoc`
#1 [check_well_formed] checking that `<impl at 2.rs:13:1: 13:38>` is well-formed
#2 [check_mod_type_wf] checking that types are well-formed in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0119, E0405, E0601.
For more information about an error, try `rustc --explain E0119`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-specialization`#![feature(specialization)]`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.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions