diff options
| author | Ralf Jung <post@ralfj.de> | 2019-08-03 12:46:20 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2019-08-03 12:46:20 +0200 |
| commit | f44abba4ec19ee8b7ae4dfbe557fa4846eec8ad6 (patch) | |
| tree | eaae2c735c237c2237b20d66f4ffd0fd9e24356f /src/libcore/slice | |
| parent | d7270712cb446aad0817040bbca73a8d024f67b0 (diff) | |
| download | rust-f44abba4ec19ee8b7ae4dfbe557fa4846eec8ad6.tar.gz rust-f44abba4ec19ee8b7ae4dfbe557fa4846eec8ad6.zip | |
clarify that unchecked indexing is UB even if the reference is never used
Diffstat (limited to 'src/libcore/slice')
| -rw-r--r-- | src/libcore/slice/mod.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index b06511cad97..bb6abd8e003 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -292,8 +292,10 @@ impl<T> [T] { /// Returns a reference to an element or subslice, without doing bounds /// checking. /// - /// This is generally not recommended, use with caution! For a safe - /// alternative see [`get`]. + /// This is generally not recommended, use with caution! + /// Calling this method with an out-of-bounds index is UB even if the resulting + /// reference is not used. + /// For a safe alternative see [`get`]. /// /// [`get`]: #method.get /// @@ -317,8 +319,10 @@ impl<T> [T] { /// Returns a mutable reference to an element or subslice, without doing /// bounds checking. /// - /// This is generally not recommended, use with caution! For a safe - /// alternative see [`get_mut`]. + /// This is generally not recommended, use with caution! + /// Calling this method with an out-of-bounds index is UB even if the resulting + /// reference is not used. + /// For a safe alternative see [`get_mut`]. /// /// [`get_mut`]: #method.get_mut /// @@ -2629,11 +2633,15 @@ pub trait SliceIndex<T: ?Sized>: private_slice_index::Sealed { /// Returns a shared reference to the output at this location, without /// performing any bounds checking. + /// Calling this method with an out-of-bounds index is UB even if the resulting + /// reference is not used. #[unstable(feature = "slice_index_methods", issue = "0")] unsafe fn get_unchecked(self, slice: &T) -> &Self::Output; /// Returns a mutable reference to the output at this location, without /// performing any bounds checking. + /// Calling this method with an out-of-bounds index is UB even if the resulting + /// reference is not used. #[unstable(feature = "slice_index_methods", issue = "0")] unsafe fn get_unchecked_mut(self, slice: &mut T) -> &mut Self::Output; |
