Skip to content

Commit cfd5fb5

Browse files
committed
Reuse to_bits instead of badly reinventing it
1 parent 50628b7 commit cfd5fb5

File tree

1 file changed

+14
-17
lines changed
  • src/librustc_mir/hair/pattern

1 file changed

+14
-17
lines changed

src/librustc_mir/hair/pattern/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,27 +1092,24 @@ pub fn compare_const_vals<'a, 'tcx>(
10921092
(
10931093
Some(Value::ScalarPair(
10941094
Scalar::Ptr(ptr_a),
1095-
Scalar::Bits {
1096-
bits: size_a,
1097-
defined: defined_a,
1098-
},
1095+
len_a,
10991096
)),
11001097
Some(Value::ScalarPair(
11011098
Scalar::Ptr(ptr_b),
1102-
Scalar::Bits {
1103-
bits: size_b,
1104-
defined: defined_b,
1105-
},
1099+
len_b,
11061100
))
1107-
) if size_a == size_b &&
1108-
ptr_a.offset.bytes() == 0 && ptr_b.offset.bytes() == 0 &&
1109-
tcx.data_layout.pointer_size.bits() <= defined_a.into() &&
1110-
tcx.data_layout.pointer_size.bits() <= defined_b.into() => {
1111-
let map = tcx.alloc_map.lock();
1112-
let alloc_a = map.unwrap_memory(ptr_a.alloc_id);
1113-
let alloc_b = map.unwrap_memory(ptr_b.alloc_id);
1114-
if alloc_a.bytes.len() as u64 == size_a as u64 {
1115-
return from_bool(alloc_a == alloc_b);
1101+
) if ptr_a.offset.bytes() == 0 && ptr_b.offset.bytes() == 0 => {
1102+
if let Ok(len_a) = len_a.to_bits(tcx.data_layout.pointer_size) {
1103+
if let Ok(len_b) = len_b.to_bits(tcx.data_layout.pointer_size) {
1104+
if len_a == len_b {
1105+
let map = tcx.alloc_map.lock();
1106+
let alloc_a = map.unwrap_memory(ptr_a.alloc_id);
1107+
let alloc_b = map.unwrap_memory(ptr_b.alloc_id);
1108+
if alloc_a.bytes.len() as u128 == len_a {
1109+
return from_bool(alloc_a == alloc_b);
1110+
}
1111+
}
1112+
}
11161113
}
11171114
}
11181115
_ => (),

0 commit comments

Comments
 (0)