Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: Slice pattern matching with constant slice and slice literal #55911

Closed
Brekcel opened this issue Nov 13, 2018 · 1 comment · Fixed by #55922
Closed

ICE: Slice pattern matching with constant slice and slice literal #55911

Brekcel opened this issue Nov 13, 2018 · 1 comment · Fixed by #55922
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Brekcel
Copy link

Brekcel commented Nov 13, 2018

Attempting to pattern match a slice with a constant value and THEN a slice literal causes an ICE.

Simple test case:

fn main() {
	let s = &[0x00; 4][..]; //Slice of any value
	const MAGIC_TEST: &[u8] = b"TEST"; //Const slice to pattern match with
	match 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 fine
fn main() {
	let s = &[0x00; 4][..]; //Slice of any value
	const MAGIC_TEST: &[u8] = b"TEST"; //Const slice to pattern match with
	match s {
		[0x00, 0x00, 0x00, 0x00] => (), // Only thing changes was the order of these 2
		MAGIC_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)

rustc version:

B:\slice_ice>rustc --version --verbose
rustc 1.30.1 (1433507eb 2018-11-07)
binary: rustc
commit-hash: 1433507eba7d1a114e4c6f27ae0e1a74f60f20de
commit-date: 2018-11-07
host: x86_64-pc-windows-msvc
release: 1.30.1
LLVM version: 8.0
@zackmdavis zackmdavis added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Nov 13, 2018
@oli-obk oli-obk self-assigned this Nov 13, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Nov 13, 2018

So... I do have a fix for byte slices, but that just exposed that we have the same ICE for other slices:

fn main() {
	let s = &[0x00; 4][..]; //Slice of any value
	const MAGIC_TEST: &[u32] = &[1, 2, 3, 4]; //Const slice to pattern match with
	match 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.

bors added a commit that referenced this issue Dec 5, 2018
Fix ICE in `const` slice patterns

fixes #55911

based on #55915

New commits start at eabc1551e0d0953f1951020afb5919ab4c129cf5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants