Skip to content

Commit f62ad99

Browse files
committed
Elaborate on the invariants for references-to-slices
1 parent cabdf3a commit f62ad99

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

library/core/src/primitive_docs.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,9 +1387,19 @@ mod prim_usize {}
13871387
/// returning values from safe functions; such violations may result in undefined behavior. Where
13881388
/// exceptions to this latter requirement exist, they will be called out explicitly in documentation.
13891389
///
1390+
/// For references to [slices](primitive.slice.html) and [`str`s](primitive.str.html),
1391+
/// a consequence of the above is that their lengths must always be short enough that
1392+
/// `size_of_val(t) <= isize::MAX`. Said otherwise, for an element type `E` where
1393+
/// `size_of::<E>() > 0` (a non-ZST), the length of the slice must never exceed
1394+
/// `isize::MAX / size_of::<E>()`. (Raw pointers may have longer lengths, but
1395+
/// references must not. For example, compare the documentation of
1396+
/// [`ptr::slice_from_raw_parts`](ptr/fn.slice_from_raw_parts.html) and
1397+
/// [`slice::from_raw_parts`](slice/fn.from_raw_parts.html).)
1398+
///
13901399
/// It is not decided yet whether unsafe code may violate these invariants temporarily on internal
13911400
/// data. As a consequence, unsafe code which violates these invariants temporarily on internal data
1392-
/// may become unsound in future versions of Rust depending on how this question is decided.
1401+
/// may already be unsound in current versions of Rust, and additional violations may become unsound
1402+
/// in future versions of Rust depending on how this question is decided.
13931403
///
13941404
/// [allocated object]: ptr#allocated-object
13951405
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)