Skip to content

ICE: Unexpected unsized type tail: &ReStatic [u8] #122488

Closed

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

use std::ops::Deref;

struct ArenaSet<U: Deref, V: ?Sized = <U as Deref>::Target>(V, U);

const DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();
original code / tests/ui/issues/issue-39367.rs

original:

//@ run-pass

use std::ops::Deref;

struct ArenaSet<U: Deref, V=<U as Deref>::Target>(V, &'static V)
    where V: 'static + ?Sized;

static Z: [u8; 3] = [1,2,3,4];

fn arena() -> &'static ArenaSet<Vec<u8>> {
    fn transmute() -> ArenaSet<Vec<u8>> {
        ArenaSet(|| {
                DATA = transmute
                    ::<ArenaSet<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
                    (Box::new(__static_ref_initialize(vec![], &Z)));
            })
    }
    unsafe {
        use std::sync::Once;
        fn arena<T: Sync>(_: &T) { }
        unsafe fn __stability() -> &'static ArenaSet<Vec<u8>> {
            use std::mem::transmute;
            static mut DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();

            static mut ONCE: Once = Once::new();
            ONCE.call_once(|| {
                unsafe {
        use std::sync::Once;
        fn require_sync<T: Sync>(_: &T) { }
        unsafe fn __stability() -> &'static ArenaSet<Vec<u8>> {
            use std::mem::transmute;
            static mut DATA: *const ArenaSet<Vec<u8>> = std::ptr::null_mut();

            static mut ONCE: Once = Once::new();
            ONCE.call_once(|| {
                DATA = transmute
                    ::<Box<ArenaSet<Vec<u8>>>, *const ArenaSet<Vec<u8>>>
                    (Box::new(__static_ref_initialize()));
            });

            &*DATA
        }
        let static_ref = __stability();
        require_sync(static_ref);
        static_ref
    }
            });

            &*DATA
        }
        let static_ref = __stability();
        require_sync(static_ref);
        static_ref
    }
}

fn main() {
    let &ArenaSet(ref u, v) = arena();
    assert!(u.is_empty());
    assert_eq!(v, Z);
}

Version information

rustc 1.78.0-nightly (6f3eb1ce3 2024-03-14)
binary: rustc
commit-hash: 6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6
commit-date: 2024-03-14
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0425]: cannot find value `static_ref` in this scope
  --> /tmp/icemaker_global_tempdir.NZlyzSctY1fd/rustc_testrunner_tmpdir_reporting.UHHGSMyDtFiG/mvce.rs:15:9
   |
15 |         static_ref
   |         ^^^^^^^^^^ not found in this scope

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.NZlyzSctY1fd/rustc_testrunner_tmpdir_reporting.UHHGSMyDtFiG/mvce.rs:17:2
   |
17 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.NZlyzSctY1fd/rustc_testrunner_tmpdir_reporting.UHHGSMyDtFiG/mvce.rs`

error[E0277]: the size for values of type `V` cannot be known at compilation time
 --> /tmp/icemaker_global_tempdir.NZlyzSctY1fd/rustc_testrunner_tmpdir_reporting.UHHGSMyDtFiG/mvce.rs:3:53
  |
3 | struct ArenaSet<U: Deref, V = <U as Deref>::Target>(V, &'static V)
  |                           ------------------------  ^ doesn't have a size known at compile-time
  |                           |
  |                           this type parameter needs to be `Sized`
  |
  = note: only the last field of a struct may have a dynamically sized type
  = help: change the field's type to have a statically known size
help: consider removing the `?Sized` bound to make the type parameter `Sized`
  |
5 -     V: 'static + ?Sized;
5 +     V: 'static;
  |
help: borrowed types always have a statically known size
  |
3 | struct ArenaSet<U: Deref, V = <U as Deref>::Target>(&V, &'static V)
  |                                                     +
help: the `Box` type always has a statically known size and allocates its contents in the heap
  |
3 | struct ArenaSet<U: Deref, V = <U as Deref>::Target>(Box<V>, &'static V)
  |                                                     ++++ +

error[E0392]: type parameter `U` is never used
 --> /tmp/icemaker_global_tempdir.NZlyzSctY1fd/rustc_testrunner_tmpdir_reporting.UHHGSMyDtFiG/mvce.rs:3:17
  |
3 | struct ArenaSet<U: Deref, V = <U as Deref>::Target>(V, &'static V)
  |                 ^ unused type parameter
  |
  = help: consider removing `U`, referring to it in a field, or using a marker such as `PhantomData`

error: internal compiler error: compiler/rustc_const_eval/src/interpret/validity.rs:362:18: Unexpected unsized type tail: &ReStatic [u8]

thread 'rustc' panicked at compiler/rustc_middle/src/util/bug.rs:35:44:
Box<dyn Any>
stack backtrace:
   0:     0x7ffa2538cc22 - std::backtrace_rs::backtrace::libunwind::trace::h51bf9b6011ecfe46
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7ffa2538cc22 - std::backtrace_rs::backtrace::trace_unsynchronized::ha7a99e8dfe87a5f1
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ffa2538cc22 - std::sys_common::backtrace::_print_fmt::h553275cb9152f9b7
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7ffa2538cc22 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8630fe2600383786
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ffa253ddeac - core::fmt::rt::Argument::fmt::h3a63bdd93942d79d
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/core/src/fmt/rt.rs:142:9
   5:     0x7ffa253ddeac - core::fmt::write::had61d91578b9cacb
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/core/src/fmt/mod.rs:1153:17
   6:     0x7ffa25381a1f - std::io::Write::write_fmt::hae3d824a3cf88f9d
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/io/mod.rs:1843:15
   7:     0x7ffa2538c9f4 - std::sys_common::backtrace::_print::h0314863ea3443f50
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ffa2538c9f4 - std::sys_common::backtrace::print::hbb8fe6c998935be0
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ffa2538f6fb - std::panicking::default_hook::{{closure}}::he3b999a7524899ad
  10:     0x7ffa2538f453 - std::panicking::default_hook::hf1ab3997598997ad
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/panicking.rs:292:9
  11:     0x7ffa282f8b2f - std[51808fdf74a5b252]::panicking::update_hook::<alloc[bb6d84cceaf892b5]::boxed::Box<rustc_driver_impl[5ed4bc6caf392c18]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7ffa2538fe60 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h77828d88808d1300
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/alloc/src/boxed.rs:2034:9
  13:     0x7ffa2538fe60 - std::panicking::rust_panic_with_hook::hf855f69e938f97bf
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/panicking.rs:783:13
  14:     0x7ffa283255d4 - std[51808fdf74a5b252]::panicking::begin_panic::<rustc_errors[225c6794f4585fe9]::ExplicitBug>::{closure#0}
  15:     0x7ffa28322226 - std[51808fdf74a5b252]::sys_common::backtrace::__rust_end_short_backtrace::<std[51808fdf74a5b252]::panicking::begin_panic<rustc_errors[225c6794f4585fe9]::ExplicitBug>::{closure#0}, !>
  16:     0x7ffa2831d736 - std[51808fdf74a5b252]::panicking::begin_panic::<rustc_errors[225c6794f4585fe9]::ExplicitBug>
  17:     0x7ffa2832ea41 - <rustc_errors[225c6794f4585fe9]::diagnostic::BugAbort as rustc_errors[225c6794f4585fe9]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7ffa287af7b1 - rustc_middle[7492fbb28f48ec2e]::util::bug::opt_span_bug_fmt::<rustc_span[ba0d7ae542c94e2e]::span_encoding::Span>::{closure#0}
  19:     0x7ffa287933ca - rustc_middle[7492fbb28f48ec2e]::ty::context::tls::with_opt::<rustc_middle[7492fbb28f48ec2e]::util::bug::opt_span_bug_fmt<rustc_span[ba0d7ae542c94e2e]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7ffa28793248 - rustc_middle[7492fbb28f48ec2e]::ty::context::tls::with_context_opt::<rustc_middle[7492fbb28f48ec2e]::ty::context::tls::with_opt<rustc_middle[7492fbb28f48ec2e]::util::bug::opt_span_bug_fmt<rustc_span[ba0d7ae542c94e2e]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7ffa26f59ee0 - rustc_middle[7492fbb28f48ec2e]::util::bug::bug_fmt
  22:     0x7ffa282b3637 - <rustc_const_eval[c77aacba90eb860b]::interpret::validity::ValidityVisitor<rustc_const_eval[c77aacba90eb860b]::const_eval::machine::CompileTimeInterpreter>>::check_wide_ptr_meta
  23:     0x7ffa296d0953 - <rustc_const_eval[c77aacba90eb860b]::interpret::validity::ValidityVisitor<rustc_const_eval[c77aacba90eb860b]::const_eval::machine::CompileTimeInterpreter> as rustc_const_eval[c77aacba90eb860b]::interpret::visitor::ValueVisitor<rustc_const_eval[c77aacba90eb860b]::const_eval::machine::CompileTimeInterpreter>>::visit_value
  24:     0x7ffa2a4a8db1 - rustc_const_eval[c77aacba90eb860b]::const_eval::eval_queries::eval_in_interpreter
  25:     0x7ffa29f60393 - rustc_const_eval[c77aacba90eb860b]::const_eval::eval_queries::eval_static_initializer_provider
  26:     0x7ffa29f60195 - rustc_query_impl[c8e011bed631d2ff]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c8e011bed631d2ff]::query_impl::eval_static_initializer::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7492fbb28f48ec2e]::query::erase::Erased<[u8; 16usize]>>
  27:     0x7ffa29f60167 - <rustc_query_impl[c8e011bed631d2ff]::query_impl::eval_static_initializer::dynamic_query::{closure#2} as core[f643d38b75b51528]::ops::function::FnOnce<(rustc_middle[7492fbb28f48ec2e]::ty::context::TyCtxt, rustc_span[ba0d7ae542c94e2e]::def_id::DefId)>>::call_once
  28:     0x7ffa29929a41 - rustc_query_system[33ba2b8a2c2ab98f]::query::plumbing::try_execute_query::<rustc_query_impl[c8e011bed631d2ff]::DynamicConfig<rustc_query_system[33ba2b8a2c2ab98f]::query::caches::DefIdCache<rustc_middle[7492fbb28f48ec2e]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[c8e011bed631d2ff]::plumbing::QueryCtxt, false>
  29:     0x7ffa2a5b3b71 - rustc_query_impl[c8e011bed631d2ff]::query_impl::eval_static_initializer::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7ffa297cbe83 - <rustc_middle[7492fbb28f48ec2e]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[49ec76ea6559053a]::check_crate::{closure#3}>::{closure#0}
  31:     0x7ffa297ca5c6 - rustc_hir_analysis[49ec76ea6559053a]::check_crate
  32:     0x7ffa29cc4e6a - rustc_interface[b4344970d0253b12]::passes::analysis
  33:     0x7ffa29cc4aa5 - rustc_query_impl[c8e011bed631d2ff]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c8e011bed631d2ff]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7492fbb28f48ec2e]::query::erase::Erased<[u8; 1usize]>>
  34:     0x7ffa2a425c25 - rustc_query_system[33ba2b8a2c2ab98f]::query::plumbing::try_execute_query::<rustc_query_impl[c8e011bed631d2ff]::DynamicConfig<rustc_query_system[33ba2b8a2c2ab98f]::query::caches::SingleCache<rustc_middle[7492fbb28f48ec2e]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c8e011bed631d2ff]::plumbing::QueryCtxt, false>
  35:     0x7ffa2a425989 - rustc_query_impl[c8e011bed631d2ff]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7ffa2a12fd04 - rustc_interface[b4344970d0253b12]::interface::run_compiler::<core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>, rustc_driver_impl[5ed4bc6caf392c18]::run_compiler::{closure#0}>::{closure#0}
  37:     0x7ffa2a62ef45 - std[51808fdf74a5b252]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b4344970d0253b12]::util::run_in_thread_with_globals<rustc_interface[b4344970d0253b12]::util::run_in_thread_pool_with_globals<rustc_interface[b4344970d0253b12]::interface::run_compiler<core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>, rustc_driver_impl[5ed4bc6caf392c18]::run_compiler::{closure#0}>::{closure#0}, core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>>::{closure#0}, core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>>
  38:     0x7ffa2a62ed72 - <<std[51808fdf74a5b252]::thread::Builder>::spawn_unchecked_<rustc_interface[b4344970d0253b12]::util::run_in_thread_with_globals<rustc_interface[b4344970d0253b12]::util::run_in_thread_pool_with_globals<rustc_interface[b4344970d0253b12]::interface::run_compiler<core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>, rustc_driver_impl[5ed4bc6caf392c18]::run_compiler::{closure#0}>::{closure#0}, core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>>::{closure#0}, core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f643d38b75b51528]::result::Result<(), rustc_span[ba0d7ae542c94e2e]::ErrorGuaranteed>>::{closure#1} as core[f643d38b75b51528]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7ffa25399505 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h97ea3917b3b3035c
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/alloc/src/boxed.rs:2020:9
  40:     0x7ffa25399505 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf2f1ed3ae326d6aa
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/alloc/src/boxed.rs:2020:9
  41:     0x7ffa25399505 - std::sys::pal::unix::thread::Thread::new::thread_start::h2c562c9f4cefc069
                               at /rustc/6f3eb1ce3d50246b2cbc5de3107c0f34889f5cc6/library/std/src/sys/pal/unix/thread.rs:108:17
  42:     0x7ffa2514b55a - <unknown>
  43:     0x7ffa251c8a3c - <unknown>
  44:                0x0 - <unknown>

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.78.0-nightly (6f3eb1ce3 2024-03-14) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `arena::__stability::DATA`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0277, E0392, E0425, E0601.
For more information about an error, try `rustc --explain E0277`.

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Mar 14, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 14, 2024
  3. matthiaskrgr commented on Mar 14, 2024

    @matthiaskrgr
    MemberAuthor
  4. added
    A-codegenArea: Code generation
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Mar 14, 2024
  5. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Apr 4, 2024
  6. matthiaskrgr commented on Apr 4, 2024

    @matthiaskrgr
    MemberAuthor

    maybe fixed by #121546

  7. gurry commented on Apr 5, 2024

    @gurry
    Contributor

    It is indeed fixed by #121546 . Does not ICE with the latest nightly.

  8. added a commit that references this issue on Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions