rust-lang / rust

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

ICE: coherence: `did not expect successful goal when collecting ambiguity errors` #129444

Open matthiaskrgr opened 2 months ago

matthiaskrgr commented 2 months ago

auto-reduced (treereduce-rust):

trait Trait {
    type Assoc;
}

struct W<T: Trait>(*mut T);
impl<T: ?Trait> Trait for W<W<W<T>>> {}

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

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

original:

trait Trait {
    type Assoc;
}

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

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

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

fn main() {}

Version information

rustc 1.82.0-nightly (b5723af34 2024-08-22)
binary: rustc
commit-hash: b5723af3457b9cd3795eeb97e9af2d34964854f2
commit-date: 2024-08-22
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

Command: /home/matthias/.rustup/toolchains/master/bin/rustc -Znext-solver=coherence

Program output

``` error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:11:50 | 11 | impl> NoOverlap for W {} | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs` warning: relaxing a default bound only does something for `?Sized`; all other traits are not bound by default --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:6:9 | 6 | impl Trait for W>> {} | ^^^^^^ error[E0277]: the trait bound `W>: Trait` is not satisfied --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:6:27 | 6 | impl Trait for W>> {} | ^^^^^^^^^^ the trait `Trait` is not implemented for `W>` | note: required by a bound in `W` --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:5:13 | 5 | struct W(*mut T); | ^^^^^ required by this bound in `W` help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | 6 | impl Trait for W>> where W>: Trait {} | ++++++++++++++++++++ error[E0277]: the trait bound `W: Trait` is not satisfied --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:6:27 | 6 | impl Trait for W>> {} | ^^^^^^^^^^ the trait `Trait` is not implemented for `W` | note: required by a bound in `W` --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:5:13 | 5 | struct W(*mut T); | ^^^^^ required by this bound in `W` help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | 6 | impl Trait for W>> where W: Trait {} | +++++++++++++++++ error[E0277]: the trait bound `T: Trait` is not satisfied --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:6:27 | 6 | impl Trait for W>> {} | ^^^^^^^^^^ the trait `Trait` is not implemented for `T` | note: required by a bound in `W` --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:5:13 | 5 | struct W(*mut T); | ^^^^^ required by this bound in `W` error[E0046]: not all trait items implemented, missing: `Assoc` --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:6:1 | 2 | type Assoc; | ---------- `Assoc` from trait ... 6 | impl Trait for W>> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `Assoc` in implementation error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:9:9 | 9 | impl>> NoOverlap for T {} | ^^^^^ expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:1:7 | 1 | trait Trait { | ^^^^^ help: replace the generic bound with the associated type | 9 | impl>> NoOverlap for T {} | +++++++ error: internal compiler error: compiler/rustc_trait_selection/src/solve/fulfill.rs:312:17: did not expect successful goal when collecting ambiguity errors thread 'rustc' panicked at compiler/rustc_trait_selection/src/solve/fulfill.rs:312:17: Box stack backtrace: 0: 0x788166ddae4d - ::fmt::hdeb249d545474f9b 1: 0x788167604cd7 - core::fmt::write::h535343ca954aeccd 2: 0x7881685d2591 - std::io::Write::write_fmt::h73510fadecc39092 3: 0x788166ddd52b - std::panicking::default_hook::{{closure}}::hdc6da51cb88ad27a 4: 0x788166ddd19e - std::panicking::default_hook::h41412ed7496f57e4 5: 0x788165f576e9 - std[ac58f62747036fc1]::panicking::update_hook::>::{closure#0} 6: 0x788166ddde47 - std::panicking::rust_panic_with_hook::h892b2ca9ecc482c2 7: 0x788165f91ce1 - std[ac58f62747036fc1]::panicking::begin_panic::::{closure#0} 8: 0x788165f84ec6 - std[ac58f62747036fc1]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 9: 0x788165f84e76 - std[ac58f62747036fc1]::panicking::begin_panic:: 10: 0x788165f9af01 - ::emit_producing_guarantee 11: 0x788166561a54 - rustc_middle[b76c697a51a06e3f]::util::bug::opt_span_bug_fmt::::{closure#0} 12: 0x78816654766a - rustc_middle[b76c697a51a06e3f]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 13: 0x78816654751b - rustc_middle[b76c697a51a06e3f]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 14: 0x78816403fa80 - rustc_middle[b76c697a51a06e3f]::util::bug::bug_fmt 15: 0x788166c661e6 - >::from_solver_error 16: 0x788166c64fe2 - as rustc_infer[5092c81005b9ad9d]::traits::engine::TraitEngine>::collect_remaining_errors 17: 0x788166be10e4 - as rustc_infer[5092c81005b9ad9d]::traits::engine::TraitEngine>::select_all_or_error 18: 0x788167d97833 - rustc_trait_selection[c2282a9ae94e9bfd]::traits::coherence::overlap 19: 0x78816420dfe1 - ::insert 20: 0x78816423f952 - ::insert 21: 0x7881677d26b4 - rustc_trait_selection[c2282a9ae94e9bfd]::traits::specialize::specialization_graph_provider 22: 0x7881677d2031 - rustc_query_impl[2cebc1718d30e6d2]::plumbing::__rust_begin_short_backtrace::> 23: 0x7881676266f2 - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2cebc1718d30e6d2]::plumbing::QueryCtxt, false> 24: 0x7881681ef910 - rustc_query_impl[2cebc1718d30e6d2]::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace 25: 0x788167e5dc77 - rustc_hir_analysis[bfda1e21ad19cc85]::coherence::coherent_trait 26: 0x788167e5d989 - rustc_query_impl[2cebc1718d30e6d2]::plumbing::__rust_begin_short_backtrace::> 27: 0x7881679a14d2 - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2cebc1718d30e6d2]::plumbing::QueryCtxt, false> 28: 0x7881679a3871 - rustc_query_impl[2cebc1718d30e6d2]::query_impl::coherent_trait::get_query_non_incr::__rust_end_short_backtrace 29: 0x788164bd28a8 - rustc_hir_analysis[bfda1e21ad19cc85]::check::wfcheck::check_well_formed 30: 0x7881679b6d27 - rustc_query_impl[2cebc1718d30e6d2]::plumbing::__rust_begin_short_backtrace::> 31: 0x7881679b6fb4 - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2cebc1718d30e6d2]::plumbing::QueryCtxt, false> 32: 0x7881679b6d06 - rustc_query_impl[2cebc1718d30e6d2]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace 33: 0x7881679b7acb - rustc_hir_analysis[bfda1e21ad19cc85]::check::wfcheck::check_mod_type_wf 34: 0x7881679b7909 - rustc_query_impl[2cebc1718d30e6d2]::plumbing::__rust_begin_short_backtrace::> 35: 0x78816846a83b - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2cebc1718d30e6d2]::plumbing::QueryCtxt, false> 36: 0x78816846a5ed - rustc_query_impl[2cebc1718d30e6d2]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace 37: 0x788167bd240d - rustc_hir_analysis[bfda1e21ad19cc85]::check_crate 38: 0x788167bcfb7f - rustc_interface[c97eda6d5aa6852e]::passes::run_required_analyses 39: 0x7881681773de - rustc_interface[c97eda6d5aa6852e]::passes::analysis 40: 0x7881681773b1 - rustc_query_impl[2cebc1718d30e6d2]::plumbing::__rust_begin_short_backtrace::> 41: 0x7881685840ae - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[2cebc1718d30e6d2]::plumbing::QueryCtxt, false> 42: 0x788168583e0f - rustc_query_impl[2cebc1718d30e6d2]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 43: 0x7881683f67aa - rustc_interface[c97eda6d5aa6852e]::interface::run_compiler::, rustc_driver_impl[6eb08f12fed63020]::run_compiler::{closure#0}>::{closure#1} 44: 0x788168312450 - std[ac58f62747036fc1]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[6eb08f12fed63020]::run_compiler::{closure#0}>::{closure#1}, core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>>::{closure#0}, core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>> 45: 0x788168312aba - <::spawn_unchecked_, rustc_driver_impl[6eb08f12fed63020]::run_compiler::{closure#0}>::{closure#1}, core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>>::{closure#0}, core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>>::{closure#1} as core[52832522425d02a4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 46: 0x788168312e2b - std::sys::pal::unix::thread::Thread::new::thread_start::hb624315ea7c850da 47: 0x788169c1839d - 48: 0x788169c9d49c - 49: 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: rustc 1.82.0-nightly (b5723af34 2024-08-22) running on x86_64-unknown-linux-gnu note: compiler flags: -Z next-solver=coherence -Z dump-mir-dir=dir query stack during panic: #0 [specialization_graph_of] building specialization graph of trait `NoOverlap` #1 [coherent_trait] coherence checking all impls of trait `NoOverlap` end of query stack error: aborting due to 7 previous errors; 1 warning emitted Some errors have detailed explanations: E0046, E0107, E0277, E0601. For more information about an error, try `rustc --explain E0046`. ```

matthiaskrgr commented 2 months ago

123737 cc @compiler-errors ^^