Skip to content

miri panics on const_err #2106

@matthiaskrgr

Description

@matthiaskrgr

similar to #2088

const X: u32 = 5;
const Y: u32 = 6;
const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];

fn main() {
    println!("{}", FOO);
}

rust displays an error here:

error: any use of this value will cause an error
 --> src/main.rs:3:19
  |
3 | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
  | ------------------^^^^^---------------------------
  |                   |
  |                   attempt to compute `5_u32 - 6_u32`, which would overflow
  |
  = note: `#[deny(const_err)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

error: could not compile `mi` due to previous error

while miri panics after displaying its error message

error: any use of this value will cause an error
 --> src/main.rs:3:19
  |
3 | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
  | ------------------^^^^^---------------------------
  |                   |
  |                   attempt to compute `5_u32 - 6_u32`, which would overflow
  |
  = note: `#[deny(const_err)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>

error[E0080]: evaluation of constant value failed
 --> src/main.rs:6:20
  |
6 |     println!("{}", FOO);
  |                    ^^^ referenced constant has errors

error: erroneous constant used
 --> src/main.rs:6:20
  |
6 |     println!("{}", FOO);
  |                    ^^^ referenced constant has errors
  |
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
  = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: src/tools/miri/src/diagnostics.rs:188:21: This error should be impossible in Miri: referenced constant has errors

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/ea92b08383b718e79317b29470cb244c48557cd5/compiler/rustc_errors/src/lib.rs:1324:9
stack backtrace:
   0:     0x7ff57389dead - std::backtrace_rs::backtrace::libunwind::trace::ha82e355503b775ae
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ff57389dead - std::backtrace_rs::backtrace::trace_unsynchronized::h8e110267c4bde050
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff57389dead - std::sys_common::backtrace::_print_fmt::h5f563af01e258275
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7ff57389dead - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hea5b1fa30c1333eb
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7ff5738f9b6c - core::fmt::write::h82dfb1eb62467416
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/core/src/fmt/mod.rs:1194:17
   5:     0x7ff57388f5a1 - std::io::Write::write_fmt::h453cda435b3f142f
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/io/mod.rs:1655:15
   6:     0x7ff5738a0bc5 - std::sys_common::backtrace::_print::hc8f28f28ca4dc2eb
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7ff5738a0bc5 - std::sys_common::backtrace::print::he50667b6c89ab0df
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7ff5738a0bc5 - std::panicking::default_hook::{{closure}}::hefe4dc9c157160a4
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/panicking.rs:295:22
   9:     0x7ff5738a0839 - std::panicking::default_hook::h1376b5b10508fdef
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/panicking.rs:314:9
  10:     0x7ff5740e5ee1 - rustc_driver[5234e93807a03500]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7ff5738a1396 - std::panicking::rust_panic_with_hook::h839908001643daf0
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/panicking.rs:702:17
  12:     0x7ff575170131 - std[da27fefd8cd19b64]::panicking::begin_panic::<rustc_errors[473276f074908285]::ExplicitBug>::{closure#0}
  13:     0x7ff57516a466 - std[da27fefd8cd19b64]::sys_common::backtrace::__rust_end_short_backtrace::<std[da27fefd8cd19b64]::panicking::begin_panic<rustc_errors[473276f074908285]::ExplicitBug>::{closure#0}, !>
  14:     0x7ff5751013a6 - std[da27fefd8cd19b64]::panicking::begin_panic::<rustc_errors[473276f074908285]::ExplicitBug>
  15:     0x7ff5750b8676 - std[da27fefd8cd19b64]::panic::panic_any::<rustc_errors[473276f074908285]::ExplicitBug>
  16:     0x7ff5750b1fb5 - <rustc_errors[473276f074908285]::HandlerInner>::bug::<&alloc[1986a0fec37ee717]::string::String>
  17:     0x7ff5750b19c0 - <rustc_errors[473276f074908285]::Handler>::bug::<&alloc[1986a0fec37ee717]::string::String>
  18:     0x7ff575178afd - rustc_middle[1a99a9759c5accc7]::ty::context::tls::with_opt::<rustc_middle[1a99a9759c5accc7]::util::bug::opt_span_bug_fmt<rustc_span[e19c93a5cc4d231b]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7ff575178e76 - rustc_middle[1a99a9759c5accc7]::util::bug::opt_span_bug_fmt::<rustc_span[e19c93a5cc4d231b]::span_encoding::Span>
  20:     0x7ff575178df3 - rustc_middle[1a99a9759c5accc7]::util::bug::bug_fmt
  21:     0x555a484f351d - miri[6f4523000af34d]::diagnostics::report_error
  22:     0x555a484f9ea3 - miri[6f4523000af34d]::eval::eval_entry
  23:     0x555a4846560b - <rustc_interface[259f7f2d687dc9cd]::passes::QueryContext>::enter::<<miri[ef398ca452135779]::MiriCompilerCalls as rustc_driver[5234e93807a03500]::Callbacks>::after_analysis::{closure#0}, ()>
  24:     0x555a48468d5e - <miri[ef398ca452135779]::MiriCompilerCalls as rustc_driver[5234e93807a03500]::Callbacks>::after_analysis
  25:     0x7ff5761571f5 - <rustc_interface[259f7f2d687dc9cd]::interface::Compiler>::enter::<rustc_driver[5234e93807a03500]::run_compiler::{closure#1}::{closure#2}, core[6c67f8de41fca20a]::result::Result<core[6c67f8de41fca20a]::option::Option<rustc_interface[259f7f2d687dc9cd]::queries::Linker>, rustc_errors[473276f074908285]::ErrorGuaranteed>>
  26:     0x7ff57617f59f - rustc_span[e19c93a5cc4d231b]::with_source_map::<core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>, rustc_interface[259f7f2d687dc9cd]::interface::create_compiler_and_run<core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>, rustc_driver[5234e93807a03500]::run_compiler::{closure#1}>::{closure#1}>
  27:     0x7ff576157f44 - rustc_interface[259f7f2d687dc9cd]::interface::create_compiler_and_run::<core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>, rustc_driver[5234e93807a03500]::run_compiler::{closure#1}>
  28:     0x7ff5761556f2 - <scoped_tls[7f40d5f18d3a19f0]::ScopedKey<rustc_span[e19c93a5cc4d231b]::SessionGlobals>>::set::<rustc_interface[259f7f2d687dc9cd]::interface::run_compiler<core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>, rustc_driver[5234e93807a03500]::run_compiler::{closure#1}>::{closure#0}, core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>>
  29:     0x7ff57616c76f - std[da27fefd8cd19b64]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[259f7f2d687dc9cd]::util::run_in_thread_pool_with_globals<rustc_interface[259f7f2d687dc9cd]::interface::run_compiler<core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>, rustc_driver[5234e93807a03500]::run_compiler::{closure#1}>::{closure#0}, core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>>::{closure#0}, core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>>
  30:     0x7ff57616c8a9 - <<std[da27fefd8cd19b64]::thread::Builder>::spawn_unchecked_<rustc_interface[259f7f2d687dc9cd]::util::run_in_thread_pool_with_globals<rustc_interface[259f7f2d687dc9cd]::interface::run_compiler<core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>, rustc_driver[5234e93807a03500]::run_compiler::{closure#1}>::{closure#0}, core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>>::{closure#0}, core[6c67f8de41fca20a]::result::Result<(), rustc_errors[473276f074908285]::ErrorGuaranteed>>::{closure#1} as core[6c67f8de41fca20a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7ff5738ab2e3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd85bf70b078c05e8
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/alloc/src/boxed.rs:1872:9
  32:     0x7ff5738ab2e3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6a20ba204ab10b14
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/alloc/src/boxed.rs:1872:9
  33:     0x7ff5738ab2e3 - std::sys::unix::thread::Thread::new::thread_start::h6522ecd8b15d879a
                               at /rustc/ea92b08383b718e79317b29470cb244c48557cd5/library/std/src/sys/unix/thread.rs:108:17
  34:     0x7ff57359b5c2 - start_thread
  35:     0x7ff573620584 - __clone
  36:                0x0 - <unknown>

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.62.0-nightly (ea92b0838 2022-05-07) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental -C target-cpu=native

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

query stack during panic:
end of query stack
error: aborting due to 4 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions