@@ -292,10 +292,13 @@ 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 *[undefined behavior]*
297
+ /// even if the resulting reference is not used.
298
+ /// For a safe alternative see [`get`].
297
299
///
298
300
/// [`get`]: #method.get
301
+ /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
299
302
///
300
303
/// # Examples
301
304
///
@@ -317,10 +320,13 @@ impl<T> [T] {
317
320
/// Returns a mutable reference to an element or subslice, without doing
318
321
/// bounds checking.
319
322
///
320
- /// This is generally not recommended, use with caution! For a safe
321
- /// alternative see [`get_mut`].
323
+ /// This is generally not recommended, use with caution!
324
+ /// Calling this method with an out-of-bounds index is *[undefined behavior]*
325
+ /// even if the resulting reference is not used.
326
+ /// For a safe alternative see [`get_mut`].
322
327
///
323
328
/// [`get_mut`]: #method.get_mut
329
+ /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
324
330
///
325
331
/// # Examples
326
332
///
@@ -2629,11 +2635,17 @@ pub trait SliceIndex<T: ?Sized>: private_slice_index::Sealed {
2629
2635
2630
2636
/// Returns a shared reference to the output at this location, without
2631
2637
/// performing any bounds checking.
2638
+ /// Calling this method with an out-of-bounds index is *[undefined behavior]*
2639
+ /// even if the resulting reference is not used.
2640
+ /// [undefined behavior]: ../../reference/behavior-considered-undefined.html
2632
2641
#[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
2633
2642
unsafe fn get_unchecked ( self , slice : & T ) -> & Self :: Output ;
2634
2643
2635
2644
/// Returns a mutable reference to the output at this location, without
2636
2645
/// performing any bounds checking.
2646
+ /// Calling this method with an out-of-bounds index is *[undefined behavior]*
2647
+ /// even if the resulting reference is not used.
2648
+ /// [undefined behavior]: ../../reference/behavior-considered-undefined.html
2637
2649
#[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
2638
2650
unsafe fn get_unchecked_mut ( self , slice : & mut T ) -> & mut Self :: Output ;
2639
2651
0 commit comments