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: has inference variables for offset_of with Box<dyn Trait> #111678

Closed
est31 opened this issue May 17, 2023 · 2 comments · Fixed by #111696
Closed

ICE: has inference variables for offset_of with Box<dyn Trait> #111678

est31 opened this issue May 17, 2023 · 2 comments · Fixed by #111696
Labels
F-offset_of `#![feature(offset_of)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@est31
Copy link
Member

est31 commented May 17, 2023

There is an ICE with dyn Trait, generics, and offset_of, if you turn on debug-assertions in the compiler (of the compiler itself, not of the compiled code). For this code:

#![feature(offset_of)]

use std::mem::offset_of;

trait Trait {}

struct Delta<T: ?Sized> {
    x: u8,
    z: T,
}

fn main() {}

fn delta() {
    offset_of!(Delta<Box<dyn Trait>>, z);
}

You get:

error: internal compiler error: compiler/rustc_hir_typeck/src/writeback.rs:697:17: writeback: `Delta<std::boxed::Box<dyn Trait>>` has inference variables
  --> /home/user/src/rust/tests/ui/offset-of/ice.rs:15:5
   |
LL |     offset_of!(Delta<Box<dyn Trait>>, z);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this error: internal compiler error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)

Originally discovered in #111665 (comment) as an ICE-on-error but you can change the code to also ICEs if there is no error (like done in this issue report).

Backtrace:

thread 'rustc' panicked at 'Box<dyn Any>', /checkout/compiler/rustc_errors/src/lib.rs:994:33
thread 'rustc' panicked at 'Box<dyn Any>', /checkout/compiler/rustc_errors/src/lib.rs:994:33
stack backtrace:
   0:     0x7fc9756d2494 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h83c4d273a293937a
   1:     0x7fc975739148 - core::fmt::write::h4944797bfd0ec333
   2:     0x7fc9756c6c41 - std::io::Write::write_fmt::hdcc1f740d69f3926
   3:     0x7fc9756d22a1 - std::sys_common::backtrace::print::h073f86496844392b
   4:     0x7fc9756d541a - std::panicking::default_hook::{{closure}}::h05a9bc928a1853ef
   5:     0x7fc9756d50fc - std::panicking::default_hook::h3f4a2e90430e7afd
   6:     0x7fc97618222b - rustc_driver_impl[3f6d7dedc3cd2469]::install_ice_hook::{closure#0}
   7:     0x7fc9756d5b27 - std::panicking::rust_panic_with_hook::hcab7ffc533d49d69
   8:     0x7fc97677a7f3 - std[6e36f31dabee1d53]::panicking::begin_panic::<rustc_errors[eb4320e7b0a9c594]::ExplicitBug>::{closure#0}
   9:     0x7fc976769c86 - std[6e36f31dabee1d53]::sys_common::backtrace::__rust_end_short_backtrace::<std[6e36f31dabee1d53]::panicking::begin_panic<rustc_errors[eb4320e7b0a9c594]::ExplicitBug>::{closure#0}, !>
  10:     0x7fc975f421e6 - std[6e36f31dabee1d53]::panicking::begin_panic::<rustc_errors[eb4320e7b0a9c594]::ExplicitBug>
  11:     0x7fc97682a1f1 - <rustc_errors[eb4320e7b0a9c594]::HandlerInner>::span_bug::<rustc_span[e7b4b05131986322]::span_encoding::Span, alloc[dfd73537032ceef3]::string::String>
  12:     0x7fc976829ed0 - <rustc_errors[eb4320e7b0a9c594]::Handler>::span_bug::<rustc_span[e7b4b05131986322]::span_encoding::Span, alloc[dfd73537032ceef3]::string::String>
  13:     0x7fc976792648 - rustc_middle[dff2417f09c5d1c7]::util::bug::opt_span_bug_fmt::<rustc_span[e7b4b05131986322]::span_encoding::Span>::{closure#0}
  14:     0x7fc97679269c - rustc_middle[dff2417f09c5d1c7]::ty::context::tls::with_opt::<rustc_middle[dff2417f09c5d1c7]::util::bug::opt_span_bug_fmt<rustc_span[e7b4b05131986322]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x7fc97678bc74 - rustc_middle[dff2417f09c5d1c7]::ty::context::tls::with_context_opt::<rustc_middle[dff2417f09c5d1c7]::ty::context::tls::with_opt<rustc_middle[dff2417f09c5d1c7]::util::bug::opt_span_bug_fmt<rustc_span[e7b4b05131986322]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x7fc975f3bab7 - rustc_middle[dff2417f09c5d1c7]::util::bug::span_bug_fmt::<rustc_span[e7b4b05131986322]::span_encoding::Span>
  17:     0x7fc97673bc47 - <rustc_hir_typeck[5e8ba42dccce2c8d]::writeback::WritebackCx>::visit_offset_of_container_types
  18:     0x7fc9766c6e2c - <rustc_hir_typeck[5e8ba42dccce2c8d]::fn_ctxt::FnCtxt>::resolve_type_vars_in_body
  19:     0x7fc97675e698 - rustc_hir_typeck[5e8ba42dccce2c8d]::typeck
  20:     0x7fc977e4d8e8 - rustc_query_system[eec62171ae950562]::query::plumbing::try_execute_query::<rustc_query_impl[4d8232e64bd838e8]::DynamicConfig<rustc_query_system[eec62171ae950562]::query::caches::VecCache<rustc_span[e7b4b05131986322]::def_id::LocalDefId, rustc_middle[dff2417f09c5d1c7]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[4d8232e64bd838e8]::plumbing::QueryCtxt, false>
  21:     0x7fc977c3e75a - rustc_query_impl[4d8232e64bd838e8]::get_query_non_incr::typeck
  22:     0x7fc976747db9 - rustc_middle[dff2417f09c5d1c7]::ty::query::query_get_at::<rustc_query_system[eec62171ae950562]::query::caches::VecCache<rustc_span[e7b4b05131986322]::def_id::LocalDefId, rustc_middle[dff2417f09c5d1c7]::query::erase::Erased<[u8; 8usize]>>>
  23:     0x7fc97675d942 - rustc_hir_typeck[5e8ba42dccce2c8d]::used_trait_imports
  24:     0x7fc977e4d8e8 - rustc_query_system[eec62171ae950562]::query::plumbing::try_execute_query::<rustc_query_impl[4d8232e64bd838e8]::DynamicConfig<rustc_query_system[eec62171ae950562]::query::caches::VecCache<rustc_span[e7b4b05131986322]::def_id::LocalDefId, rustc_middle[dff2417f09c5d1c7]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[4d8232e64bd838e8]::plumbing::QueryCtxt, false>
  25:     0x7fc977c3f47a - rustc_query_impl[4d8232e64bd838e8]::get_query_non_incr::used_trait_imports
  26:     0x7fc976a4a459 - rustc_middle[dff2417f09c5d1c7]::ty::query::query_get_at::<rustc_query_system[eec62171ae950562]::query::caches::VecCache<rustc_span[e7b4b05131986322]::def_id::LocalDefId, rustc_middle[dff2417f09c5d1c7]::query::erase::Erased<[u8; 8usize]>>>
  27:     0x7fc976a6097f - rustc_hir_analysis[d1318f2d0275e338]::check_crate
  28:     0x7fc976276229 - rustc_interface[2e0b07c19739ca13]::passes::analysis
  29:     0x7fc977f22227 - <rustc_query_impl[4d8232e64bd838e8]::dynamic_query::analysis::{closure#2} as core[889acdda7fcfab05]::ops::function::FnOnce<(rustc_middle[dff2417f09c5d1c7]::ty::context::TyCtxt, ())>>::call_once
  30:     0x7fc977dbf652 - rustc_query_system[eec62171ae950562]::query::plumbing::try_execute_query::<rustc_query_impl[4d8232e64bd838e8]::DynamicConfig<rustc_query_system[eec62171ae950562]::query::caches::SingleCache<rustc_middle[dff2417f09c5d1c7]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[4d8232e64bd838e8]::plumbing::QueryCtxt, false>
  31:     0x7fc977c1aa36 - rustc_query_impl[4d8232e64bd838e8]::get_query_non_incr::analysis
  32:     0x7fc97619e89d - <rustc_middle[dff2417f09c5d1c7]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[3f6d7dedc3cd2469]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>>
  33:     0x7fc9761d4888 - <rustc_interface[2e0b07c19739ca13]::interface::Compiler>::enter::<rustc_driver_impl[3f6d7dedc3cd2469]::run_compiler::{closure#1}::{closure#2}, core[889acdda7fcfab05]::result::Result<core[889acdda7fcfab05]::option::Option<rustc_interface[2e0b07c19739ca13]::queries::Linker>, rustc_span[e7b4b05131986322]::ErrorGuaranteed>>
  34:     0x7fc97619d4f0 - rustc_span[e7b4b05131986322]::set_source_map::<core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>, rustc_interface[2e0b07c19739ca13]::interface::run_compiler<core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>, rustc_driver_impl[3f6d7dedc3cd2469]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  35:     0x7fc97618fae9 - <scoped_tls[85c7688d238b0262]::ScopedKey<rustc_span[e7b4b05131986322]::SessionGlobals>>::set::<rustc_interface[2e0b07c19739ca13]::interface::run_compiler<core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>, rustc_driver_impl[3f6d7dedc3cd2469]::run_compiler::{closure#1}>::{closure#0}, core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>>
  36:     0x7fc9761a78c6 - std[6e36f31dabee1d53]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2e0b07c19739ca13]::util::run_in_thread_pool_with_globals<rustc_interface[2e0b07c19739ca13]::interface::run_compiler<core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>, rustc_driver_impl[3f6d7dedc3cd2469]::run_compiler::{closure#1}>::{closure#0}, core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>>
  37:     0x7fc9761d5d56 - std[6e36f31dabee1d53]::panicking::try::<core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>, core[889acdda7fcfab05]::panic::unwind_safe::AssertUnwindSafe<<std[6e36f31dabee1d53]::thread::Builder>::spawn_unchecked_<rustc_interface[2e0b07c19739ca13]::util::run_in_thread_pool_with_globals<rustc_interface[2e0b07c19739ca13]::interface::run_compiler<core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>, rustc_driver_impl[3f6d7dedc3cd2469]::run_compiler::{closure#1}>::{closure#0}, core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
  38:     0x7fc976195cbd - <<std[6e36f31dabee1d53]::thread::Builder>::spawn_unchecked_<rustc_interface[2e0b07c19739ca13]::util::run_in_thread_pool_with_globals<rustc_interface[2e0b07c19739ca13]::interface::run_compiler<core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>, rustc_driver_impl[3f6d7dedc3cd2469]::run_compiler::{closure#1}>::{closure#0}, core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[889acdda7fcfab05]::result::Result<(), rustc_span[e7b4b05131986322]::ErrorGuaranteed>>::{closure#1} as core[889acdda7fcfab05]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7fc9756e245e - std::sys::unix::thread::Thread::new::thread_start::h4ca786d16292e1e9
  40:     0x7fc97547db43 - <unknown>
  41:     0x7fc97550fa00 - <unknown>
  42:                0x0 - <unknown>

@rustbot label I-ICE F-offset_of

cc @WaffleLapkin
cc #106655 offset_of tracking issue

@rustbot rustbot added F-offset_of `#![feature(offset_of)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels May 17, 2023
@compiler-errors
Copy link
Member

This should be fixed by #111661?

@est31
Copy link
Member Author

est31 commented May 17, 2023

@compiler-errors I've wondered about that too, so I rebased #111665 onto master shortly after the PR you linked was merged, and it still gave the ICE. See the thread of #111665.

@bors bors closed this as completed in a11235d May 21, 2023
thomcc pushed a commit to tcdi/postgrestd that referenced this issue Jul 18, 2023
…compiler-errors

don't skip inference for type in `offset_of!`

Fixes rust-lang/rust#111678 by no longer skipping inference on the type in `offset_of!`. Simply erasing the regions the during writeback isn't enough and can cause ICEs. A test case for this is included.

This reverts rust-lang/rust#111661, because it becomes redundant, since inference already erases the regions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-offset_of `#![feature(offset_of)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants