Closed
Description
I recently updated my nightly toolchain for rust, and compiled a project I was working on. Previously I was on the nightly-2018-04-19-x86_64-pc-windows-msvc
version, and updated to the nightly-2018-04-29-x86_64-pc-windows-msvc
version. I encountered a compiler error when dealing with match
statements and Associated Constants, centered around alignment issues of the associated constant.
After some testing, I managed to create a simple example with the code below:
#[derive(PartialEq, Eq)] // Needed for pattern matching
#[repr(packed)] // Commenting out this line removes the error
pub struct Num(u64);
impl Num {
const ZERO: Self = Num(0); // Error points to this line as the alignment issue
}
fn decrement(a: Num) -> Num {
match a {
// Matching Num against Num::Zero with repr(packed) causes alignment error:
Num::ZERO => Num::ZERO, // Commenting out this line removes the error
a => Num(a.0 - 1)
}
}
fn main() {
}
cargo build
:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ConstEvalErr { span: src\main.rs:6:5: 6:31, kind: Miri(EvalError { kind: AlignmentCheckFailed { required: 8, has: 1 }, backtrace: None }, []) }', libcore\result.rs:945:5
stack backtrace:
0: <std::collections::hash::map::DefaultHasher as core::fmt::Debug>::fmt
1: <std::sys::windows::os_str::Buf as std::sys_common::IntoInner<std::sys_common::wtf8::Wtf8Buf>>::into_inner
2: std::panicking::take_hook
3: std::panicking::take_hook
4: rustc::ty::structural_impls::<impl rustc::ty::context::Lift<'tcx> for rustc::middle::const_val::ErrKind<'a>>::lift_to_tcx
5: std::panicking::rust_panic_with_hook
6: std::panicking::begin_panic_fmt
7: rust_begin_unwind
8: core::panicking::panic_fmt
9: <rustc_mir::transform::inline::CallSite<'tcx> as core::fmt::Debug>::fmt
10: rustc_mir::hair::pattern::PatternContext::lower_pattern
11: <unknown>
12: rustc_mir::hair::pattern::PatternContext::lower_pattern
13: rustc_mir::hair::pattern::PatternContext::lower_pattern
14: rustc_mir::hair::pattern::PatternContext::lower_pattern
15: <rustc_mir::transform::inline::CallSite<'tcx> as core::fmt::Debug>::fmt
16: <unknown>
17: <unknown>
18: <rustc_mir::hair::pattern::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
19: <rustc_mir::hair::pattern::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
20: <rustc_mir::monomorphize::collector::MonoItemCollectionMode as core::fmt::Debug>::fmt
21: rustc_mir::hair::pattern::check_match::check_crate
22: rustc::ty::context::tls::track_diagnostic
23: rustc::dep_graph::graph::DepGraph::assert_ignored
24: rustc::ty::context::tls::track_diagnostic
25: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
26: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
27: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::check_match
28: <rustc_mir::transform::inline::CallSite<'tcx> as core::fmt::Debug>::fmt
29: <rustc_mir::monomorphize::collector::MonoItemCollectionMode as core::fmt::Debug>::fmt
30: rustc_mir::hair::pattern::check_match::check_crate
31: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
32: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
33: <unknown>
34: rustc_driver::driver::compile_input
35: rustc_driver::run_compiler
36: rustc_driver::target_features::add_configuration
37: <unknown>
38: rustc_driver::target_features::add_configuration
39: _rust_maybe_catch_panic
40: rustc_driver::profile::trace::write_style
41: rustc_driver::main
42: <unknown>
43: std::panicking::update_panic_count
44: _rust_maybe_catch_panic
45: std::rt::lang_start_internal
46: <unknown>
47: <unknown>
48: BaseThreadInitThunk
49: RtlUserThreadStart
query stack during panic:
#0 [check_match] processing `decrement`
end of query stack
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/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.27.0-nightly (79252ff4e 2018-04-29) running on x86_64-pc-windows-msvc
note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `error-example`.
To learn more, run the command again with --verbose.
Meta
rustc --version --verbose
:
rustc 1.27.0-nightly (79252ff4e 2018-04-29)
binary: rustc
commit-hash: 79252ff4e25d82f9fe856cb66f127b79cdace163
commit-date: 2018-04-29
host: x86_64-pc-windows-msvc
release: 1.27.0-nightly
LLVM version: 6.0
I've also tested and encountered this error on the following versions:
- nightly-2018-04-27-x86_64-pc-windows-msvc
- nightly-2018-04-28-x86_64-pc-windows-msvc
- nightly-2018-04-29-x86_64-pc-windows-msvc
- nightly-2018-04-30-x86_64-pc-windows-msvc