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 when using offset_of! in generic_const_exprs #123959

Open
Kolsky opened this issue Apr 15, 2024 · 0 comments
Open

ICE when using offset_of! in generic_const_exprs #123959

Kolsky opened this issue Apr 15, 2024 · 0 comments
Labels
A-traits Area: Trait system C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` F-offset_of `#![feature(offset_of)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kolsky
Copy link

Kolsky commented Apr 15, 2024

Code (playground)

#![feature(generic_const_exprs)]
fn foo<T>(_: [(); std::mem::offset_of!((T,), 0)]) {}

Produces ICE:

error: internal compiler error: Missing value for constant, but no error reported?
 --> src/lib.rs:2:19
  |
2 | fn foo<T>(_: [(); std::mem::offset_of!((T,), 0)]) {}
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: delayed at compiler/rustc_trait_selection/src/traits/const_evaluatable.rs:74:68
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxt>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: rustc_trait_selection::traits::const_evaluatable::is_const_evaluatable.cold
         4: <rustc_trait_selection::traits::fulfill::FulfillProcessor as rustc_data_structures::obligation_forest::ObligationProcessor>::process_obligation
         5: <rustc_data_structures::obligation_forest::ObligationForest<rustc_trait_selection::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection::traits::fulfill::FulfillProcessor>
         6: <rustc_trait_selection::traits::engine::ObligationCtxt>::assumed_wf_types
         7: rustc_hir_analysis::check::wfcheck::check_item_fn
         8: rustc_hir_analysis::check::wfcheck::check_well_formed
         9: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        10: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        11: rustc_query_impl::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
        12: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
        13: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        15: rustc_query_impl::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
        16: rustc_hir_analysis::check_crate
        17: rustc_interface::passes::analysis
        18: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        20: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        21: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
        22: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        23: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#2} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        24: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/alloc/src/boxed.rs:2018:9
        25: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/alloc/src/boxed.rs:2018:9
        26: std::sys::pal::unix::thread::Thread::new::thread_start
                   at /rustc/0d8b3346a3992ab11ea35ff0fb95a6864b91f797/library/std/src/sys/pal/unix/thread.rs:108:17
        27: start_thread
        28: clone
 --> src/lib.rs:2:19
  |
2 | fn foo<T>(_: [(); std::mem::offset_of!((T,), 0)]) {}
  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: this error: internal compiler error originates in the macro `std::mem::offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)

Similar looking code also ICEs on stable with different error message and feature enabled:

#![feature(generic_const_exprs)]

struct Foo<T, const N: usize = { std::mem::size_of::<T>() }>(T) where [(); std::mem::size_of::<T>()]:;

struct Bar<T> {
    foo: Foo<T>,
}

Upd.: additionaly, it does not ICE with -Znext-solver enabled for the first provided case, but not the second.

@Kolsky Kolsky 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 Apr 15, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 15, 2024
@Kolsky Kolsky changed the title generic_const_exprs and offset_of don't bode well ICE when using offset_of! in generic_const_exprs Apr 15, 2024
@jieyouxu jieyouxu added F-generic_const_exprs `#![feature(generic_const_exprs)]` S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue F-offset_of `#![feature(offset_of)]` A-traits Area: Trait system requires-incomplete-features This issue requires the use of incomplete features. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-traits Area: Trait system C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` F-offset_of `#![feature(offset_of)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants