rust-lang / rust

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

ICE: specialization graph: `unexpected infer in QueryInput` #123155

Closed matthiaskrgr closed 5 months ago

matthiaskrgr commented 5 months ago

auto-reduced (treereduce-rust):

#![feature(with_negative_coherence)]

pub trait ContainsKey<const K: &'static str> {}

pub trait KeySchema {}

pub struct KeyCons<Tail, const KEY_ID: &'static str> {}

impl<Tail> ContainsKeyHelper<false, K> for KeyCons<Tail, KEY_ID> where
    Tail: KeySchema + ContainsKey<K>
{
}

pub trait ContainsKeyHelper {}

impl<Tail, const KEY_ID: &'static str> ContainsKeyHelper<false, K> for KeyCons<Tail, KEY_ID> where
    Tail: KeySchema + ContainsKey<false, K>
{
}

original:

#![feature(with_negative_coherence)]

pub trait ContainsKey<const K: &'static str> {}

pub trait KeySchema {}

pub struct KeyCons<Tail, const KEY_ID: &'static str> {}

impl<Tail, const KEY_ID: &'static str> ContainsKeyHelper<false, K> for KeyCons<Tail, KEY_ID> where
    Tail: KeySchema + ContainsKey<K>
{
}

pub trait ContainsKeyHelper<const IS_EQUAL: bool> {}

impl<Tail, const KEY_ID: &'static str> ContainsKeyHelper<false, K> for KeyCons<Tail, KEY_ID> where
    Tail: KeySchema + ContainsKey<false, K>
{
}

Version information

rustc 1.79.0-nightly (463a11bef 2024-03-28)
binary: rustc
commit-hash: 463a11bef4d6378439afebf2a9543aef36ccf2c1
commit-date: 2024-03-28
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Command: /home/matthias/.rustup/toolchains/master/bin/rustc

Program output

``` error[E0412]: cannot find type `K` in this scope --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:9:37 | 9 | impl ContainsKeyHelper for KeyCons where | ^ not found in this scope | help: you might be missing a type parameter | 9 | impl ContainsKeyHelper for KeyCons where | +++ error[E0412]: cannot find type `KEY_ID` in this scope --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:9:58 | 9 | impl ContainsKeyHelper for KeyCons where | ^^^^^^ not found in this scope | help: you might be missing a type parameter | 9 | impl ContainsKeyHelper for KeyCons where | ++++++++ error[E0412]: cannot find type `K` in this scope --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:10:35 | 10 | Tail: KeySchema + ContainsKey | ^ not found in this scope | help: you might be missing a type parameter | 9 | impl ContainsKeyHelper for KeyCons where | +++ error[E0412]: cannot find type `K` in this scope --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:16:65 | 16 | impl ContainsKeyHelper for KeyCons where | ^ not found in this scope | help: you might be missing a type parameter | 16 | impl ContainsKeyHelper for KeyCons where | +++ error[E0412]: cannot find type `K` in this scope --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:17:42 | 17 | Tail: KeySchema + ContainsKey | ^ not found in this scope | help: you might be missing a type parameter | 16 | impl ContainsKeyHelper for KeyCons where | +++ error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:19:2 | 19 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs` error: `&'static str` is forbidden as the type of a const generic parameter --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:3:32 | 3 | pub trait ContainsKey {} | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | 3 + #![feature(adt_const_params)] | error[E0392]: type parameter `Tail` is never used --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:7:20 | 7 | pub struct KeyCons {} | ^^^^ unused type parameter | = help: consider removing `Tail`, referring to it in a field, or using a marker such as `PhantomData` = help: if you intended `Tail` to be a const parameter, use `const Tail: /* Type */` instead error: `&'static str` is forbidden as the type of a const generic parameter --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:7:40 | 7 | pub struct KeyCons {} | ^^^^^^^^^^^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | 3 + #![feature(adt_const_params)] | error[E0747]: unresolved item provided when a constant was expected --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:9:58 | 9 | impl ContainsKeyHelper for KeyCons where | ^^^^^^ | help: if this generic argument was intended as a const parameter, surround it with braces | 9 | impl ContainsKeyHelper for KeyCons where | + + error[E0107]: trait takes 0 generic arguments but 2 generic arguments were supplied --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:9:12 | 9 | impl ContainsKeyHelper for KeyCons where | ^^^^^^^^^^^^^^^^^---------- help: remove these generics | | | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:14:11 | 14 | pub trait ContainsKeyHelper {} | ^^^^^^^^^^^^^^^^^ error[E0747]: unresolved item provided when a constant was expected --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:10:35 | 10 | Tail: KeySchema + ContainsKey | ^ | help: if this generic argument was intended as a const parameter, surround it with braces | 10 | Tail: KeySchema + ContainsKey<{ K }> | + + error[E0107]: trait takes 0 generic arguments but 2 generic arguments were supplied --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:16:40 | 16 | impl ContainsKeyHelper for KeyCons where | ^^^^^^^^^^^^^^^^^---------- help: remove these generics | | | expected 0 generic arguments | note: trait defined here, with 0 generic parameters --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:14:11 | 14 | pub trait ContainsKeyHelper {} | ^^^^^^^^^^^^^^^^^ error[E0107]: trait takes 1 generic argument but 2 generic arguments were supplied --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:17:23 | 17 | Tail: KeySchema + ContainsKey | ^^^^^^^^^^^ - help: remove this generic argument | | | expected 1 generic argument | note: trait defined here, with 1 generic parameter: `K` --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:3:11 | 3 | pub trait ContainsKey {} | ^^^^^^^^^^^ --------------------- thread 'rustc' panicked at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/compiler/rustc_next_trait_solver/src/canonicalizer.rs:67:9: unexpected infer in QueryInput { goal: Goal { predicate: Binder { value: NormalizesTo(AliasTy { args: [], def_id: DefId(0:16 ~ mvce[cf35]::{impl#1}::{constant#0}) }, Term::Ct(^1_0: &'?0 str)), bound_vars: [] }, param_env: ParamEnv { caller_bounds: [Binder { value: TraitPredicate(<^1_1 as ContainsKey<{const error}>>, polarity:Positive), bound_vars: [] }, Binder { value: TraitPredicate(<^1_1 as KeySchema>, polarity:Positive), bound_vars: [] }, Binder { value: TraitPredicate(<^1_1 as std::marker::Sized>, polarity:Positive), bound_vars: [] }], reveal: UserFacing } }, anchor: Bind([]), predefined_opaques_in_body: PredefinedOpaques(PredefinedOpaquesData { opaque_types: [] }) } stack backtrace: 0: 0x7cd0fcffd2a5 - std::backtrace_rs::backtrace::libunwind::trace::hc9ad77caa68248e0 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5 1: 0x7cd0fcffd2a5 - std::backtrace_rs::backtrace::trace_unsynchronized::hdb167fe848110c22 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7cd0fcffd2a5 - std::sys_common::backtrace::_print_fmt::hf60d026528b44cae at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7cd0fcffd2a5 - ::fmt::h77057cdf9abd0a3b at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7cd0fd04e64b - core::fmt::rt::Argument::fmt::h2d5682051c912193 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/core/src/fmt/rt.rs:142:9 5: 0x7cd0fd04e64b - core::fmt::write::h91045f17dad5810f at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/core/src/fmt/mod.rs:1153:17 6: 0x7cd0fcff1f0f - std::io::Write::write_fmt::h9aaeb0d030b375cc at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/io/mod.rs:1843:15 7: 0x7cd0fcffd07e - std::sys_common::backtrace::_print::hcbf63c33da44def2 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7cd0fcffd07e - std::sys_common::backtrace::print::h53b1e15a738ad4ac at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7cd0fcfffd29 - std::panicking::default_hook::{{closure}}::h08fdf489308ec011 10: 0x7cd0fcfffa93 - std::panicking::default_hook::h0eff550faf8f8601 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/panicking.rs:292:9 11: 0x7cd0f99fa06e - std[598b8342d1a3a4e8]::panicking::update_hook::>::{closure#0} 12: 0x7cd0fd00042c - as core::ops::function::Fn>::call::h20a693632b460b24 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/alloc/src/boxed.rs:2032:9 13: 0x7cd0fd00042c - std::panicking::rust_panic_with_hook::hefd953fb72b64219 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/panicking.rs:793:13 14: 0x7cd0fd0001d6 - std::panicking::begin_panic_handler::{{closure}}::hdc56613d7db54a00 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/panicking.rs:658:13 15: 0x7cd0fcffd769 - std::sys_common::backtrace::__rust_end_short_backtrace::hb81e2ffdefb458a7 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/sys_common/backtrace.rs:171:18 16: 0x7cd0fcffff07 - rust_begin_unwind at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/panicking.rs:646:5 17: 0x7cd0fd04aae6 - core::panicking::panic_fmt::h9e3c9a0f50b4a31d at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/core/src/panicking.rs:72:14 18: 0x7cd0fa4c902b - ::canonicalize_goal:: 19: 0x7cd0fa4ccb6b - ::evaluate_goal_raw 20: 0x7cd0fa5105e4 - ::try_evaluate_added_goals 21: 0x7cd0fa50b640 - ::try_normalize_term 22: 0x7cd0fa4dbbf9 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>::{closure#3} 23: 0x7cd0fa4d90e6 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 24: 0x7cd0fa4cce27 - ::evaluate_goal_raw 25: 0x7cd0fa4cca82 - ::evaluate_goal 26: 0x7cd0fa510c9d - ::try_evaluate_added_goals 27: 0x7cd0fa50bca2 - ::evaluate_added_goals_and_make_canonical_response 28: 0x7cd0fa4dfcac - ::probe_and_match_goal_against_assumption::<::consider_implied_clause<[rustc_middle[13a917e17ab0fec8]::traits::solve::Goal; 0usize]>::{closure#0}> 29: 0x7cd0fa50b9d8 - ::assemble_param_env_candidates:: 30: 0x7cd0fa4c6dcc - ::assemble_and_evaluate_candidates:: 31: 0x7cd0fa4dbe1e - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>::{closure#3} 32: 0x7cd0fa4d90e6 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 33: 0x7cd0fa4cce27 - ::evaluate_goal_raw 34: 0x7cd0fa4cca82 - ::evaluate_goal 35: 0x7cd0fa4cc7d3 - ::enter_root::, ::evaluate_root_goal::{closure#0}> 36: 0x7cd0fa4cf244 - ::select_where_possible 37: 0x7cd0fa491540 - ::select_all_or_error 38: 0x7cd0fa4eaecc - rustc_trait_selection[f9161e542b264224]::traits::coherence::impl_intersection_has_negative_obligation 39: 0x7cd0fb49cb09 - rustc_trait_selection[f9161e542b264224]::traits::coherence::overlap 40: 0x7cd0fbb6e0a4 - ::insert 41: 0x7cd0f87b4f4b - ::insert 42: 0x7cd0fafcca05 - rustc_trait_selection[f9161e542b264224]::traits::specialize::specialization_graph_provider 43: 0x7cd0fafcc55d - rustc_query_impl[1ebd684e80feb137]::plumbing::__rust_begin_short_backtrace::> 44: 0x7cd0fafcf01e - rustc_query_system[47def78e3fe379f5]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1ebd684e80feb137]::plumbing::QueryCtxt, false> 45: 0x7cd0fb5429de - rustc_query_impl[1ebd684e80feb137]::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace 46: 0x7cd0fb60d8f1 - rustc_hir_analysis[cf06ecc502e6f33f]::coherence::coherent_trait 47: 0x7cd0fb60d5e7 - rustc_query_impl[1ebd684e80feb137]::plumbing::__rust_begin_short_backtrace::> 48: 0x7cd0fb107810 - rustc_query_system[47def78e3fe379f5]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1ebd684e80feb137]::plumbing::QueryCtxt, false> 49: 0x7cd0fb4326d7 - rustc_query_impl[1ebd684e80feb137]::query_impl::coherent_trait::get_query_non_incr::__rust_end_short_backtrace 50: 0x7cd0fb44502b - rustc_hir_analysis[cf06ecc502e6f33f]::check::wfcheck::check_well_formed 51: 0x7cd0fb442deb - rustc_query_impl[1ebd684e80feb137]::plumbing::__rust_begin_short_backtrace::> 52: 0x7cd0fb442580 - rustc_query_system[47def78e3fe379f5]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1ebd684e80feb137]::plumbing::QueryCtxt, false> 53: 0x7cd0fb4422ff - rustc_query_impl[1ebd684e80feb137]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace 54: 0x7cd0fb44023a - rustc_hir_analysis[cf06ecc502e6f33f]::check::wfcheck::check_mod_type_wf 55: 0x7cd0fb440061 - rustc_query_impl[1ebd684e80feb137]::plumbing::__rust_begin_short_backtrace::> 56: 0x7cd0fb8ca2b0 - rustc_query_system[47def78e3fe379f5]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1ebd684e80feb137]::plumbing::QueryCtxt, false> 57: 0x7cd0fb8ca05b - rustc_query_impl[1ebd684e80feb137]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace 58: 0x7cd0fafe503f - rustc_hir_analysis[cf06ecc502e6f33f]::check_crate 59: 0x7cd0fb356daa - rustc_interface[af68b54697b6df15]::passes::analysis 60: 0x7cd0fb356913 - rustc_query_impl[1ebd684e80feb137]::plumbing::__rust_begin_short_backtrace::> 61: 0x7cd0fbbd8365 - rustc_query_system[47def78e3fe379f5]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1ebd684e80feb137]::plumbing::QueryCtxt, false> 62: 0x7cd0fbbd80c9 - rustc_query_impl[1ebd684e80feb137]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 63: 0x7cd0fba84685 - rustc_interface[af68b54697b6df15]::interface::run_compiler::, rustc_driver_impl[69f15d569c4f2de1]::run_compiler::{closure#0}>::{closure#0} 64: 0x7cd0fbb73663 - std[598b8342d1a3a4e8]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[69f15d569c4f2de1]::run_compiler::{closure#0}>::{closure#0}, core[aba9afb3109def9a]::result::Result<(), rustc_span[a52ae730658d6744]::ErrorGuaranteed>>::{closure#0}, core[aba9afb3109def9a]::result::Result<(), rustc_span[a52ae730658d6744]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[aba9afb3109def9a]::result::Result<(), rustc_span[a52ae730658d6744]::ErrorGuaranteed>> 65: 0x7cd0fbb73490 - <::spawn_unchecked_, rustc_driver_impl[69f15d569c4f2de1]::run_compiler::{closure#0}>::{closure#0}, core[aba9afb3109def9a]::result::Result<(), rustc_span[a52ae730658d6744]::ErrorGuaranteed>>::{closure#0}, core[aba9afb3109def9a]::result::Result<(), rustc_span[a52ae730658d6744]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[aba9afb3109def9a]::result::Result<(), rustc_span[a52ae730658d6744]::ErrorGuaranteed>>::{closure#1} as core[aba9afb3109def9a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 66: 0x7cd0fd009d89 - as core::ops::function::FnOnce>::call_once::h0da6186c2c724e12 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/alloc/src/boxed.rs:2018:9 67: 0x7cd0fd009d89 - as core::ops::function::FnOnce>::call_once::hb8df2349f2e6b3c3 at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/alloc/src/boxed.rs:2018:9 68: 0x7cd0fd009d89 - std::sys::pal::unix::thread::Thread::new::thread_start::hd76932c3803a914a at /rustc/463a11bef4d6378439afebf2a9543aef36ccf2c1/library/std/src/sys/pal/unix/thread.rs:108:17 69: 0x7cd0f68a955a - 70: 0x7cd0f6926a3c - 71: 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: rustc 1.79.0-nightly (463a11bef 2024-03-28) running on x86_64-unknown-linux-gnu query stack during panic: #0 [specialization_graph_of] building specialization graph of trait `ContainsKeyHelper` #1 [coherent_trait] coherence checking all impls of trait `ContainsKeyHelper` #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[E0308]: mismatched types --> /tmp/icemaker_global_tempdir.GJcVylPrIFuu/rustc_testrunner_tmpdir_reporting.nT7ghpao5shm/mvce.rs:17:35 | 17 | Tail: KeySchema + ContainsKey | ^^^^^ expected `&str`, found `bool` error: aborting due to 15 previous errors Some errors have detailed explanations: E0107, E0308, E0392, E0412, E0601, E0747. For more information about an error, try `rustc --explain E0107`. ```

matthiaskrgr commented 5 months ago

bisects to #120498 cc @compiler-errors

compiler-errors commented 5 months ago

This should get minimized more

matthiaskrgr commented 5 months ago

hmm, bit smaller:

#![feature(with_negative_coherence)]

pub trait A<const K: &'static str> {}

pub struct B<Tail> {}

impl<Tail> C<K> for B<Tail> where Tail: A<K> {}

pub trait C {}

impl<Tail, const KEY_ID: &'static str> C<K> for B<Tail> where Tail: A<false, K> {}
compiler-errors commented 5 months ago

There's still an overwhelming number of compiler errors that can be suppressed very easily, and that really occlude the underlying issue (type mismatch in a const generic parameter). That's what I mean by minimization:

#![feature(with_negative_coherence)]

pub trait A<const K: &'static str> {}
pub trait C {}

impl<T> C for T where T: A<""> {}
impl<T> C for T where T: A<false> {}