Description
Rust beginner here. I was trying something out on the Playground, turns out I didn't understand how to use wrapping_add
correctly; but following a sequence of suggested fixes from the compiler I arrived at the below, which gives two internal compiler errors. I asked on Discord and was told it is worth reporting it here, even though this code is incorrect and uses an unstable library feature.
Code
#![feature(core_intrinsics)]
use std::intrinsics::wrapping_add;
#[derive(Clone, Copy)]
struct WrapInt8 {
value: u8
}
impl std::ops::Add for WrapInt8 {
type Output = WrapInt8;
fn add(self, other: WrapInt8) -> WrapInt8 {
wrapping_add(self, other)
}
}
fn main() {
let p = WrapInt8 { value: 123 };
let q = WrapInt8 { value: 234 };
println!("{}", (p + q).value);
}
Meta
This occurred on the Playground, using the current nightly build (1.63.0-nightly, 2022-05-27 ebbcbfc).
Error output
Compiling playground v0.0.1 (/playground)
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:8 ~ playground[3faf]::{impl#0}::add), const_param_did: None }) (end of phase transition to Optimized) at bb0[2]:
Cannot perform arithmetic on type WrapInt8
--> src/main.rs:12:9
|
12 | wrapping_add(self, other)
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:127:36
thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1368:13
stack backtrace:
0: 0x7f216626ffcd - std::backtrace_rs::backtrace::libunwind::trace::h9dd319c001cd5d5b
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x7f216626ffcd - std::backtrace_rs::backtrace::trace_unsynchronized::h5cdb9413f7b7f703
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x7f216626ffcd - std::sys_common::backtrace::_print_fmt::h62e01fe71d2f0609
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/sys_common/backtrace.rs:66:5
3: 0x7f216626ffcd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb568664ce7d28696
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/sys_common/backtrace.rs:45:22
4: 0x7f21662cbe5c - core::fmt::write::hff09181fc8f150c2
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/core/src/fmt/mod.rs:1196:17
5: 0x7f21662616c1 - std::io::Write::write_fmt::h77801493f17dbb5a
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/io/mod.rs:1654:15
6: 0x7f2166272cb5 - std::sys_common::backtrace::_print::hace3cc1f256ece45
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/sys_common/backtrace.rs:48:5
7: 0x7f2166272cb5 - std::sys_common::backtrace::print::hc1b81d3f2867b83b
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/sys_common/backtrace.rs:35:9
8: 0x7f2166272cb5 - std::panicking::default_hook::{{closure}}::he802b1e81f85775c
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/panicking.rs:295:22
9: 0x7f21662729d6 - std::panicking::default_hook::h57b0d510bf2c9fe7
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/panicking.rs:314:9
10: 0x7f2166a3c211 - rustc_driver[8a2d58f6f4bf431a]::DEFAULT_HOOK::{closure#0}::{closure#0}
11: 0x7f216627338a - std::panicking::rust_panic_with_hook::hdd373bc6c22fa56f
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/panicking.rs:702:17
12: 0x7f2167bdb181 - std[aa967257b9f8f73b]::panicking::begin_panic::<rustc_errors[1ed68885dba1d6d1]::ExplicitBug>::{closure#0}
13: 0x7f2167bd9e06 - std[aa967257b9f8f73b]::sys_common::backtrace::__rust_end_short_backtrace::<std[aa967257b9f8f73b]::panicking::begin_panic<rustc_errors[1ed68885dba1d6d1]::ExplicitBug>::{closure#0}, !>
14: 0x7f2167bedd56 - std[aa967257b9f8f73b]::panicking::begin_panic::<rustc_errors[1ed68885dba1d6d1]::ExplicitBug>
15: 0x7f2167bf1ec6 - std[aa967257b9f8f73b]::panic::panic_any::<rustc_errors[1ed68885dba1d6d1]::ExplicitBug>
16: 0x7f21694638e1 - <rustc_errors[1ed68885dba1d6d1]::HandlerInner as core[8467f2214112d7a4]::ops::drop::Drop>::drop
17: 0x7f2168bcf7a8 - core[8467f2214112d7a4]::ptr::drop_in_place::<rustc_session[f5a33ef05da8b8fa]::parse::ParseSess>
18: 0x7f2168bd1ac3 - <alloc[e5cd0633e65a6c1f]::rc::Rc<rustc_session[f5a33ef05da8b8fa]::session::Session> as core[8467f2214112d7a4]::ops::drop::Drop>::drop
19: 0x7f2168bce36d - core[8467f2214112d7a4]::ptr::drop_in_place::<rustc_interface[b93c8180971df832]::interface::Compiler>
20: 0x7f2168bcdd94 - rustc_span[4bbade9624b8160a]::with_source_map::<core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>, rustc_interface[b93c8180971df832]::interface::create_compiler_and_run<core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>, rustc_driver[8a2d58f6f4bf431a]::run_compiler::{closure#1}>::{closure#1}>
21: 0x7f2168bba454 - rustc_interface[b93c8180971df832]::interface::create_compiler_and_run::<core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>, rustc_driver[8a2d58f6f4bf431a]::run_compiler::{closure#1}>
22: 0x7f2168ba4792 - <scoped_tls[6dc72d687799c0be]::ScopedKey<rustc_span[4bbade9624b8160a]::SessionGlobals>>::set::<rustc_interface[b93c8180971df832]::interface::run_compiler<core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>, rustc_driver[8a2d58f6f4bf431a]::run_compiler::{closure#1}>::{closure#0}, core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>>
23: 0x7f2168bbbb3f - std[aa967257b9f8f73b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b93c8180971df832]::util::run_in_thread_pool_with_globals<rustc_interface[b93c8180971df832]::interface::run_compiler<core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>, rustc_driver[8a2d58f6f4bf431a]::run_compiler::{closure#1}>::{closure#0}, core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>>::{closure#0}, core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>>
24: 0x7f2168bbbc79 - <<std[aa967257b9f8f73b]::thread::Builder>::spawn_unchecked_<rustc_interface[b93c8180971df832]::util::run_in_thread_pool_with_globals<rustc_interface[b93c8180971df832]::interface::run_compiler<core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>, rustc_driver[8a2d58f6f4bf431a]::run_compiler::{closure#1}>::{closure#0}, core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>>::{closure#0}, core[8467f2214112d7a4]::result::Result<(), rustc_errors[1ed68885dba1d6d1]::ErrorGuaranteed>>::{closure#1} as core[8467f2214112d7a4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
25: 0x7f216627d2a3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hf3233b13e94151c3
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/alloc/src/boxed.rs:1872:9
26: 0x7f216627d2a3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4e8ef0a8db850d9e
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/alloc/src/boxed.rs:1872:9
27: 0x7f216627d2a3 - std::sys::unix::thread::Thread::new::thread_start::haa7458da1d6aafbd
at /rustc/ebbcbfc236ced21d5e6a92269edb704692ff26b8/library/std/src/sys/unix/thread.rs:108:17
28: 0x7f21661a3609 - start_thread
29: 0x7f21660c6133 - clone
30: 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.63.0-nightly (ebbcbfc23 2022-05-27) running on x86_64-unknown-linux-gnu
note: compiler flags: --crate-type bin -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:
end of query stack
error: could not compile `playground`
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: IntrinsicsArea: Suggestions generated by the compiler applied by `cargo fix`Category: This is a bug.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint; hard to understand for new users.Issue in the "core intrinsics" for internal usage only.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.