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: Next coherence: called Result::unwrap() on an Err value: Sorts(ExpectedFound { expected: (), found: str }) #124791

Closed
fmease opened this issue May 6, 2024 · 2 comments · Fixed by #124936
Assignees
Labels
C-bug Category: This is a bug. F-specialization `#![feature(specialization)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Comments

@fmease
Copy link
Member

fmease commented May 6, 2024

Context

This was minimized from library/alloc. Relevant to #121848 (the stabilization of -Znext-solver=coherence).

This is related to the open issue #124702 and the closed issue #124422.
However, contrary to those, this issue represents a pass→ICE regression, not just an error→ICE one.
Furthermore, it only uses the feature min_specialization (and not the more general specialization)
as it solely relies on assoc fn specialization (and not assoc type specialization).

Reproducer

rustc allok.rs -Znext-solver=coherence where allok.rs contains:

// #![no_std] // optionally
#![crate_type = "lib"]
#![feature(min_specialization)]
#![allow(dead_code)]

trait Display {}

trait ToOwned {
    type Owned;
}

impl<T> ToOwned for T {
    type Owned = T;
}

struct Cow<B: ?Sized>(B);

impl<B: ?Sized> Display for Cow<B>
where
    B: ToOwned,
    B::Owned: Display,
{
}

impl Display for () {}

trait ToString {
    fn to_string();
}

impl<T: Display + ?Sized> ToString for T {
    default fn to_string() {}
}

impl ToString for Cow<str> {
    fn to_string() {}
}

impl ToOwned for str {
    type Owned = ();
}

Compiler Output

thread 'rustc' panicked at compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs:354:18:
called `Result::unwrap()` on an `Err` value: Sorts(ExpectedFound { expected: (), found: str })
Full compiler output (incl. backtrace)
thread 'rustc' panicked at compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs:354:18:
called `Result::unwrap()` on an `Err` value: Sorts(ExpectedFound { expected: (), found: str })
stack backtrace:
   0:     0x7f3966b8cb55 - std::backtrace_rs::backtrace::libunwind::trace::h31c27f5cd8890956
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7f3966b8cb55 - std::backtrace_rs::backtrace::trace_unsynchronized::ha07b1f1ddca65445
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f3966b8cb55 - std::sys_common::backtrace::_print_fmt::h483b2f8f14ecd78e
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f3966b8cb55 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h90ddf6aa5ba26796
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f3966bdbd6b - core::fmt::rt::Argument::fmt::h37457b6759783b1e
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/core/src/fmt/rt.rs:165:63
   5:     0x7f3966bdbd6b - core::fmt::write::h7a84d347dc46f1df
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/core/src/fmt/mod.rs:1157:21
   6:     0x7f3966b8189f - std::io::Write::write_fmt::h75548018278e1e2d
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/io/mod.rs:1835:15
   7:     0x7f3966b8c92e - std::sys_common::backtrace::_print::hfd2cbf6f93bd2979
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f3966b8c92e - std::sys_common::backtrace::print::h977548a342545762
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f3966b8f299 - std::panicking::default_hook::{{closure}}::hf83accd896299866
  10:     0x7f3966b8efdd - std::panicking::default_hook::h461a18bec2aea8c7
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/panicking.rs:298:9
  11:     0x7f3969cb06ec - std[54c5d3e34c069c08]::panicking::update_hook::<alloc[6626c39146c6add4]::boxed::Box<rustc_driver_impl[cb5cb60ec49302dc]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f3966b8f996 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h30d290371b8f08f7
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/alloc/src/boxed.rs:2036:9
  13:     0x7f3966b8f996 - std::panicking::rust_panic_with_hook::h811d7f93fb5b56a8
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/panicking.rs:799:13
  14:     0x7f3966b8f744 - std::panicking::begin_panic_handler::{{closure}}::h2c83d37cb400439f
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/panicking.rs:664:13
  15:     0x7f3966b8d019 - std::sys_common::backtrace::__rust_end_short_backtrace::hd5859b7327062f1c
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f3966b8f477 - rust_begin_unwind
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/panicking.rs:652:5
  17:     0x7f3966bd8333 - core::panicking::panic_fmt::he7d3af46f65769b3
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/core/src/panicking.rs:72:14
  18:     0x7f3966bd8976 - core::result::unwrap_failed::h4fa3196e36a2fbb4
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/core/src/result.rs:1654:5
  19:     0x7f396bc4b61b - <rustc_trait_selection[6bd5f21d8d80d48f]::solve::eval_ctxt::EvalCtxt>::unify_query_var_values
  20:     0x7f396bc3f741 - <rustc_trait_selection[6bd5f21d8d80d48f]::solve::inspect::analyse::InspectCandidate>::instantiate_nested_goals
  21:     0x7f396a7e975e - <rustc_trait_selection[6bd5f21d8d80d48f]::traits::coherence::AmbiguityCausesVisitor as rustc_trait_selection[6bd5f21d8d80d48f]::solve::inspect::analyse::ProofTreeVisitor>::visit_goal
  22:     0x7f396a7e97f3 - <rustc_trait_selection[6bd5f21d8d80d48f]::traits::coherence::AmbiguityCausesVisitor as rustc_trait_selection[6bd5f21d8d80d48f]::solve::inspect::analyse::ProofTreeVisitor>::visit_goal
  23:     0x7f396a7e97f3 - <rustc_trait_selection[6bd5f21d8d80d48f]::traits::coherence::AmbiguityCausesVisitor as rustc_trait_selection[6bd5f21d8d80d48f]::solve::inspect::analyse::ProofTreeVisitor>::visit_goal
  24:     0x7f396a7e97f3 - <rustc_trait_selection[6bd5f21d8d80d48f]::traits::coherence::AmbiguityCausesVisitor as rustc_trait_selection[6bd5f21d8d80d48f]::solve::inspect::analyse::ProofTreeVisitor>::visit_goal
  25:     0x7f396b57201a - rustc_trait_selection[6bd5f21d8d80d48f]::traits::coherence::overlap
  26:     0x7f396bc8a248 - <rustc_middle[152581898470156b]::traits::specialization_graph::Children as rustc_trait_selection[6bd5f21d8d80d48f]::traits::specialize::specialization_graph::ChildrenExt>::insert
  27:     0x7f396867a488 - <rustc_middle[152581898470156b]::traits::specialization_graph::Graph as rustc_trait_selection[6bd5f21d8d80d48f]::traits::specialize::specialization_graph::GraphExt>::insert
  28:     0x7f396b08447c - rustc_trait_selection[6bd5f21d8d80d48f]::traits::specialize::specialization_graph_provider
  29:     0x7f396b083fdf - rustc_query_impl[b4be295015ca8fb2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b4be295015ca8fb2]::query_impl::specialization_graph_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[152581898470156b]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7f396b0869d7 - rustc_query_system[e6c56b7dd6267367]::query::plumbing::try_execute_query::<rustc_query_impl[b4be295015ca8fb2]::DynamicConfig<rustc_query_system[e6c56b7dd6267367]::query::caches::DefIdCache<rustc_middle[152581898470156b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[b4be295015ca8fb2]::plumbing::QueryCtxt, false>
  31:     0x7f396b7580f2 - rustc_query_impl[b4be295015ca8fb2]::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f396b757a53 - <rustc_middle[152581898470156b]::ty::trait_def::TraitDef>::ancestors
  33:     0x7f396b61eff9 - rustc_hir_analysis[5c82ccef5ad3385e]::check::wfcheck::check_well_formed
  34:     0x7f396b61c26d - rustc_query_impl[b4be295015ca8fb2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b4be295015ca8fb2]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[152581898470156b]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7f396b61ba00 - rustc_query_system[e6c56b7dd6267367]::query::plumbing::try_execute_query::<rustc_query_impl[b4be295015ca8fb2]::DynamicConfig<rustc_query_system[e6c56b7dd6267367]::query::caches::VecCache<rustc_hir[b66080818c936735]::hir_id::OwnerId, rustc_middle[152581898470156b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[b4be295015ca8fb2]::plumbing::QueryCtxt, false>
  36:     0x7f396b61b77f - rustc_query_impl[b4be295015ca8fb2]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f396b6196c1 - rustc_hir_analysis[5c82ccef5ad3385e]::check::wfcheck::check_mod_type_wf
  38:     0x7f396b619507 - rustc_query_impl[b4be295015ca8fb2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b4be295015ca8fb2]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[152581898470156b]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7f396bdc0786 - rustc_query_system[e6c56b7dd6267367]::query::plumbing::try_execute_query::<rustc_query_impl[b4be295015ca8fb2]::DynamicConfig<rustc_query_system[e6c56b7dd6267367]::query::caches::DefaultCache<rustc_span[431df025478c194f]::def_id::LocalModDefId, rustc_middle[152581898470156b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[b4be295015ca8fb2]::plumbing::QueryCtxt, false>
  40:     0x7f396bdc053f - rustc_query_impl[b4be295015ca8fb2]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7f396b3071dc - rustc_hir_analysis[5c82ccef5ad3385e]::check_crate
  42:     0x7f396b2fdc87 - rustc_interface[6cfcedd897ebfba3]::passes::analysis
  43:     0x7f396b2fd7c7 - rustc_query_impl[b4be295015ca8fb2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b4be295015ca8fb2]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[152581898470156b]::query::erase::Erased<[u8; 1usize]>>
  44:     0x7f396bdbb025 - rustc_query_system[e6c56b7dd6267367]::query::plumbing::try_execute_query::<rustc_query_impl[b4be295015ca8fb2]::DynamicConfig<rustc_query_system[e6c56b7dd6267367]::query::caches::SingleCache<rustc_middle[152581898470156b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[b4be295015ca8fb2]::plumbing::QueryCtxt, false>
  45:     0x7f396bdbad89 - rustc_query_impl[b4be295015ca8fb2]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:     0x7f396bc19bce - rustc_interface[6cfcedd897ebfba3]::interface::run_compiler::<core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>, rustc_driver_impl[cb5cb60ec49302dc]::run_compiler::{closure#0}>::{closure#1}
  47:     0x7f396bc06889 - std[54c5d3e34c069c08]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6cfcedd897ebfba3]::util::run_in_thread_with_globals<rustc_interface[6cfcedd897ebfba3]::util::run_in_thread_pool_with_globals<rustc_interface[6cfcedd897ebfba3]::interface::run_compiler<core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>, rustc_driver_impl[cb5cb60ec49302dc]::run_compiler::{closure#0}>::{closure#1}, core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>>::{closure#0}, core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>>
  48:     0x7f396bc06636 - <<std[54c5d3e34c069c08]::thread::Builder>::spawn_unchecked_<rustc_interface[6cfcedd897ebfba3]::util::run_in_thread_with_globals<rustc_interface[6cfcedd897ebfba3]::util::run_in_thread_pool_with_globals<rustc_interface[6cfcedd897ebfba3]::interface::run_compiler<core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>, rustc_driver_impl[cb5cb60ec49302dc]::run_compiler::{closure#0}>::{closure#1}, core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>>::{closure#0}, core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d365900a307aefd6]::result::Result<(), rustc_span[431df025478c194f]::ErrorGuaranteed>>::{closure#2} as core[d365900a307aefd6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:     0x7f3966b997eb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h82bad4f6994c816b
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/alloc/src/boxed.rs:2022:9
  50:     0x7f3966b997eb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8259f63a3422ebdf
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/alloc/src/boxed.rs:2022:9
  51:     0x7f3966b997eb - std::sys::pal::unix::thread::Thread::new::thread_start::hb7744739c9820032
                               at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/std/src/sys/pal/unix/thread.rs:108:17
  52:     0x7f39669809eb - <unknown>
  53:     0x7f3966a047cc - <unknown>
  54:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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 `/home/fmease/programming/rust/rustc-ice-2024-05-06T06_53_45-318190.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 `ToString`
#1 [check_well_formed] checking that `<impl at allok.rs:31:1: 31:41>` 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

Meta

  1. Reproduces with e27af29 (i.e., HEAD~1 wrt. to an earlier iteration of PR #121848)
  2. Reproduces on nightly (9c9b568)
  3. Reproduces on master (96f1da8)
@fmease fmease 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. F-specialization `#![feature(specialization)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-types Relevant to the types team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels May 6, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 6, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 6, 2024
@fmease
Copy link
Member Author

fmease commented May 6, 2024

I think this was fixed at some point, presumably by #124566.
However, it regressed again in #124418 (cc @compiler-errors) similar to #124702.

@fmease
Copy link
Member Author

fmease commented May 6, 2024

I presume #121848 will fail to build library/alloc again after a rebase onto the latest master.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 9, 2024
analyse visitor: build proof tree in probe

see inline comments

fixes rust-lang#124791
fixes rust-lang#124702

r? `@compiler-errors`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 10, 2024
analyse visitor: build proof tree in probe

see inline comments

fixes rust-lang#124791
fixes rust-lang#124702

r? ``@compiler-errors``
@bors bors closed this as completed in 43ddd1d May 10, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 10, 2024
Rollup merge of rust-lang#124936 - lcnr:cool-beans, r=compiler-errors

analyse visitor: build proof tree in probe

see inline comments

fixes rust-lang#124791
fixes rust-lang#124702

r? ```@compiler-errors```
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. F-specialization `#![feature(specialization)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants