]> git.lizzy.rs Git - rust.git/commitdiff
Clarify offset rules a bit
authorSimonas Kazlauskas <git@kazlauskas.me>
Sun, 19 Apr 2015 17:17:47 +0000 (20:17 +0300)
committerSimonas Kazlauskas <git@kazlauskas.me>
Tue, 28 Apr 2015 17:56:52 +0000 (20:56 +0300)
src/libcore/intrinsics.rs
src/libcore/ptr.rs

index 8ed89adec5b69385d208b821dcd39cfb67530497..c651eacfe0a8a9647006ac00a5bd1c6bbdcf122e 100644 (file)
     /// Returns `true` if a type is managed (will be allocated on the local heap)
     pub fn owns_managed<T>() -> bool;
 
-    /// Calculates the offset from a pointer. The offset *must* be in-bounds of
-    /// the object, or one-byte-past-the-end. An arithmetic overflow is also
-    /// undefined behaviour.
+    /// Calculates the offset from a pointer.
     ///
     /// This is implemented as an intrinsic to avoid converting to and from an
     /// integer, since the conversion would throw away aliasing information.
+    ///
+    /// # Safety
+    ///
+    /// 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 of
+    /// bounds or arithmetic overflow occurs then any further use of the
+    /// returned value will result in undefined behavior.
     pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
 
     /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
index 0e9570df09d55cf19ac0495e0d670f93cb5aadea..2ebbab4162337d478fbb9757e1a27ea3b049eba0 100644 (file)
@@ -301,9 +301,10 @@ pub unsafe fn as_ref<'a>(&self) -> Option<&'a T> where T: Sized {
     ///
     /// # Safety
     ///
-    /// The offset must be in-bounds of the object, or one-byte-past-the-end.
-    /// Otherwise `offset` invokes Undefined Behaviour, regardless of whether
-    /// the pointer is used.
+    /// 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 of
+    /// bounds or arithmetic overflow occurs then
+    /// any further use of the returned value will result in undefined behavior.
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
     pub unsafe fn offset(self, count: isize) -> *const T where T: Sized {