Skip to content

ICE when using offset_of! in generic_const_exprs #123959

Open
@Kolsky

Description

@Kolsky

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-generic_const_exprs`#![feature(generic_const_exprs)]`F-offset_of`#![feature(offset_of)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions