rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
93.58k stars 12.05k forks source link

ICE: Next coherence: called `Result::unwrap()` on an `Err` value: Sorts(ExpectedFound { expected: (), found: str }) #124791

Closed fmease closed 1 week ago

fmease commented 1 week ago

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 - ::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::>::{closure#0} 12: 0x7f3966b8f996 - as core::ops::function::Fn>::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 - ::unify_query_var_values 20: 0x7f396bc3f741 - ::instantiate_nested_goals 21: 0x7f396a7e975e - ::visit_goal 22: 0x7f396a7e97f3 - ::visit_goal 23: 0x7f396a7e97f3 - ::visit_goal 24: 0x7f396a7e97f3 - ::visit_goal 25: 0x7f396b57201a - rustc_trait_selection[6bd5f21d8d80d48f]::traits::coherence::overlap 26: 0x7f396bc8a248 - ::insert 27: 0x7f396867a488 - ::insert 28: 0x7f396b08447c - rustc_trait_selection[6bd5f21d8d80d48f]::traits::specialize::specialization_graph_provider 29: 0x7f396b083fdf - rustc_query_impl[b4be295015ca8fb2]::plumbing::__rust_begin_short_backtrace::> 30: 0x7f396b0869d7 - rustc_query_system[e6c56b7dd6267367]::query::plumbing::try_execute_query::>, 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 - ::ancestors 33: 0x7f396b61eff9 - rustc_hir_analysis[5c82ccef5ad3385e]::check::wfcheck::check_well_formed 34: 0x7f396b61c26d - rustc_query_impl[b4be295015ca8fb2]::plumbing::__rust_begin_short_backtrace::> 35: 0x7f396b61ba00 - rustc_query_system[e6c56b7dd6267367]::query::plumbing::try_execute_query::>, 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::> 39: 0x7f396bdc0786 - rustc_query_system[e6c56b7dd6267367]::query::plumbing::try_execute_query::>, 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::> 44: 0x7f396bdbb025 - rustc_query_system[e6c56b7dd6267367]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[cb5cb60ec49302dc]::run_compiler::{closure#0}>::{closure#1} 47: 0x7f396bc06889 - std[54c5d3e34c069c08]::sys_common::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - as core::ops::function::FnOnce>::call_once::h82bad4f6994c816b at /rustc/e82c861d7e5ecd766cb0dab0bf622445dec999dc/library/alloc/src/boxed.rs:2022:9 50: 0x7f3966b997eb - as core::ops::function::FnOnce>::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 - 53: 0x7f3966a047cc - 54: 0x0 - 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 `` 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 e27af2917b80487e9c0de00118fdcb9ccb1177f9 (i.e., HEAD~1 wrt. to an earlier iteration of PR #121848)
  2. Reproduces on nightly (9c9b568792ef20d8459c745345dd3e79b7c7fa8c)
  3. Reproduces on master (96f1da82687f499dd3f57006ae71548714532382)
fmease commented 1 week ago

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

fmease commented 1 week ago

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