Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: coherence: did not expect selection error when collecting ambiguity errors #124845

Closed
matthiaskrgr opened this issue May 7, 2024 · 1 comment · Fixed by #124871
Closed
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative

Comments

@matthiaskrgr
Copy link
Member

Code

trait Trait {
    type Assoc;
}

struct W<T: Trait<Assoc = u32>>(*mut T);
impl<T: ?Sized> Trait for W<W<W<T>>>
where
    W<T>: Trait,
{
    type Assoc = ();
}

trait NoOverlap {}
impl<T: Trait<W<T>>> NoOverlap for T {}


impl<T: Trait<Assoc = u32>> NoOverlap for W<T> {}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (5ae5d1353 2024-05-07)
binary: rustc
commit-hash: 5ae5d135372c4b576edc73c191d2dc86b1d16b5c
commit-date: 2024-05-07
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.4

Error output

` rustc ice.rs -Znext-solver=coherence

error[E0275]: overflow evaluating the requirement `W<W<W<_>>>: Trait`
  |
  = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`ice`)
note: required for `W<W<W<W<W<_>>>>>` to implement `Trait`
 --> ice.rs:6:17
  |
6 | impl<T: ?Sized> Trait for W<W<W<T>>>
  |                 ^^^^^     ^^^^^^^^^^
7 | where
8 |     W<T>: Trait,
  |           ----- unsatisfied trait bound introduced here
  = note: 126 redundant requirements hidden
  = note: required for `W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<W<...>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>` to implement `Trait`
  = note: the full name for the type has been written to 'ice.long-type-16872895002395984658.txt'
  = note: consider using `--verbose` to print the full type name to the console

error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
  --> ice.rs:14:9
   |
14 | impl<T: Trait<W<T>>> NoOverlap for T {}
   |         ^^^^^ expected 0 generic arguments
   |
note: trait defined here, with 0 generic parameters
  --> ice.rs:1:7
   |
1  | trait Trait {
   |       ^^^^^
help: replace the generic bound with the associated type
   |
14 | impl<T: Trait<Assoc = W<T>>> NoOverlap for T {}
   |               +++++++
Backtrace

error: internal compiler error: compiler/rustc_trait_selection/src/solve/fulfill.rs:264:17: did not expect selection error when collecting ambiguity errors

thread 'rustc' panicked at compiler/rustc_trait_selection/src/solve/fulfill.rs:264:17:
Box<dyn Any>
stack backtrace:
   0:     0x7a8d62606b35 - std::backtrace_rs::backtrace::libunwind::trace::h918aaf6e60cc0a20
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7a8d62606b35 - std::backtrace_rs::backtrace::trace_unsynchronized::h2eac6c94b93f8e3c
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7a8d62606b35 - std::sys_common::backtrace::_print_fmt::h8e5edaeb6a4352e8
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7a8d62606b35 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf5cc6736d08af678
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7a8d62655cfb - core::fmt::rt::Argument::fmt::hb75c12041eb78bdc
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/core/src/fmt/rt.rs:165:63
   5:     0x7a8d62655cfb - core::fmt::write::h3e6a6276a812b52d
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/core/src/fmt/mod.rs:1157:21
   6:     0x7a8d625fb87f - std::io::Write::write_fmt::h1eb4d2f52c7badcc
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/io/mod.rs:1835:15
   7:     0x7a8d6260690e - std::sys_common::backtrace::_print::h027a355b4099d109
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7a8d6260690e - std::sys_common::backtrace::print::h9288434216016cb8
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7a8d62609279 - std::panicking::default_hook::{{closure}}::hb774f76bb0cbe3f3
  10:     0x7a8d62608fbd - std::panicking::default_hook::h5e6bb2fe4f610e68
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/panicking.rs:298:9
  11:     0x7a8d5eeb3d1f - std[2409bda48c37ea6b]::panicking::update_hook::<alloc[e4f27f1b259856c9]::boxed::Box<rustc_driver_impl[3b65384176704029]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7a8d62609976 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h150247b09595b272
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/alloc/src/boxed.rs:2036:9
  13:     0x7a8d62609976 - std::panicking::rust_panic_with_hook::h193842b19bca8c30
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/panicking.rs:799:13
  14:     0x7a8d5eee3cd4 - std[2409bda48c37ea6b]::panicking::begin_panic::<rustc_errors[cb4eda40c63952d6]::ExplicitBug>::{closure#0}
  15:     0x7a8d5eee0686 - std[2409bda48c37ea6b]::sys_common::backtrace::__rust_end_short_backtrace::<std[2409bda48c37ea6b]::panicking::begin_panic<rustc_errors[cb4eda40c63952d6]::ExplicitBug>::{closure#0}, !>
  16:     0x7a8d5eedbc66 - std[2409bda48c37ea6b]::panicking::begin_panic::<rustc_errors[cb4eda40c63952d6]::ExplicitBug>
  17:     0x7a8d5eeece61 - <rustc_errors[cb4eda40c63952d6]::diagnostic::BugAbort as rustc_errors[cb4eda40c63952d6]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7a8d5f3a04fc - rustc_middle[d85377d387f08e9a]::util::bug::opt_span_bug_fmt::<rustc_span[86ddde2698e45e98]::span_encoding::Span>::{closure#0}
  19:     0x7a8d5f384eca - rustc_middle[d85377d387f08e9a]::ty::context::tls::with_opt::<rustc_middle[d85377d387f08e9a]::util::bug::opt_span_bug_fmt<rustc_span[86ddde2698e45e98]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7a8d5f384d4b - rustc_middle[d85377d387f08e9a]::ty::context::tls::with_context_opt::<rustc_middle[d85377d387f08e9a]::ty::context::tls::with_opt<rustc_middle[d85377d387f08e9a]::util::bug::opt_span_bug_fmt<rustc_span[86ddde2698e45e98]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7a8d5d09cdd0 - rustc_middle[d85377d387f08e9a]::util::bug::bug_fmt
  22:     0x7a8d5f9d8dd7 - <rustc_trait_selection[e301c94095ae1ef9]::solve::fulfill::FulfillmentCtxt as rustc_infer[8f29aeb09f313402]::traits::engine::TraitEngine>::collect_remaining_errors
  23:     0x7a8d60575ba8 - <rustc_trait_selection[e301c94095ae1ef9]::traits::engine::ObligationCtxt>::select_all_or_error
  24:     0x7a8d607198de - rustc_trait_selection[e301c94095ae1ef9]::traits::coherence::overlap
  25:     0x7a8d60e75591 - <rustc_middle[d85377d387f08e9a]::traits::specialization_graph::Children as rustc_trait_selection[e301c94095ae1ef9]::traits::specialize::specialization_graph::ChildrenExt>::insert
  26:     0x7a8d5dedfa68 - <rustc_middle[d85377d387f08e9a]::traits::specialization_graph::Graph as rustc_trait_selection[e301c94095ae1ef9]::traits::specialize::specialization_graph::GraphExt>::insert
  27:     0x7a8d602866bc - rustc_trait_selection[e301c94095ae1ef9]::traits::specialize::specialization_graph_provider
  28:     0x7a8d6028621f - rustc_query_impl[f7d6eb8805e88c29]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f7d6eb8805e88c29]::query_impl::specialization_graph_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 8usize]>>
  29:     0x7a8d60288c17 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::<rustc_query_impl[f7d6eb8805e88c29]::DynamicConfig<rustc_query_system[bd604859ea317a95]::query::caches::DefIdCache<rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[f7d6eb8805e88c29]::plumbing::QueryCtxt, false>
  30:     0x7a8d608f2a32 - rustc_query_impl[f7d6eb8805e88c29]::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7a8d60d62cb0 - rustc_hir_analysis[c4ab2add954ac9f7]::coherence::coherent_trait
  32:     0x7a8d60d629a3 - rustc_query_impl[f7d6eb8805e88c29]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f7d6eb8805e88c29]::query_impl::coherent_trait::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 1usize]>>
  33:     0x7a8d606bb793 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::<rustc_query_impl[f7d6eb8805e88c29]::DynamicConfig<rustc_query_system[bd604859ea317a95]::query::caches::DefIdCache<rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f7d6eb8805e88c29]::plumbing::QueryCtxt, false>
  34:     0x7a8d606b9e89 - rustc_query_impl[f7d6eb8805e88c29]::query_impl::coherent_trait::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7a8d608155ca - rustc_hir_analysis[c4ab2add954ac9f7]::check::wfcheck::check_well_formed
  36:     0x7a8d608133ad - rustc_query_impl[f7d6eb8805e88c29]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f7d6eb8805e88c29]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 1usize]>>
  37:     0x7a8d60812b40 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::<rustc_query_impl[f7d6eb8805e88c29]::DynamicConfig<rustc_query_system[bd604859ea317a95]::query::caches::VecCache<rustc_hir[606efbe1a170016d]::hir_id::OwnerId, rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f7d6eb8805e88c29]::plumbing::QueryCtxt, false>
  38:     0x7a8d608128bf - rustc_query_impl[f7d6eb8805e88c29]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7a8d60810801 - rustc_hir_analysis[c4ab2add954ac9f7]::check::wfcheck::check_mod_type_wf
  40:     0x7a8d60810647 - rustc_query_impl[f7d6eb8805e88c29]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f7d6eb8805e88c29]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 1usize]>>
  41:     0x7a8d60fb48c6 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::<rustc_query_impl[f7d6eb8805e88c29]::DynamicConfig<rustc_query_system[bd604859ea317a95]::query::caches::DefaultCache<rustc_span[86ddde2698e45e98]::def_id::LocalModDefId, rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f7d6eb8805e88c29]::plumbing::QueryCtxt, false>
  42:     0x7a8d60fb467f - rustc_query_impl[f7d6eb8805e88c29]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7a8d6052219e - rustc_hir_analysis[c4ab2add954ac9f7]::check_crate
  44:     0x7a8d60518c47 - rustc_interface[45e847dd6c11ec07]::passes::analysis
  45:     0x7a8d60518787 - rustc_query_impl[f7d6eb8805e88c29]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f7d6eb8805e88c29]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 1usize]>>
  46:     0x7a8d60faf165 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::<rustc_query_impl[f7d6eb8805e88c29]::DynamicConfig<rustc_query_system[bd604859ea317a95]::query::caches::SingleCache<rustc_middle[d85377d387f08e9a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f7d6eb8805e88c29]::plumbing::QueryCtxt, false>
  47:     0x7a8d60faeec9 - rustc_query_impl[f7d6eb8805e88c29]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7a8d60e270ce - rustc_interface[45e847dd6c11ec07]::interface::run_compiler::<core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>, rustc_driver_impl[3b65384176704029]::run_compiler::{closure#0}>::{closure#1}
  49:     0x7a8d60e126c9 - std[2409bda48c37ea6b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[45e847dd6c11ec07]::util::run_in_thread_with_globals<rustc_interface[45e847dd6c11ec07]::util::run_in_thread_pool_with_globals<rustc_interface[45e847dd6c11ec07]::interface::run_compiler<core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>, rustc_driver_impl[3b65384176704029]::run_compiler::{closure#0}>::{closure#1}, core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>>::{closure#0}, core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>>
  50:     0x7a8d60e12478 - <<std[2409bda48c37ea6b]::thread::Builder>::spawn_unchecked_<rustc_interface[45e847dd6c11ec07]::util::run_in_thread_with_globals<rustc_interface[45e847dd6c11ec07]::util::run_in_thread_pool_with_globals<rustc_interface[45e847dd6c11ec07]::interface::run_compiler<core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>, rustc_driver_impl[3b65384176704029]::run_compiler::{closure#0}>::{closure#1}, core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>>::{closure#0}, core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e58631ecc326099b]::result::Result<(), rustc_span[86ddde2698e45e98]::ErrorGuaranteed>>::{closure#2} as core[e58631ecc326099b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x7a8d626137bb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h02edc3183d1b3ab4
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/alloc/src/boxed.rs:2022:9
  52:     0x7a8d626137bb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd14ff6036f87e3a7
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/alloc/src/boxed.rs:2022:9
  53:     0x7a8d626137bb - std::sys::pal::unix::thread::Thread::new::thread_start::he158ab2f3983310c
                               at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/std/src/sys/pal/unix/thread.rs:108:17
  54:     0x7a8d623b255a - <unknown>
  55:     0x7a8d6242fa3c - <unknown>
  56:                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-07T15_33_11-55686.txt` to your bug report

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

query stack during panic:
#0 [specialization_graph_of] building specialization graph of trait `NoOverlap`
#1 [coherent_trait] coherence checking all impls of trait `NoOverlap`
#2 [check_well_formed] checking that `<impl at ice.rs:14:1: 14:37>` is well-formed
#3 [check_mod_type_wf] checking that types are well-formed in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0107, E0275.
For more information about an error, try `rustc --explain E0107`.

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example WG-trait-system-refactor The Rustc Trait System Refactor Initiative labels May 7, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 7, 2024
@compiler-errors compiler-errors self-assigned this May 7, 2024
@matthiaskrgr
Copy link
Member Author

bisects to #124418

@saethlin saethlin removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels May 10, 2024
@bors bors closed this as completed in 71ae7db May 16, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 16, 2024
Rollup merge of rust-lang#124871 - compiler-errors:overflowo, r=lcnr

Don't ICE because recomputing overflow goals during find_best_leaf_obligation causes inference side-effects

See the comments for more info. Reprocessing overflowed obligations may cause *other* goals to go from ambig -> pass/fail, causing an ICE. This suppresses that error, but makes all the overflow obligations messages back to their root obl. That kinda sucks, but 🤷

Fixes rust-lang#124834
Fixes rust-lang#124845

r? lcnr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative
Projects
None yet
4 participants