From 2c13ee8970126261dd30a7b1be865af6d26afaea Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 21 Oct 2023 21:32:06 -0700 Subject: [PATCH 1/3] Clarify UB in `get_unchecked(_mut)` --- library/core/src/slice/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 45080eda2ce2f..5866a88881970 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -640,6 +640,11 @@ impl [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] { /// 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 /// From 01ca7a0cb05e5684049a1ebb6179d63796e24e5c Mon Sep 17 00:00:00 2001 From: scottmcm Date: Wed, 25 Oct 2023 15:31:05 +0000 Subject: [PATCH 2/3] Add the missing word --- library/core/src/slice/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 5866a88881970..fdf265cb3bfb5 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -642,8 +642,8 @@ impl [T] { /// /// 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. + /// pointer. And it's UB to call `.get_unchecked(..len +1)`, + /// `.get_unchecked(..=len)`, or similar. /// /// [`get`]: slice::get /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html @@ -682,8 +682,8 @@ impl [T] { /// /// 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. + /// to a pointer. And it's UB to call `.get_unchecked_mut(..len +1)`, + /// `.get_unchecked_mut(..=len)`, or similar. /// /// [`get_mut`]: slice::get_mut /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html From 545175ce87a9de4ea371f9d88bafd4d35984a533 Mon Sep 17 00:00:00 2001 From: scottmcm Date: Tue, 7 Nov 2023 18:39:09 -0800 Subject: [PATCH 3/3] Fix addition formatting --- library/core/src/slice/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index fdf265cb3bfb5..6cf5d48a1678e 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -642,7 +642,7 @@ impl [T] { /// /// 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)`, + /// pointer. And it's UB to call `.get_unchecked(..len + 1)`, /// `.get_unchecked(..=len)`, or similar. /// /// [`get`]: slice::get @@ -682,7 +682,7 @@ impl [T] { /// /// 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)`, + /// to a pointer. And it's UB to call `.get_unchecked_mut(..len + 1)`, /// `.get_unchecked_mut(..=len)`, or similar. /// /// [`get_mut`]: slice::get_mut