Skip to content

ICE: need to be able to compute layouts: Unknown(T) running miri with -Zunpretty-mir #107999

Closed

Description

Code

You can repro with RUSTFLAGS="-Zunpretty=mir" MIRIFLAGS="-Zmir-opt-level=3" cargo miri run

// This test checks that calling `mem::{uninitialized,zeroed}` with certain types results
// in a lint.

use std::mem::{self};
struct Wrap<T> { wrapped: T }

#[allow(unused)]
fn generic<T: 'static>() {
    unsafe {
        let _val: Wrap<&'static T> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.69.0-nightly (20081880a 2023-02-13)
binary: rustc
commit-hash: 20081880ad2a98bbc8c8293f96c5b284d1584d86
commit-date: 2023-02-13
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

Error output

warning: use of deprecated function `std::mem::uninitialized`: use `mem::MaybeUninit` instead
  --> src/main.rs:10:43
   |
10 |         let _val: Wrap<&'static T> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
   |                                           ^^^^^^^^^^^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: field `wrapped` is never read
 --> src/main.rs:5:18
  |
5 | struct Wrap<T> { wrapped: T }
  |        ----      ^^^^^^^
  |        |
  |        field in this struct
  |
  = note: `#[warn(dead_code)]` on by default

warning: the type `Wrap<&T>` does not permit being left uninitialized
  --> src/main.rs:10:38
   |
10 |         let _val: Wrap<&'static T> = mem::uninitialized(); //~ ERROR: does not permit being left uninitialized
   |                                      ^^^^^^^^^^^^^^^^^^^^
   |                                      |
   |                                      this code causes undefined behavior when executed
   |                                      help: use `MaybeUninit<T>` instead, and only call `assume_init` after initialization is done
   |
   = note: `Wrap<&T>` must be non-null
note: because references must be non-null (in this struct field)
  --> src/main.rs:5:18
   |
5  | struct Wrap<T> { wrapped: T }
   |                  ^^^^^^^^^^
   = note: `#[warn(invalid_value)]` on by default
Backtrace


thread 'rustc' panicked at 'need to be able to compute layouts: Unknown(T)', compiler/rustc_const_eval/src/util/might_permit_raw_init.rs:111:48
stack backtrace:
   0:     0x7febf276a9ea - std::backtrace_rs::backtrace::libunwind::trace::h599c8a609f9333f9
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7febf276a9ea - std::backtrace_rs::backtrace::trace_unsynchronized::hd98c4236d5e12dd3
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7febf276a9ea - std::sys_common::backtrace::_print_fmt::h5e56057600010abc
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7febf276a9ea - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6c880a29175ff5a3
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7febf27caafe - core::fmt::write::hfc0242af538b8a46
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/core/src/fmt/mod.rs:1232:17
   5:     0x7febf275b005 - std::io::Write::write_fmt::h01aa30c6b6ac7c12
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/io/mod.rs:1684:15
   6:     0x7febf276a7b5 - std::sys_common::backtrace::_print::hffab19929157fc64
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7febf276a7b5 - std::sys_common::backtrace::print::hcc10add6529763f5
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7febf276d54f - std::panicking::default_hook::{{closure}}::h7b790581a0467591
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/panicking.rs:267:22
   9:     0x7febf276d28b - std::panicking::default_hook::hea529077c0649ab7
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/panicking.rs:286:9
  10:     0x7febf5adcca4 - <rustc_driver_impl[25fd4ad55bd4d290]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[b6202784567cb4e4]::ops::function::FnOnce<(&core[b6202784567cb4e4]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7febf276dd8a - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h9025e888b11b840d
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/alloc/src/boxed.rs:2002:9
  12:     0x7febf276dd8a - std::panicking::rust_panic_with_hook::hbf88635db69aa1e9
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/panicking.rs:692:13
  13:     0x7febf276db09 - std::panicking::begin_panic_handler::{{closure}}::h0a5dea2fedd0d5a5
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/panicking.rs:579:13
  14:     0x7febf276ae8c - std::sys_common::backtrace::__rust_end_short_backtrace::h2507953ca43dc350
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/sys_common/backtrace.rs:137:18
  15:     0x7febf276d812 - rust_begin_unwind
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/panicking.rs:575:5
  16:     0x7febf27c74a3 - core::panicking::panic_fmt::hf2288fbc08000d27
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/core/src/panicking.rs:64:14
  17:     0x7febf27c7a33 - core::result::unwrap_failed::h949aaa38a1828029
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/core/src/result.rs:1790:5
  18:     0x7febf519ebb1 - rustc_const_eval[344787e6075ccab3]::util::might_permit_raw_init::might_permit_raw_init_lax
  19:     0x7febf519e2ee - rustc_const_eval[344787e6075ccab3]::util::might_permit_raw_init::might_permit_raw_init_lax
  20:     0x7febf519dfb9 - rustc_const_eval[344787e6075ccab3]::util::might_permit_raw_init::might_permit_raw_init
  21:     0x7febf51fa047 - <rustc_query_system[6e05d7961ccd4849]::dep_graph::graph::DepGraph<rustc_middle[26406bea1d07e151]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[26406bea1d07e151]::ty::context::TyCtxt, rustc_middle[26406bea1d07e151]::ty::ParamEnvAnd<rustc_target[88529097bdb44244]::abi::TyAndLayout<rustc_middle[26406bea1d07e151]::ty::Ty>>, bool>
  22:     0x7febf63882d9 - rustc_query_system[6e05d7961ccd4849]::query::plumbing::try_execute_query::<rustc_query_impl[38ddc62a235656bd]::queries::permits_uninit_init, rustc_query_impl[38ddc62a235656bd]::plumbing::QueryCtxt>
  23:     0x7febf63ad825 - rustc_query_system[6e05d7961ccd4849]::query::plumbing::get_query::<rustc_query_impl[38ddc62a235656bd]::queries::permits_uninit_init, rustc_query_impl[38ddc62a235656bd]::plumbing::QueryCtxt, rustc_middle[26406bea1d07e151]::dep_graph::dep_node::DepKind>
  24:     0x7febf642aa67 - <rustc_query_impl[38ddc62a235656bd]::Queries as rustc_middle[26406bea1d07e151]::ty::query::QueryEngine>::permits_uninit_init
  25:     0x7febf61b9f6e - rustc_mir_transform[d56b548caf7a8cfa]::instcombine::intrinsic_assert_panics::mem_uninitialized_valid_predicate
  26:     0x7febf4f7d8a6 - <rustc_mir_transform[d56b548caf7a8cfa]::instcombine::InstCombine as rustc_middle[26406bea1d07e151]::mir::MirPass>::run_pass
  27:     0x7febf41a1fe8 - rustc_mir_transform[d56b548caf7a8cfa]::optimized_mir
  28:     0x7febf4198ff6 - <rustc_query_system[6e05d7961ccd4849]::dep_graph::graph::DepGraph<rustc_middle[26406bea1d07e151]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[26406bea1d07e151]::ty::context::TyCtxt, rustc_span[f166845bd5138698]::def_id::DefId, &rustc_middle[26406bea1d07e151]::mir::Body>
  29:     0x7febf413771d - rustc_query_system[6e05d7961ccd4849]::query::plumbing::try_execute_query::<rustc_query_impl[38ddc62a235656bd]::queries::optimized_mir, rustc_query_impl[38ddc62a235656bd]::plumbing::QueryCtxt>
  30:     0x7febf4135484 - <rustc_middle[26406bea1d07e151]::ty::context::TyCtxt>::instance_mir
  31:     0x7febf5feda35 - rustc_middle[26406bea1d07e151]::mir::pretty::write_mir_pretty
  32:     0x7febf5ab4882 - rustc_driver_impl[25fd4ad55bd4d290]::pretty::print_after_hir_lowering
  33:     0x7febf5aa02cb - <rustc_middle[26406bea1d07e151]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[25fd4ad55bd4d290]::run_compiler::{closure#1}::{closure#2}::{closure#1}, core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>>
  34:     0x7febf4d0aa30 - <rustc_interface[cf329bccbcde2f18]::interface::Compiler>::enter::<rustc_driver_impl[25fd4ad55bd4d290]::run_compiler::{closure#1}::{closure#2}, core[b6202784567cb4e4]::result::Result<core[b6202784567cb4e4]::option::Option<rustc_interface[cf329bccbcde2f18]::queries::Linker>, rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>>
  35:     0x7febf4d058c4 - rustc_span[f166845bd5138698]::with_source_map::<core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>, rustc_interface[cf329bccbcde2f18]::interface::run_compiler<core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>, rustc_driver_impl[25fd4ad55bd4d290]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  36:     0x7febf4d053d4 - <scoped_tls[9115c50d9b00df7e]::ScopedKey<rustc_span[f166845bd5138698]::SessionGlobals>>::set::<rustc_interface[cf329bccbcde2f18]::interface::run_compiler<core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>, rustc_driver_impl[25fd4ad55bd4d290]::run_compiler::{closure#1}>::{closure#0}, core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>>
  37:     0x7febf4d04ad2 - std[b5e4c008489c853a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cf329bccbcde2f18]::util::run_in_thread_pool_with_globals<rustc_interface[cf329bccbcde2f18]::interface::run_compiler<core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>, rustc_driver_impl[25fd4ad55bd4d290]::run_compiler::{closure#1}>::{closure#0}, core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>>
  38:     0x7febf5371eac - <<std[b5e4c008489c853a]::thread::Builder>::spawn_unchecked_<rustc_interface[cf329bccbcde2f18]::util::run_in_thread_pool_with_globals<rustc_interface[cf329bccbcde2f18]::interface::run_compiler<core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>, rustc_driver_impl[25fd4ad55bd4d290]::run_compiler::{closure#1}>::{closure#0}, core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b6202784567cb4e4]::result::Result<(), rustc_errors[51cf6c1aaeeb3d69]::ErrorGuaranteed>>::{closure#1} as core[b6202784567cb4e4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7febf2777d23 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h11a55f6f3d84245d
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/alloc/src/boxed.rs:1988:9
  40:     0x7febf2777d23 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd367d709d06ebfbd
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/alloc/src/boxed.rs:1988:9
  41:     0x7febf2777d23 - std::sys::unix::thread::Thread::new::thread_start::h340e26124c1b592b
                               at /rustc/20081880ad2a98bbc8c8293f96c5b284d1584d86/library/std/src/sys/unix/thread.rs:108:17
  42:     0x7febf24208fd - <unknown>
  43:     0x7febf24a2d20 - <unknown>
  44:                0x0 - <unknown>

error: 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.69.0-nightly (20081880a 2023-02-13) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED] -Z unpretty=mir -Z mir-opt-level=3

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

query stack during panic:
#0 [permits_uninit_init] checking to see if `Wrap<&T>` permits being left uninit
#1 [optimized_mir] optimizing MIR for `generic`
end of query stack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

C-bugCategory: This is a bug.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.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions