about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2015-04-19 20:17:47 +0300
committerSimonas Kazlauskas <git@kazlauskas.me>2015-04-28 20:56:52 +0300
commit82b43568a64822c693fdfa50a736056efe92c4ce (patch)
treebb76a4266406421c378e73e2e5b76f9bcd727e8e /src/libcore
parentf191f924214aa1dcd342ada1d99775ccbb01ddd7 (diff)
downloadrust-82b43568a64822c693fdfa50a736056efe92c4ce.tar.gz
rust-82b43568a64822c693fdfa50a736056efe92c4ce.zip
Clarify offset rules a bit
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/intrinsics.rs11
-rw-r--r--src/libcore/ptr.rs7
2 files changed, 12 insertions, 6 deletions
diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs
index 8ed89adec5b..c651eacfe0a 100644
--- a/src/libcore/intrinsics.rs
+++ b/src/libcore/intrinsics.rs
@@ -255,12 +255,17 @@ extern "rust-intrinsic" {
     /// 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
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 0e9570df09d..2ebbab41623 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -301,9 +301,10 @@ impl<T: ?Sized> *const T {
     ///
     /// # 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 {