From 9526ce60fd5bb46221f4a0c35dda694aa14716b0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 10 May 2024 16:31:57 +0200 Subject: [PATCH] improve comment wording --- compiler/rustc_const_eval/src/interpret/validity.rs | 3 ++- library/core/src/intrinsics.rs | 4 ++-- library/core/src/ptr/const_ptr.rs | 12 ++++++------ library/core/src/ptr/mut_ptr.rs | 12 ++++++------ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index a47828bb63c25..e36d30184c858 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -434,7 +434,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' found_bytes: has.bytes() }, ); - // Make sure this is non-null. (ZST references can be dereferenceable and null.) + // Make sure this is non-null. We checked dereferenceability above, but if `size` is zero + // that does not imply non-null. if self.ecx.scalar_may_be_null(Scalar::from_maybe_pointer(place.ptr(), self.ecx))? { throw_validation_failure!(self.path, NullPtr { ptr_kind }) } diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 90a7e2bf382e5..33ecaae98e518 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -1484,7 +1484,7 @@ extern "rust-intrinsic" { /// # Safety /// /// If the computed offset is non-zero, then both the starting and resulting pointer must be - /// either in bounds or one byte past the end of an allocated object. If either pointer is out + /// either in bounds or at the end of an allocated object. If either pointer is out /// of bounds or arithmetic overflow occurs then any further use of the returned value will /// result in undefined behavior. /// @@ -1502,7 +1502,7 @@ extern "rust-intrinsic" { /// # Safety /// /// Unlike the `offset` intrinsic, this intrinsic does not restrict the - /// resulting pointer to point into or one byte past the end of an allocated + /// resulting pointer to point into or at the end of an allocated /// object, and it wraps with two's complement arithmetic. The resulting /// value is not necessarily valid to be used to actually access memory. /// diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index 27b0c69d32d0f..c8065b2e70906 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -465,8 +465,8 @@ impl *const T { /// If any of the following conditions are violated, the result is Undefined /// Behavior: /// - /// * If the computed offset is non-zero, then both the starting and resulting pointer must be - /// either in bounds or one byte past the end of the same [allocated object]. + /// * If the computed offset, **in bytes**, is non-zero, then both the starting and resulting + /// pointer must be either in bounds or at the end of the same [allocated object]. /// (If it is zero, then the function is always well-defined.) /// /// * The computed offset, **in bytes**, cannot overflow an `isize`. @@ -952,8 +952,8 @@ impl *const T { /// If any of the following conditions are violated, the result is Undefined /// Behavior: /// - /// * If the computed offset is non-zero, then both the starting and resulting pointer must be - /// either in bounds or one byte past the end of the same [allocated object]. + /// * If the computed offset, **in bytes**, is non-zero, then both the starting and resulting + /// pointer must be either in bounds or at the end of the same [allocated object]. /// (If it is zero, then the function is always well-defined.) /// /// * The computed offset, **in bytes**, cannot overflow an `isize`. @@ -1037,8 +1037,8 @@ impl *const T { /// If any of the following conditions are violated, the result is Undefined /// Behavior: /// - /// * If the computed offset is non-zero, then both the starting and resulting pointer must be - /// either in bounds or one byte past the end of the same [allocated object]. + /// * If the computed offset, **in bytes**, is non-zero, then both the starting and resulting + /// pointer must be either in bounds or at the end of the same [allocated object]. /// (If it is zero, then the function is always well-defined.) /// /// * The computed offset cannot exceed `isize::MAX` **bytes**. diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 3d05715f7a46d..f87496bd400f8 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -480,8 +480,8 @@ impl *mut T { /// If any of the following conditions are violated, the result is Undefined /// Behavior: /// - /// * If the computed offset is non-zero, then both the starting and resulting pointer must be - /// either in bounds or one byte past the end of the same [allocated object]. + /// * If the computed offset, **in bytes**, is non-zero, then both the starting and resulting + /// pointer must be either in bounds or at the end of the same [allocated object]. /// (If it is zero, then the function is always well-defined.) /// /// * The computed offset, **in bytes**, cannot overflow an `isize`. @@ -1096,8 +1096,8 @@ impl *mut T { /// If any of the following conditions are violated, the result is Undefined /// Behavior: /// - /// * If the computed offset is non-zero, then both the starting and resulting pointer must be - /// either in bounds or one byte past the end of the same [allocated object]. + /// * If the computed offset, **in bytes**, is non-zero, then both the starting and resulting + /// pointer must be either in bounds or at the end of the same [allocated object]. /// (If it is zero, then the function is always well-defined.) /// /// * The computed offset, **in bytes**, cannot overflow an `isize`. @@ -1181,8 +1181,8 @@ impl *mut T { /// If any of the following conditions are violated, the result is Undefined /// Behavior: /// - /// * If the computed offset is non-zero, then both the starting and resulting pointer must be - /// either in bounds or one byte past the end of the same [allocated object]. + /// * If the computed offset, **in bytes**, is non-zero, then both the starting and resulting + /// pointer must be either in bounds or at the end of the same [allocated object]. /// (If it is zero, then the function is always well-defined.) /// /// * The computed offset cannot exceed `isize::MAX` **bytes**.