Change:
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:
So... I do have a fix for byte slices, but that just exposed that we have the same ICE for other slices: This can be fixed, too, but I need to wait for to be merged before being able to do this in a reasonable way.

Discussion:
/// outside it's module and should not be matchable with an empty match /// statement. pub module: DefId, <ins> param_env: ty::ParamEnv<'tcx>, </ins> pub pattern_arena: &'a TypedArena<Pattern<'tcx>>, pub byte_array_map: FxHashMap<*const Pattern<'tcx>, Vec<&'a Pattern<'tcx>>>, }

impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> { pub fn create_and_enter<F, R>( tcx: TyCtxt<'a, 'tcx, 'tcx>, <ins> param_env: ty::ParamEnv<'tcx>, </ins> module: DefId, f: F) -> R where F: for<'b> FnOnce(MatchCheckCtxt<'b, 'tcx>) -> R

f(MatchCheckCtxt { tcx, <ins> param_env, </ins> module, pattern_arena: &pattern_arena, byte_array_map: FxHashMap::default(), }) } <del> // convert a byte-string pattern to a list of u8 patterns. fn lower_byte_str_pattern<'p>(&mut self, pat: &'p Pattern<'tcx>) -> Vec<&'p Pattern<'tcx>> where 'a: 'p { let pattern_arena = &*self.pattern_arena; let tcx = self.tcx; self.byte_array_map.entry(pat).or_insert_with(|| { match pat.kind { box PatternKind::Constant { value: const_val } => { if let Some(ptr) = const_val.to_ptr() { let is_array_ptr = const_val.ty .builtin_deref(true) .and_then(|t| t.ty.builtin_index()) .map_or(false, |t| t == tcx.types.u8); assert!(is_array_ptr); let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id); assert_eq!(ptr.offset.bytes(), 0); // FIXME: check length alloc.bytes.iter().map(|b| { &*pattern_arena.alloc(Pattern { ty: tcx.types.u8, span: pat.span, kind: box PatternKind::Constant { value: ty::Const::from_bits( tcx, *b as u128, ty::ParamEnv::empty().and(tcx.types.u8)) } }) }).collect() } else { bug!("not a byte str: {:?}", const_val) } } _ => span_bug!(pat.span, "unexpected byte array pattern {:?}", pat) } }).clone() } </del> fn is_uninhabited(&self, ty: Ty<'tcx>) -> bool { if self.tcx.features().exhaustive_patterns { self.tcx.is_ty_uninhabited_from(self.module, ty)

ConstValue::Scalar(val) | ConstValue::ScalarPair(val, _) => val, }; if let Ok(ptr) = val.to_ptr() { <del> let is_array_ptr = const_val.ty .builtin_deref(true) .and_then(|t| t.ty.builtin_index()) .map_or(false, |t| t == tcx.types.u8); assert!(is_array_ptr); </del> tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id).bytes.as_ref() } else { bug!("unexpected non-ptr ConstantValue")

PatternKind::Constant { value } => { match *constructor { Slice(..) => { <del> if let Some(ptr) = value.to_ptr() { let is_array_ptr = value.ty .builtin_deref(true) .and_then(|t| t.ty.builtin_index()) .map_or(false, |t| t == cx.tcx.types.u8); assert!(is_array_ptr); let data_len = cx.tcx .alloc_map .lock() .unwrap_memory(ptr.alloc_id) .bytes .len(); if wild_patterns.len() == data_len { Some(cx.lower_byte_str_pattern(pat)) } else { None </del> <ins> // we extract an `Option` for the pointer because slices of zero elements don't // necessarily point to memory, they are usually just integers. The only time // they should be pointing to memory is when they are subslices of nonzero // slices let (opt_ptr, n, ty) = match value.ty.builtin_deref(false).unwrap().ty.sty { ty::TyKind::Array(t, n) => (value.to_ptr(), n.unwrap_usize(cx.tcx), t), ty::TyKind::Slice(t) => { match value.val { ConstValue::ScalarPair(ptr, n) => ( ptr.to_ptr().ok(), n.to_bits(cx.tcx.data_layout.pointer_size).unwrap() as u64, t, ), _ => span_bug!( pat.span, "slice pattern constant must be scalar pair but is {:?}", value, ), } }, _ => span_bug!( pat.span, "unexpected const-val {:?} with ctor {:?}", value, constructor, ), }; if wild_patterns.len() as u64 == n { // convert a constant slice/array pattern to a list of patterns. match (n, opt_ptr) { (0, _) => Some(Vec::new()), (_, Some(ptr)) => { let alloc = cx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id); let layout = cx.tcx.layout_of(cx.param_env.and(ty)).ok()?; (0..n).map(|i| { let ptr = ptr.offset(layout.size * i, &cx.tcx).ok()?; let scalar = alloc.read_scalar( &cx.tcx, ptr, layout.size, ).ok()?; let scalar = scalar.not_undef().ok()?; let value = ty::Const::from_scalar(cx.tcx, scalar, ty); let pattern = Pattern { ty, span: pat.span, kind: box PatternKind::Constant { value }, }; Some(&*cx.pattern_arena.alloc(pattern)) }).collect() }, (_, None) => span_bug!( pat.span, "non zero length slice with const-val {:?}", value, ), </ins> } } else { <del> span_bug!(pat.span, "unexpected const-val {:?} with ctor {:?}", value, constructor) </del> <ins> None </ins> } } _ => {

} let module = self.tcx.hir.get_module_parent(scrut.id); <del> MatchCheckCtxt::create_and_enter(self.tcx, module, |ref mut cx| { </del> <ins> MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { </ins> let mut have_errors = false; let inlined_arms : Vec<(Vec<_>, _)> = arms.iter().map(|arm| (

fn check_irrefutable(&self, pat: &'tcx Pat, origin: &str) { let module = self.tcx.hir.get_module_parent(pat.id); <del> MatchCheckCtxt::create_and_enter(self.tcx, module, |ref mut cx| { </del> <ins> MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { </ins> let mut patcx = PatternContext::new(self.tcx, self.param_env.and(self.identity_substs), self.tables);

<ins> // compile-pass fn main() { let s = &[0x00; 4][..]; //Slice of any value const MAGIC_TEST: &[u32] = &[4, 5, 6, 7]; //Const slice to pattern match with match s { MAGIC_TEST => (), [0x00, 0x00, 0x00, 0x00] => (), [4, 5, 6, 7] => (), // this should warn _ => (), } match s { [0x00, 0x00, 0x00, 0x00] => (), MAGIC_TEST => (), [4, 5, 6, 7] => (), // this should warn _ => (), } match s { [0x00, 0x00, 0x00, 0x00] => (), [4, 5, 6, 7] => (), MAGIC_TEST => (), // this should warn _ => (), } } </ins>

<ins> // compile-pass fn main() { let s = &["0x00"; 4][..]; //Slice of any value const MAGIC_TEST: &[&str] = &["4", "5", "6", "7"]; //Const slice to pattern match with match s { MAGIC_TEST => (), ["0x00", "0x00", "0x00", "0x00"] => (), ["4", "5", "6", "7"] => (), // this should warn _ => (), } match s { ["0x00", "0x00", "0x00", "0x00"] => (), MAGIC_TEST => (), ["4", "5", "6", "7"] => (), // this should warn _ => (), } match s { ["0x00", "0x00", "0x00", "0x00"] => (), ["4", "5", "6", "7"] => (), MAGIC_TEST => (), // this should warn _ => (), } } </ins>

<ins> //compile-pass 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] => (), [84, 69, 83, 84] => (), // this should warn _ => (), } match s { [0x00, 0x00, 0x00, 0x00] => (), MAGIC_TEST => (), [84, 69, 83, 84] => (), // this should warn _ => (), } match s { [0x00, 0x00, 0x00, 0x00] => (), [84, 69, 83, 84] => (), MAGIC_TEST => (), // this should warn _ => (), } } </ins>