@@ -292,8 +292,10 @@ impl<T> [T] {
292
292
/// Returns a reference to an element or subslice, without doing bounds
293
293
/// checking.
294
294
///
295
- /// This is generally not recommended, use with caution! For a safe
296
- /// alternative see [`get`].
295
+ /// This is generally not recommended, use with caution!
296
+ /// Calling this method with an out-of-bounds index is UB even if the resulting
297
+ /// reference is not used.
298
+ /// For a safe alternative see [`get`].
297
299
///
298
300
/// [`get`]: #method.get
299
301
///
@@ -317,8 +319,10 @@ impl<T> [T] {
317
319
/// Returns a mutable reference to an element or subslice, without doing
318
320
/// bounds checking.
319
321
///
320
- /// This is generally not recommended, use with caution! For a safe
321
- /// alternative see [`get_mut`].
322
+ /// This is generally not recommended, use with caution!
323
+ /// Calling this method with an out-of-bounds index is UB even if the resulting
324
+ /// reference is not used.
325
+ /// For a safe alternative see [`get_mut`].
322
326
///
323
327
/// [`get_mut`]: #method.get_mut
324
328
///
@@ -2629,11 +2633,15 @@ pub trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
2629
2633
2630
2634
/// Returns a shared reference to the output at this location, without
2631
2635
/// performing any bounds checking.
2636
+ /// Calling this method with an out-of-bounds index is UB even if the resulting
2637
+ /// reference is not used.
2632
2638
#[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
2633
2639
unsafe fn get_unchecked ( self , slice : & T ) -> & Self :: Output ;
2634
2640
2635
2641
/// Returns a mutable reference to the output at this location, without
2636
2642
/// performing any bounds checking.
2643
+ /// Calling this method with an out-of-bounds index is UB even if the resulting
2644
+ /// reference is not used.
2637
2645
#[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
2638
2646
unsafe fn get_unchecked_mut ( self , slice : & mut T ) -> & mut Self :: Output ;
2639
2647
0 commit comments