You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to pattern match a slice with a constant value and THEN a slice literal causes an ICE.
Simple test case:
fnmain(){let s = &[0x00;4][..];//Slice of any valueconstMAGIC_TEST:&[u8] = b"TEST";//Const slice to pattern match withmatch s {MAGIC_TEST => (),[0x00,0x00,0x00,0x00] => (),
_ => ()}}
However simply changing the order to test the slice literal and then the const slice compiles fine:
//Compiles finefnmain(){let s = &[0x00;4][..];//Slice of any valueconstMAGIC_TEST:&[u8] = b"TEST";//Const slice to pattern match withmatch s {[0x00,0x00,0x00,0x00] => (),// Only thing changes was the order of these 2MAGIC_TEST => (),// Only thing changes was the order of these 2
_ => ()}}
Error message:
B:\slice_ice>cargo run --verbose
Compiling slice_ice v0.1.0 (B:\slice_ice)
Running `rustc --crate-name slice_ice src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=f42f6a124a503700 -C extra-filename=-f42f6a124a503700 --out-dir B:\slice_ice\target\debug\deps -C incremental=B:\slice_ice\target\debug\incremental -L dependency=B:\slice_ice\target\debug\deps`
error: internal compiler error: librustc_mir\hair\pattern\_match.rs:1679: unexpected const-val Const { ty: &[u8], val: ScalarPair(Ptr(Pointer { alloc_id: AllocId(1), offset: Size { raw: 0 } }), Scalar(Bits { size: 8, bits: 4 })) } with ctor Slice(4)
--> src\main.rs:5:3
|
5 | MAGIC_TEST => (),
| ^^^^^^^^^^
thread 'main' panicked at 'Box<Any>', librustc_errors\lib.rs:525:9
stack backtrace:
0: <std::sys::windows::args::Args as core::ops::drop::Drop>::drop
1: <std::ffi::os_str::OsString as std::sys_common::IntoInner<std::sys::windows::os_str::Buf>>::into_inner
2: std::panicking::take_hook
3: std::panicking::take_hook
4: <rustc::ty::sty::Binder<rustc::ty::ProjectionPredicate<'tcx>> as rustc::ty::ToPredicate<'tcx>>::to_predicate
5: std::panicking::rust_panic_with_hook
6: <rustc_mir::build::scope::BreakableScope<'tcx> as core::fmt::Debug>::fmt
7: <rustc_mir::dataflow::graphviz::Edge as core::fmt::Debug>::fmt
8: <unknown>
9: <unknown>
10: <unknown>
11: <unknown>
12: <rustc_mir::dataflow::graphviz::Edge as core::fmt::Debug>::fmt
13: <rustc_mir::dataflow::graphviz::Edge as core::fmt::Debug>::fmt
14: rustc_mir::hair::pattern::_match::split_grouped_constructors::range_borders
15: <unknown>
16: <rustc_mir::hair::pattern::_match::Matrix<'a, 'tcx> as core::fmt::Debug>::fmt
17: <unknown>
18: <rustc_mir::hair::pattern::_match::Matrix<'a, 'tcx> as core::fmt::Debug>::fmt
19: <rustc_mir::hair::pattern::_match::Matrix<'a, 'tcx> as core::fmt::Debug>::fmt
20: <unknown>
21: <rustc_mir::hair::pattern::_match::Matrix<'a, 'tcx> as core::fmt::Debug>::fmt
22: <rustc_mir::hair::pattern::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_body
23: <rustc_mir::hair::pattern::_match::Matrix<'a, 'tcx> as core::fmt::Debug>::fmt
24: <rustc_mir::hair::pattern::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
25: <rustc_mir::hair::pattern::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
26: <rustc_mir::hair::pattern::check_match::MatchVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_body
27: rustc_mir::hair::pattern::check_match::check_crate
28: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
29: rustc::ty::context::tls::track_diagnostic
30: rustc::dep_graph::graph::DepGraph::assert_ignored
31: rustc::ty::context::tls::track_diagnostic
32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
34: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::check_match
35: <rustc_mir::dataflow::move_paths::abs_domain::AbstractOperand as core::fmt::Debug>::fmt
36: rustc_mir::dataflow::impls::MaybeUninitializedPlaces::new
37: rustc_mir::hair::pattern::check_match::check_crate
38: <unknown>
39: <rustc_driver::pretty::IdentifiedAnnotation<'hir> as rustc_driver::pretty::HirPrinterSupport<'hir>>::sess
40: <rustc_driver::CompilationFailure as core::fmt::Debug>::fmt
41: rustc_driver::driver::compile_input
42: rustc_driver::run_compiler
43: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
44: rustc_driver::run_compiler
45: <env_logger::filter::inner::Filter as core::fmt::Display>::fmt
46: _rust_maybe_catch_panic
47: rustc_driver::profile::dump
48: rustc_driver::main
49: <unknown>
50: std::panicking::update_panic_count
51: _rust_maybe_catch_panic
52: std::rt::lang_start_internal
53: <unknown>
54: <unknown>
55: BaseThreadInitThunk
56: RtlUserThreadStart
query stack during panic:
#0 [check_match] processing `main`
end of query stack
error: aborting due to previous error
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.30.1 (1433507eb 2018-11-07) 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 `slice_ice`.
Caused by:
process didn't exit successfully: `rustc --crate-name slice_ice src\main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=f42f6a124a503700 -C extra-filename=-f42f6a124a503700 --out-dir B:\slice_ice\target\debug\deps -C incremental=B:\slice_ice\target\debug\incremental -L dependency=B:\slice_ice\target\debug\deps` (exit code: 101)
So... I do have a fix for byte slices, but that just exposed that we have the same ICE for other slices:
fnmain(){let s = &[0x00;4][..];//Slice of any valueconstMAGIC_TEST:&[u32] = &[1,2,3,4];//Const slice to pattern match withmatch s {MAGIC_TEST => (),[0x00,0x00,0x00,0x00] => (),
_ => ()}}
This can be fixed, too, but I need to wait for #55915 to be merged before being able to do this in a reasonable way.
Attempting to pattern match a slice with a constant value and THEN a slice literal causes an ICE.
Simple test case:
However simply changing the order to test the slice literal and then the const slice compiles fine:
Error message:
rustc version:
The text was updated successfully, but these errors were encountered: