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 with inline_const and TypeId #102117

Closed
ghost opened this issue Sep 21, 2022 · 3 comments · Fixed by #102187
Closed

ICE with inline_const and TypeId #102117

ghost opened this issue Sep 21, 2022 · 3 comments · Fixed by #102187
Assignees
Labels
C-bug Category: This is a bug. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) glacier ICE tracked in rust-lang/glacier. 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

@ghost
Copy link

ghost commented Sep 21, 2022

Code

#![feature(inline_const, const_type_id)]

use std::alloc::Layout;
use std::any::TypeId;
use std::mem::transmute;
use std::ptr::drop_in_place;

pub struct VTable {
    layout: Layout,
    type_id: TypeId,
    drop_in_place: unsafe fn(*mut ()),
}

impl VTable {
    pub fn new<T>() -> &'static Self {
        const {
            &VTable {
                layout: Layout::new::<T>(),
                type_id: TypeId::of::<T>(),
                drop_in_place: unsafe {
                    transmute::<unsafe fn(*mut T), unsafe fn(*mut ())>(drop_in_place::<T>)
                },
            }
        }
    }
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=eac6582df10214dd6b363003a9346ac4

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (432abd86f 2022-09-20)
binary: rustc
commit-hash: 432abd86f231c908f6df3cdd779e83f35084be90
commit-date: 2022-09-20
host: x86_64-apple-darwin
release: 1.66.0-nightly
LLVM version: 15.0.0

(latest nightly as of today)

Error output

Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', compiler/rustc_middle/src/mir/mod.rs:424:22
stack backtrace:
   0:     0x7f00279f8d50 - std::backtrace_rs::backtrace::libunwind::trace::h22157d54c25d05ad
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1:     0x7f00279f8d50 - std::backtrace_rs::backtrace::trace_unsynchronized::hf9a98b3986ed5962
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f00279f8d50 - std::sys_common::backtrace::_print_fmt::h44f8a801ddb575b4
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f00279f8d50 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h306abe8d5f5fb26d
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f0027a53aae - core::fmt::write::h5a3c14feb177cc6f
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/core/src/fmt/mod.rs:1202:17
   5:     0x7f00279e9865 - std::io::Write::write_fmt::h2fac6c752c3fce7e
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/io/mod.rs:1679:15
   6:     0x7f00279fba03 - std::sys_common::backtrace::_print::h17490259a7578aec
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f00279fba03 - std::sys_common::backtrace::print::h6dba4ce5923cf00b
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f00279fba03 - std::panicking::default_hook::{{closure}}::h25daedc6802fa9d1
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/panicking.rs:295:22
   9:     0x7f00279fb6ef - std::panicking::default_hook::hffec061dc0fa1a5a
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/panicking.rs:314:9
  10:     0x7f002a20a951 - <rustc_driver[2817d6214121e090]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[7a17016bf310e64d]::ops::function::FnOnce<(&core[7a17016bf310e64d]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f00279fc23d - std::panicking::rust_panic_with_hook::h74e697c31d32505c
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/panicking.rs:702:17
  12:     0x7f00279fc097 - std::panicking::begin_panic_handler::{{closure}}::hd0b9cdbd524ed365
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/panicking.rs:588:13
  13:     0x7f00279f91fc - std::sys_common::backtrace::__rust_end_short_backtrace::h3feb3f4e0604d329
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7f00279fbdb2 - rust_begin_unwind
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/panicking.rs:584:5
  15:     0x7f0027a50683 - core::panicking::panic_fmt::h0f41ee9e7f6526dd
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/core/src/panicking.rs:142:14
  16:     0x7f0027a505c2 - core::panicking::panic_bounds_check::he56b772f2574babd
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/core/src/panicking.rs:84:5
  17:     0x7f0028e38ac0 - <rustc_middle[e9ef365c3785ee8]::mir::Body>::source_info
  18:     0x7f0029261d77 - <rustc_borrowck[1f33eea8b2f8e421]::region_infer::RegionInferenceContext>::solve
  19:     0x7f0029200b63 - rustc_borrowck[1f33eea8b2f8e421]::nll::compute_regions
  20:     0x7f00291d5708 - rustc_borrowck[1f33eea8b2f8e421]::do_mir_borrowck
  21:     0x7f0029bfb436 - rustc_borrowck[1f33eea8b2f8e421]::mir_borrowck
  22:     0x7f0029bfabb1 - <rustc_borrowck[1f33eea8b2f8e421]::provide::{closure#0} as core[7a17016bf310e64d]::ops::function::FnOnce<(rustc_middle[e9ef365c3785ee8]::ty::context::TyCtxt, rustc_span[8a07e301efc44469]::def_id::LocalDefId)>>::call_once
  23:     0x7f0029787445 - rustc_query_system[64e6e6746f0d4f91]::query::plumbing::try_execute_query::<rustc_query_impl[33edb96cb03c9964]::plumbing::QueryCtxt, rustc_query_system[64e6e6746f0d4f91]::query::caches::DefaultCache<rustc_span[8a07e301efc44469]::def_id::LocalDefId, &rustc_middle[e9ef365c3785ee8]::mir::query::BorrowCheckResult>>
  24:     0x7f002a1507ce - <rustc_query_impl[33edb96cb03c9964]::Queries as rustc_middle[e9ef365c3785ee8]::ty::query::QueryEngine>::mir_borrowck
  25:     0x7f00292b5c48 - <rustc_borrowck[1f33eea8b2f8e421]::type_check::TypeChecker>::prove_closure_bounds
  26:     0x7f002929b78f - <rustc_borrowck[1f33eea8b2f8e421]::type_check::TypeChecker>::typeck_mir
  27:     0x7f0029215981 - rustc_borrowck[1f33eea8b2f8e421]::type_check::type_check
  28:     0x7f0029200799 - rustc_borrowck[1f33eea8b2f8e421]::nll::compute_regions
  29:     0x7f00291d5708 - rustc_borrowck[1f33eea8b2f8e421]::do_mir_borrowck
  30:     0x7f0029bfb436 - rustc_borrowck[1f33eea8b2f8e421]::mir_borrowck
  31:     0x7f0029bfabb1 - <rustc_borrowck[1f33eea8b2f8e421]::provide::{closure#0} as core[7a17016bf310e64d]::ops::function::FnOnce<(rustc_middle[e9ef365c3785ee8]::ty::context::TyCtxt, rustc_span[8a07e301efc44469]::def_id::LocalDefId)>>::call_once
  32:     0x7f0029787445 - rustc_query_system[64e6e6746f0d4f91]::query::plumbing::try_execute_query::<rustc_query_impl[33edb96cb03c9964]::plumbing::QueryCtxt, rustc_query_system[64e6e6746f0d4f91]::query::caches::DefaultCache<rustc_span[8a07e301efc44469]::def_id::LocalDefId, &rustc_middle[e9ef365c3785ee8]::mir::query::BorrowCheckResult>>
  33:     0x7f002a1507ce - <rustc_query_impl[33edb96cb03c9964]::Queries as rustc_middle[e9ef365c3785ee8]::ty::query::QueryEngine>::mir_borrowck
  34:     0x7f00295aa3b3 - rustc_data_structures[7efd42249ed2c6e9]::sync::par_for_each_in::<&[rustc_span[8a07e301efc44469]::def_id::LocalDefId], <rustc_middle[e9ef365c3785ee8]::hir::map::Map>::par_body_owners<rustc_interface[2d255db050a36d31]::passes::analysis::{closure#2}::{closure#0}>::{closure#0}>
  35:     0x7f00295aa113 - <rustc_session[920c8e110a6e000f]::session::Session>::time::<(), rustc_interface[2d255db050a36d31]::passes::analysis::{closure#2}>
  36:     0x7f00295a7705 - rustc_interface[2d255db050a36d31]::passes::analysis
  37:     0x7f0029fe19d4 - rustc_query_system[64e6e6746f0d4f91]::query::plumbing::try_execute_query::<rustc_query_impl[33edb96cb03c9964]::plumbing::QueryCtxt, rustc_query_system[64e6e6746f0d4f91]::query::caches::DefaultCache<(), core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>>>
  38:     0x7f0029fe1707 - rustc_query_system[64e6e6746f0d4f91]::query::plumbing::get_query::<rustc_query_impl[33edb96cb03c9964]::queries::analysis, rustc_query_impl[33edb96cb03c9964]::plumbing::QueryCtxt>
  39:     0x7f0028fa5b77 - <rustc_interface[2d255db050a36d31]::passes::QueryContext>::enter::<rustc_driver[2817d6214121e090]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>>
  40:     0x7f0028f996dc - rustc_interface[2d255db050a36d31]::interface::create_compiler_and_run::<core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>, rustc_driver[2817d6214121e090]::run_compiler::{closure#1}>
  41:     0x7f0028f98012 - <scoped_tls[f167104904068c68]::ScopedKey<rustc_span[8a07e301efc44469]::SessionGlobals>>::set::<rustc_interface[2d255db050a36d31]::interface::run_compiler<core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>, rustc_driver[2817d6214121e090]::run_compiler::{closure#1}>::{closure#0}, core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>>
  42:     0x7f0028f97cff - std[7414053366649774]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2d255db050a36d31]::util::run_in_thread_pool_with_globals<rustc_interface[2d255db050a36d31]::interface::run_compiler<core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>, rustc_driver[2817d6214121e090]::run_compiler::{closure#1}>::{closure#0}, core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>>::{closure#0}, core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>>
  43:     0x7f002a072fe0 - <<std[7414053366649774]::thread::Builder>::spawn_unchecked_<rustc_interface[2d255db050a36d31]::util::run_in_thread_pool_with_globals<rustc_interface[2d255db050a36d31]::interface::run_compiler<core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>, rustc_driver[2817d6214121e090]::run_compiler::{closure#1}>::{closure#0}, core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>>::{closure#0}, core[7a17016bf310e64d]::result::Result<(), rustc_errors[aa542ed4628157d3]::ErrorGuaranteed>>::{closure#1} as core[7a17016bf310e64d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:     0x7f0027a06013 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h59c19dbfda82d3be
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/alloc/src/boxed.rs:1940:9
  45:     0x7f0027a06013 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5cc1cabf17fe5922
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/alloc/src/boxed.rs:1940:9
  46:     0x7f0027a06013 - std::sys::unix::thread::Thread::new::thread_start::h8f3eeb92c9304ef6
                               at /rustc/432abd86f231c908f6df3cdd779e83f35084be90/library/std/src/sys/unix/thread.rs:108:17
  47:     0x7f00278d9609 - start_thread
  48:     0x7f00277fc133 - clone
  49:                0x0 - <unknown>

error: internal compiler error: unexpected panic

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.66.0-nightly (432abd86f 2022-09-20) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at src/lib.rs:14:1: 14:12>::new::{constant#0}`
#1 [mir_borrowck] borrow-checking `<impl at src/lib.rs:14:1: 14:12>::new`
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `playground`

@ghost ghost 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 Sep 21, 2022
@ghost
Copy link
Author

ghost commented Sep 21, 2022

@rustbot label: +F-inline_const

@rustbot rustbot added the F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) label Sep 21, 2022
@ghost
Copy link
Author

ghost commented Sep 21, 2022

Note the missing T: 'static bound. TypeId::of requires T: 'static, and should throw a lifetime bounds error, but I think the inline const block is tripping something up. It works fine if you require T: 'static or without the inline const block.

@b-naber
Copy link
Contributor

b-naber commented Sep 22, 2022

@rustbot claim

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. F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) glacier ICE tracked in rust-lang/glacier. 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

Successfully merging a pull request may close this issue.

3 participants