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 successful goal when collecting ambiguity errors #129444

Closed
matthiaskrgr opened this issue Aug 23, 2024 · 1 comment · Fixed by #133493
Closed
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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 (-Znext-solver)

Comments

@matthiaskrgr
Copy link
Member

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<T: Trait<Assoc = u32>> NoOverlap for W<T> {}
   |                                                  ^ 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<T: ?Trait> Trait for W<W<W<T>>> {}
  |         ^^^^^^

error[E0277]: the trait bound `W<W<T>>: Trait` is not satisfied
 --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:6:27
  |
6 | impl<T: ?Trait> Trait for W<W<W<T>>> {}
  |                           ^^^^^^^^^^ the trait `Trait` is not implemented for `W<W<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<T: Trait>(*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<T: ?Trait> Trait for W<W<W<T>>> where W<W<T>>: Trait {}
  |                                      ++++++++++++++++++++

error[E0277]: the trait bound `W<T>: Trait` is not satisfied
 --> /tmp/icemaker_global_tempdir.uj5nuH7lbwOu/rustc_testrunner_tmpdir_reporting.2yKo0ecHB9Wi/mvce.rs:6:27
  |
6 | impl<T: ?Trait> Trait for W<W<W<T>>> {}
  |                           ^^^^^^^^^^ the trait `Trait` is not implemented for `W<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<T: Trait>(*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<T: ?Trait> Trait for W<W<W<T>>> where W<T>: 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<T: ?Trait> Trait for W<W<W<T>>> {}
  |                           ^^^^^^^^^^ 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<T: Trait>(*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<T: ?Trait> Trait for W<W<W<T>>> {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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<T: Trait<W<T>>> 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<T: Trait<Assoc = W<T>>> 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<dyn Any>
stack backtrace:
   0:     0x788166ddae4d - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::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::<alloc[11f309e0bb526163]::boxed::Box<rustc_driver_impl[6eb08f12fed63020]::install_ice_hook::{closure#0}>>::{closure#0}
   6:     0x788166ddde47 - std::panicking::rust_panic_with_hook::h892b2ca9ecc482c2
   7:     0x788165f91ce1 - std[ac58f62747036fc1]::panicking::begin_panic::<rustc_errors[70b70b90171074f7]::ExplicitBug>::{closure#0}
   8:     0x788165f84ec6 - std[ac58f62747036fc1]::sys::backtrace::__rust_end_short_backtrace::<std[ac58f62747036fc1]::panicking::begin_panic<rustc_errors[70b70b90171074f7]::ExplicitBug>::{closure#0}, !>
   9:     0x788165f84e76 - std[ac58f62747036fc1]::panicking::begin_panic::<rustc_errors[70b70b90171074f7]::ExplicitBug>
  10:     0x788165f9af01 - <rustc_errors[70b70b90171074f7]::diagnostic::BugAbort as rustc_errors[70b70b90171074f7]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x788166561a54 - rustc_middle[b76c697a51a06e3f]::util::bug::opt_span_bug_fmt::<rustc_span[6b042fc4ff4f2559]::span_encoding::Span>::{closure#0}
  12:     0x78816654766a - rustc_middle[b76c697a51a06e3f]::ty::context::tls::with_opt::<rustc_middle[b76c697a51a06e3f]::util::bug::opt_span_bug_fmt<rustc_span[6b042fc4ff4f2559]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x78816654751b - rustc_middle[b76c697a51a06e3f]::ty::context::tls::with_context_opt::<rustc_middle[b76c697a51a06e3f]::ty::context::tls::with_opt<rustc_middle[b76c697a51a06e3f]::util::bug::opt_span_bug_fmt<rustc_span[6b042fc4ff4f2559]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x78816403fa80 - rustc_middle[b76c697a51a06e3f]::util::bug::bug_fmt
  15:     0x788166c661e6 - <rustc_trait_selection[c2282a9ae94e9bfd]::traits::FulfillmentError as rustc_infer[5092c81005b9ad9d]::traits::engine::FromSolverError<rustc_trait_selection[c2282a9ae94e9bfd]::solve::fulfill::NextSolverError>>::from_solver_error
  16:     0x788166c64fe2 - <rustc_trait_selection[c2282a9ae94e9bfd]::solve::fulfill::FulfillmentCtxt<rustc_trait_selection[c2282a9ae94e9bfd]::traits::FulfillmentError> as rustc_infer[5092c81005b9ad9d]::traits::engine::TraitEngine<rustc_trait_selection[c2282a9ae94e9bfd]::traits::FulfillmentError>>::collect_remaining_errors
  17:     0x788166be10e4 - <rustc_trait_selection[c2282a9ae94e9bfd]::solve::fulfill::FulfillmentCtxt<rustc_trait_selection[c2282a9ae94e9bfd]::traits::FulfillmentError> as rustc_infer[5092c81005b9ad9d]::traits::engine::TraitEngine<rustc_trait_selection[c2282a9ae94e9bfd]::traits::FulfillmentError>>::select_all_or_error
  18:     0x788167d97833 - rustc_trait_selection[c2282a9ae94e9bfd]::traits::coherence::overlap
  19:     0x78816420dfe1 - <rustc_middle[b76c697a51a06e3f]::traits::specialization_graph::Children as rustc_trait_selection[c2282a9ae94e9bfd]::traits::specialize::specialization_graph::ChildrenExt>::insert
  20:     0x78816423f952 - <rustc_middle[b76c697a51a06e3f]::traits::specialization_graph::Graph as rustc_trait_selection[c2282a9ae94e9bfd]::traits::specialize::specialization_graph::GraphExt>::insert
  21:     0x7881677d26b4 - rustc_trait_selection[c2282a9ae94e9bfd]::traits::specialize::specialization_graph_provider
  22:     0x7881677d2031 - rustc_query_impl[2cebc1718d30e6d2]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2cebc1718d30e6d2]::query_impl::specialization_graph_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 8usize]>>
  23:     0x7881676266f2 - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::<rustc_query_impl[2cebc1718d30e6d2]::DynamicConfig<rustc_query_system[24391e8f04765b17]::query::caches::DefIdCache<rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 8usize]>>, 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::<rustc_query_impl[2cebc1718d30e6d2]::query_impl::coherent_trait::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7881679a14d2 - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::<rustc_query_impl[2cebc1718d30e6d2]::DynamicConfig<rustc_query_system[24391e8f04765b17]::query::caches::DefIdCache<rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 1usize]>>, 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::<rustc_query_impl[2cebc1718d30e6d2]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 1usize]>>
  31:     0x7881679b6fb4 - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::<rustc_query_impl[2cebc1718d30e6d2]::DynamicConfig<rustc_query_system[24391e8f04765b17]::query::caches::VecCache<rustc_hir[395b703df744eea0]::hir_id::OwnerId, rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 1usize]>>, 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::<rustc_query_impl[2cebc1718d30e6d2]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 1usize]>>
  35:     0x78816846a83b - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::<rustc_query_impl[2cebc1718d30e6d2]::DynamicConfig<rustc_query_system[24391e8f04765b17]::query::caches::DefaultCache<rustc_span[6b042fc4ff4f2559]::def_id::LocalModDefId, rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 1usize]>>, 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::<rustc_query_impl[2cebc1718d30e6d2]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 1usize]>>
  41:     0x7881685840ae - rustc_query_system[24391e8f04765b17]::query::plumbing::try_execute_query::<rustc_query_impl[2cebc1718d30e6d2]::DynamicConfig<rustc_query_system[24391e8f04765b17]::query::caches::SingleCache<rustc_middle[b76c697a51a06e3f]::query::erase::Erased<[u8; 1usize]>>, 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::<core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>, rustc_driver_impl[6eb08f12fed63020]::run_compiler::{closure#0}>::{closure#1}
  44:     0x788168312450 - std[ac58f62747036fc1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c97eda6d5aa6852e]::util::run_in_thread_with_globals<rustc_interface[c97eda6d5aa6852e]::util::run_in_thread_pool_with_globals<rustc_interface[c97eda6d5aa6852e]::interface::run_compiler<core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>, 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 - <<std[ac58f62747036fc1]::thread::Builder>::spawn_unchecked_<rustc_interface[c97eda6d5aa6852e]::util::run_in_thread_with_globals<rustc_interface[c97eda6d5aa6852e]::util::run_in_thread_pool_with_globals<rustc_interface[c97eda6d5aa6852e]::interface::run_compiler<core[52832522425d02a4]::result::Result<(), rustc_span[6b042fc4ff4f2559]::ErrorGuaranteed>, 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 - <unknown>
  48:     0x788169c9d49c - <unknown>
  49:                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: 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 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. labels Aug 23, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 23, 2024
@matthiaskrgr
Copy link
Member Author

#123737 cc @compiler-errors ^^

@compiler-errors compiler-errors added WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 23, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Sep 1, 2024
@bors bors closed this as completed in 762a661 Nov 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Nov 27, 2024
Rollup merge of rust-lang#133493 - lcnr:fulfill-fudge, r=compiler-errors

do not constrain infer vars in `find_best_leaf_obligation`

This ended up causing an ICE by making the following code path reachable by incorrectly constraining an inference variable while computing the best obligation for a preceding ambiguity. Closes rust-lang#129444.

https://github.com/rust-lang/rust/blob/f2abf827c128120ed7a874d02973947968c158b8/compiler/rustc_trait_selection/src/solve/fulfill.rs#L312-L314

I have to be honest, I don't fully understand how that change removes all the additional diagnostics :3

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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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 (-Znext-solver)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants