mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
clarify that unchecked indexing is UB even if the reference is never used
This commit is contained in:
@@ -292,8 +292,10 @@ pub fn get_mut<I>(&mut self, index: I) -> Option<&mut I::Output>
|
||||
/// 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 @@ pub unsafe fn get_unchecked<I>(&self, index: I) -> &I::Output
|
||||
/// 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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user