rust-lang / rust

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

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

Closed matthiaskrgr closed 5 months ago

matthiaskrgr commented 6 months ago

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 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 - ::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::>::{closure#0} 12: 0x7a8d62609976 - as core::ops::function::Fn>::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::::{closure#0} 15: 0x7a8d5eee0686 - std[2409bda48c37ea6b]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7a8d5eedbc66 - std[2409bda48c37ea6b]::panicking::begin_panic:: 17: 0x7a8d5eeece61 - ::emit_producing_guarantee 18: 0x7a8d5f3a04fc - rustc_middle[d85377d387f08e9a]::util::bug::opt_span_bug_fmt::::{closure#0} 19: 0x7a8d5f384eca - rustc_middle[d85377d387f08e9a]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 20: 0x7a8d5f384d4b - rustc_middle[d85377d387f08e9a]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 21: 0x7a8d5d09cdd0 - rustc_middle[d85377d387f08e9a]::util::bug::bug_fmt 22: 0x7a8d5f9d8dd7 - ::collect_remaining_errors 23: 0x7a8d60575ba8 - ::select_all_or_error 24: 0x7a8d607198de - rustc_trait_selection[e301c94095ae1ef9]::traits::coherence::overlap 25: 0x7a8d60e75591 - ::insert 26: 0x7a8d5dedfa68 - ::insert 27: 0x7a8d602866bc - rustc_trait_selection[e301c94095ae1ef9]::traits::specialize::specialization_graph_provider 28: 0x7a8d6028621f - rustc_query_impl[f7d6eb8805e88c29]::plumbing::__rust_begin_short_backtrace::> 29: 0x7a8d60288c17 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::>, 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::> 33: 0x7a8d606bb793 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::>, 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::> 37: 0x7a8d60812b40 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::>, 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::> 41: 0x7a8d60fb48c6 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::>, 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::> 46: 0x7a8d60faf165 - rustc_query_system[bd604859ea317a95]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[3b65384176704029]::run_compiler::{closure#0}>::{closure#1} 49: 0x7a8d60e126c9 - std[2409bda48c37ea6b]::sys_common::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - as core::ops::function::FnOnce>::call_once::h02edc3183d1b3ab4 at /rustc/7d83a4c131ab9ae81a74c6fd825c827d74a2881d/library/alloc/src/boxed.rs:2022:9 52: 0x7a8d626137bb - as core::ops::function::FnOnce>::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 - 55: 0x7a8d6242fa3c - 56: 0x0 - 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 `` 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 commented 6 months ago

bisects to #124418