diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-10-21 21:32:06 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-10-21 21:32:06 -0700 |
| commit | 2c13ee8970126261dd30a7b1be865af6d26afaea (patch) | |
| tree | 50ba521d01d026dd2594c52ed675a5f495d5da1c | |
| parent | 1c05d50c8403c56d9a8b6fb871f15aaa26fb5d07 (diff) | |
| download | rust-2c13ee8970126261dd30a7b1be865af6d26afaea.tar.gz rust-2c13ee8970126261dd30a7b1be865af6d26afaea.zip | |
Clarify UB in `get_unchecked(_mut)`
| -rw-r--r-- | library/core/src/slice/mod.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 45080eda2ce..5866a888819 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -640,6 +640,11 @@ impl<T> [T] { /// Calling this method with an out-of-bounds index is *[undefined behavior]* /// even if the resulting reference is not used. /// + /// You can think of this like `.get(index).unwrap_unchecked()`. It's UB + /// to call `.get_unchecked(len)`, even if you immediately convert to a + /// pointer. And it's UB to call `.get_unchecked(..len +1)` or + /// `.get_unchecked(..=len)` similar. + /// /// [`get`]: slice::get /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html /// @@ -675,6 +680,11 @@ impl<T> [T] { /// Calling this method with an out-of-bounds index is *[undefined behavior]* /// even if the resulting reference is not used. /// + /// You can think of this like `.get_mut(index).unwrap_unchecked()`. It's + /// UB to call `.get_unchecked_mut(len)`, even if you immediately convert + /// to a pointer. And it's UB to call `.get_unchecked_mut(..len +1)` or + /// `.get_unchecked_mut(..=len)` similar. + /// /// [`get_mut`]: slice::get_mut /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html /// |
