Skip to content

Commit

Permalink
Fix another related ICE
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Nov 29, 2018
1 parent 28cc340 commit 8f9a093
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
5 changes: 0 additions & 5 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,11 +1355,6 @@ fn slice_pat_covered_by_constructor<'tcx>(
ConstValue::Scalar(val) | ConstValue::ScalarPair(val, _) => val,
};
if let Ok(ptr) = 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);
tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id).bytes.as_ref()
} else {
bug!("unexpected non-ptr ConstantValue")
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/pattern/slice-pattern-const-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ fn main() {
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
_ => (),
}
}
13 changes: 13 additions & 0 deletions src/test/ui/pattern/slice-pattern-const-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ fn main() {
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
_ => (),
}
}
15 changes: 14 additions & 1 deletion src/test/ui/pattern/slice-pattern-const.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
// compile-pass
//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
_ => (),
}
}

0 comments on commit 8f9a093

Please sign in to comment.