Skip to content

Commit c4c848c

Browse files
zachs18RalfJung
andauthored
Update compiler/rustc_const_eval/src/const_eval/machine.rs
Co-authored-by: Ralf Jung <[email protected]>
1 parent 2a24220 commit c4c848c

File tree

1 file changed

+2
-10
lines changed
  • compiler/rustc_const_eval/src/const_eval

1 file changed

+2
-10
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,8 @@ impl<'tcx> CompileTimeInterpCx<'tcx> {
280280
interp_ok(match (a, b) {
281281
// Comparisons between integers are always known.
282282
(Scalar::Int(a), Scalar::Int(b)) => (a == b) as u8,
283-
// A pointer can be known to be unequal to an integer if them being equal would imply
284-
// that the null pointer is in-bounds (including one-past-the-end) of the pointer's
285-
// allocation (as the null pointer is never in-bounds of any allocation), or is
286-
// misaligned (as `0` is a multiple of any alignment), or that the pointer's
287-
// allocation would wrap around the address space.
288-
// Concretely, if `scalar_may_be_null` indicates that `ptr.wrapping_sub(int)` cannot
289-
// be equal to `0`, then we know that `ptr != int`.
290-
// For the specific case where `int == 0`, this checks if the pointer itself
291-
// can definitely not be null, and this behavior is exposed on stable as
292-
// `pointer::is_null`.
283+
// Comparing a pointer `ptr` with an integer `int` is equivalent to comparing
284+
// `ptr-int` with null, so we can reduce this case to a `scalar_may_be_null` test.
293285
(Scalar::Int(int), Scalar::Ptr(ptr, _)) | (Scalar::Ptr(ptr, _), Scalar::Int(int)) => {
294286
let int = int.to_target_usize(*self.tcx);
295287
let offset_ptr = ptr.wrapping_offset(Size::from_bytes(int.wrapping_neg()), self);

0 commit comments

Comments
 (0)