Skip to content

Compiler panic related to const generics: "unexpected inference" #98300

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

Closed
tmerr opened this issue Jun 20, 2022 · 3 comments
Closed

Compiler panic related to const generics: "unexpected inference" #98300

tmerr opened this issue Jun 20, 2022 · 3 comments
Labels
C-bug Category: This is a bug. 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.

Comments

@tmerr
Copy link
Contributor

tmerr commented Jun 20, 2022

Compiler panic on rustc 1.63.0-nightly (bb8c2f4 2022-06-19) running on x86_64-unknown-linux-gnu
I've only seen it happen when the function g does not exist.
In my original code that was the only problem (after reducing it to a smaller example the code is more broken, but the panic is the same).

-->

Code

struct S<const K: usize> {
    xs: Vec<[u8; K]>,
}

impl<const K: usize> S<K> {
    fn f(&self, a: [u8; K], cs: i32) -> S<K> {
        g(a).map(|ws| S{xs: ws.to_vec()})
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.63.0-nightly (bb8c2f411 2022-06-19)
binary: rustc
commit-hash: bb8c2f41174caceec00c28bc6c5c20ae9f9a175c
commit-date: 2022-06-19
host: x86_64-unknown-linux-gnu
release: 1.63.0-nightly
LLVM version: 14.0.5

Error output

error[E0425]: cannot find function `g` in this scope
 --> main.rs:7:9
  |
5 | impl<const K: usize> S<K> {
  |            - similarly named const parameter `K` defined here
6 |     fn f(&self, a: [u8; K], cs: i32) -> S<K> {
7 |         g(a).map(|ws| S{xs: ws.to_vec()})
  |         ^ help: a const parameter with a similar name exists: `K`

error: internal compiler error: /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/compiler/rustc_infer/src/infer/nll_relate/mod.rs:665:17: unexpected inference var Const { ty: usize, kind: Infer(Var(_#0c)) }

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/compiler/rustc_errors/src/lib.rs:1391:9
stack backtrace:
   0:     0x7f14678efe8d - std::backtrace_rs::backtrace::libunwind::trace::h7401910188046071
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f14678efe8d - std::backtrace_rs::backtrace::trace_unsynchronized::h8dff7aa2924f24e9
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f14678efe8d - std::sys_common::backtrace::_print_fmt::h07ca90b544a24df2
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f14678efe8d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h9331308a3088c05f
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f146794bc4c - core::fmt::write::h61c349b2e024d424
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/core/src/fmt/mod.rs:1196:17
   5:     0x7f14678e15b1 - std::io::Write::write_fmt::h84ca4b318d095fa7
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/io/mod.rs:1654:15
   6:     0x7f14678f2b55 - std::sys_common::backtrace::_print::hd3c72b1e40e79baf
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f14678f2b55 - std::sys_common::backtrace::print::ha4da5a270383a62c
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f14678f2b55 - std::panicking::default_hook::{{closure}}::h8c6cca5f381817ba
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/panicking.rs:295:22
   9:     0x7f14678f2876 - std::panicking::default_hook::he91089be4e889ce2
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/panicking.rs:314:9
  10:     0x7f14680cb464 - rustc_driver[3c4ddaa230521172]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f14678f322a - std::panicking::rust_panic_with_hook::he7ddebf187262887
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/panicking.rs:702:17
  12:     0x7f1469188d11 - std[92178b8fea183b1]::panicking::begin_panic::<rustc_errors[bc32936de75f68a8]::ExplicitBug>::{closure#0}
  13:     0x7f1469187b36 - std[92178b8fea183b1]::sys_common::backtrace::__rust_end_short_backtrace::<std[92178b8fea183b1]::panicking::begin_panic<rustc_errors[bc32936de75f68a8]::ExplicitBug>::{closure#0}, !>
  14:     0x7f14690f42a6 - std[92178b8fea183b1]::panicking::begin_panic::<rustc_errors[bc32936de75f68a8]::ExplicitBug>
  15:     0x7f1469113a66 - std[92178b8fea183b1]::panic::panic_any::<rustc_errors[bc32936de75f68a8]::ExplicitBug>
  16:     0x7f1469111505 - <rustc_errors[bc32936de75f68a8]::HandlerInner>::bug::<&alloc[9a1da603931b4913]::string::String>
  17:     0x7f1469111260 - <rustc_errors[bc32936de75f68a8]::Handler>::bug::<&alloc[9a1da603931b4913]::string::String>
  18:     0x7f146918f6bd - rustc_middle[5e1b60369bd5df6]::ty::context::tls::with_opt::<rustc_middle[5e1b60369bd5df6]::util::bug::opt_span_bug_fmt<rustc_span[c6162a597843e319]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f146918f816 - rustc_middle[5e1b60369bd5df6]::util::bug::opt_span_bug_fmt::<rustc_span[c6162a597843e319]::span_encoding::Span>
  20:     0x7f146918f793 - rustc_middle[5e1b60369bd5df6]::util::bug::bug_fmt
  21:     0x7f146846111d - <rustc_infer[2986cd19b18a3338]::infer::nll_relate::TypeRelating<rustc_infer[2986cd19b18a3338]::infer::canonical::query_response::QueryTypeRelatingDelegate> as rustc_middle[5e1b60369bd5df6]::ty::relate::TypeRelation>::consts
  22:     0x7f146847fa0a - <rustc_infer[2986cd19b18a3338]::infer::InferCtxt>::instantiate_nll_query_response_and_region_obligations::<alloc[9a1da603931b4913]::vec::Vec<rustc_middle[5e1b60369bd5df6]::traits::query::OutlivesBound>>
  23:     0x7f14696b40ce - <rustc_infer[2986cd19b18a3338]::infer::outlives::env::OutlivesEnvironment as rustc_typeck[c4240235affd9ba6]::check::regionck::OutlivesEnvironmentExt>::add_implied_bounds
  24:     0x7f146976d821 - <rustc_typeck[c4240235affd9ba6]::check::regionck::RegionCtxt>::visit_fn_body
  25:     0x7f14697715d7 - <rustc_typeck[c4240235affd9ba6]::check::regionck::RegionCtxt as rustc_hir[6e5206eda1c7a30]::intravisit::Visitor>::visit_expr
  26:     0x7f146977015c - <rustc_typeck[c4240235affd9ba6]::check::regionck::RegionCtxt as rustc_hir[6e5206eda1c7a30]::intravisit::Visitor>::visit_expr
  27:     0x7f146977011c - <rustc_typeck[c4240235affd9ba6]::check::regionck::RegionCtxt as rustc_hir[6e5206eda1c7a30]::intravisit::Visitor>::visit_expr
  28:     0x7f146976dbce - <rustc_typeck[c4240235affd9ba6]::check::regionck::RegionCtxt>::visit_fn_body
  29:     0x7f146972cae9 - <rustc_infer[2986cd19b18a3338]::infer::InferCtxtBuilder>::enter::<&rustc_middle[5e1b60369bd5df6]::ty::context::TypeckResults, <rustc_typeck[c4240235affd9ba6]::check::inherited::InheritedBuilder>::enter<rustc_typeck[c4240235affd9ba6]::check::typeck_with_fallback<rustc_typeck[c4240235affd9ba6]::check::typeck::{closure#0}>::{closure#1}, &rustc_middle[5e1b60369bd5df6]::ty::context::TypeckResults>::{closure#0}>
  30:     0x7f14696c4a9a - rustc_typeck[c4240235affd9ba6]::check::typeck
  31:     0x7f1469c764b4 - rustc_query_system[e060dcc8c6e4714f]::query::plumbing::try_execute_query::<rustc_query_impl[85c2181340255b16]::plumbing::QueryCtxt, rustc_query_system[e060dcc8c6e4714f]::query::caches::DefaultCache<rustc_span[c6162a597843e319]::def_id::LocalDefId, &rustc_middle[5e1b60369bd5df6]::ty::context::TypeckResults>>
  32:     0x7f1469c4c7ee - <rustc_query_impl[85c2181340255b16]::Queries as rustc_middle[5e1b60369bd5df6]::ty::query::QueryEngine>::typeck
  33:     0x7f14696c4c2f - rustc_typeck[c4240235affd9ba6]::check::typeck
  34:     0x7f1469c764b4 - rustc_query_system[e060dcc8c6e4714f]::query::plumbing::try_execute_query::<rustc_query_impl[85c2181340255b16]::plumbing::QueryCtxt, rustc_query_system[e060dcc8c6e4714f]::query::caches::DefaultCache<rustc_span[c6162a597843e319]::def_id::LocalDefId, &rustc_middle[5e1b60369bd5df6]::ty::context::TypeckResults>>
  35:     0x7f1469c4c7ee - <rustc_query_impl[85c2181340255b16]::Queries as rustc_middle[5e1b60369bd5df6]::ty::query::QueryEngine>::typeck
  36:     0x7f1469786108 - <rustc_middle[5e1b60369bd5df6]::hir::map::Map>::par_body_owners::<rustc_typeck[c4240235affd9ba6]::check::typeck_item_bodies::{closure#0}>
  37:     0x7f146a52242c - rustc_typeck[c4240235affd9ba6]::check::typeck_item_bodies
  38:     0x7f146a81c2ec - rustc_query_system[e060dcc8c6e4714f]::query::plumbing::try_execute_query::<rustc_query_impl[85c2181340255b16]::plumbing::QueryCtxt, rustc_query_system[e060dcc8c6e4714f]::query::caches::DefaultCache<(), ()>>
  39:     0x7f146a848da1 - rustc_query_system[e060dcc8c6e4714f]::query::plumbing::get_query::<rustc_query_impl[85c2181340255b16]::queries::typeck_item_bodies, rustc_query_impl[85c2181340255b16]::plumbing::QueryCtxt>
  40:     0x7f146a561c63 - <rustc_session[52ecc3f9ef8fdbdb]::session::Session>::time::<(), rustc_typeck[c4240235affd9ba6]::check_crate::{closure#7}>
  41:     0x7f146a53d6f3 - rustc_typeck[c4240235affd9ba6]::check_crate
  42:     0x7f146a2ade47 - rustc_interface[5a583bacec404f39]::passes::analysis
  43:     0x7f146a81181f - rustc_query_system[e060dcc8c6e4714f]::query::plumbing::try_execute_query::<rustc_query_impl[85c2181340255b16]::plumbing::QueryCtxt, rustc_query_system[e060dcc8c6e4714f]::query::caches::DefaultCache<(), core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>>>
  44:     0x7f146a85b2fe - rustc_query_system[e060dcc8c6e4714f]::query::plumbing::get_query::<rustc_query_impl[85c2181340255b16]::queries::analysis, rustc_query_impl[85c2181340255b16]::plumbing::QueryCtxt>
  45:     0x7f146a290f67 - <rustc_interface[5a583bacec404f39]::passes::QueryContext>::enter::<rustc_driver[3c4ddaa230521172]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>>
  46:     0x7f146a27b24f - <rustc_interface[5a583bacec404f39]::interface::Compiler>::enter::<rustc_driver[3c4ddaa230521172]::run_compiler::{closure#1}::{closure#2}, core[fd7ff14c59d02930]::result::Result<core[fd7ff14c59d02930]::option::Option<rustc_interface[5a583bacec404f39]::queries::Linker>, rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>>
  47:     0x7f146a29f65f - rustc_span[c6162a597843e319]::with_source_map::<core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>, rustc_interface[5a583bacec404f39]::interface::create_compiler_and_run<core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>, rustc_driver[3c4ddaa230521172]::run_compiler::{closure#1}>::{closure#1}>
  48:     0x7f146a27c0e2 - <scoped_tls[df47f77656bf316c]::ScopedKey<rustc_span[c6162a597843e319]::SessionGlobals>>::set::<rustc_interface[5a583bacec404f39]::interface::run_compiler<core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>, rustc_driver[3c4ddaa230521172]::run_compiler::{closure#1}>::{closure#0}, core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>>
  49:     0x7f146a2915ef - std[92178b8fea183b1]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5a583bacec404f39]::util::run_in_thread_pool_with_globals<rustc_interface[5a583bacec404f39]::interface::run_compiler<core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>, rustc_driver[3c4ddaa230521172]::run_compiler::{closure#1}>::{closure#0}, core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>>::{closure#0}, core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>>
  50:     0x7f146a2917d9 - <<std[92178b8fea183b1]::thread::Builder>::spawn_unchecked_<rustc_interface[5a583bacec404f39]::util::run_in_thread_pool_with_globals<rustc_interface[5a583bacec404f39]::interface::run_compiler<core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>, rustc_driver[3c4ddaa230521172]::run_compiler::{closure#1}>::{closure#0}, core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>>::{closure#0}, core[fd7ff14c59d02930]::result::Result<(), rustc_errors[bc32936de75f68a8]::ErrorGuaranteed>>::{closure#1} as core[fd7ff14c59d02930]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x7f14678fd163 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd06934b23a7f2fcd
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/alloc/src/boxed.rs:1951:9
  52:     0x7f14678fd163 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb092aa1c4d31e227
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/alloc/src/boxed.rs:1951:9
  53:     0x7f14678fd163 - std::sys::unix::thread::Thread::new::thread_start::hea70d8d092b89098
                               at /rustc/bb8c2f41174caceec00c28bc6c5c20ae9f9a175c/library/std/src/sys/unix/thread.rs:108:17
  54:     0x7f14677ef259 - start_thread
  55:     0x7f14677165e3 - __GI___clone
  56:                0x0 - <unknown>

note: 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.63.0-nightly (bb8c2f411 2022-06-19) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `<impl at main.rs:5:1: 9:2>::f`
#1 [typeck] type-checking `<impl at main.rs:5:1: 9:2>::f::{closure#0}`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.
@tmerr tmerr added C-bug Category: This is a bug. 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. labels Jun 20, 2022
@JohnTitor
Copy link
Member

I think it's a duplicate of #98299.

@JohnTitor JohnTitor closed this as not planned Won't fix, can't repro, duplicate, stale Jun 20, 2022
@LoganDark
Copy link

LoganDark commented Jun 22, 2022

I think it's a duplicate of #98299.

It's not.

I just ran into this issue myself and a repro (on linux) has been preserved here. No black_box to be found anywhere.

Once the code was fixed up to compile, the ICE went away.

rustc.stderr.txt

edit: It seems the root cause is the same. The latest nightly no longer ICEs (I was 1 nightly out of date).

@JohnTitor
Copy link
Member

@LoganDark Note that the ICE doesn't need the black_box feature as it existed on the diagnostics.

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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants