Auto merge of #10629 - Alexendoo:as-ptr-cast-mut-docs-ub, r=Jarcho

Fix UB in `as_ptr_cast_mut` documentation

changelog: none

Fixes #10628

There's no `String::as_mut_ptr` surprisingly, so the example is actually calling `str::as_mut_ptr` on an empty `str`
This commit is contained in:
bors 2023-04-12 16:47:34 +00:00
commit d9c2957221

View File

@ -625,14 +625,14 @@
/// ///
/// ### Example /// ### Example
/// ```rust /// ```rust
/// let string = String::with_capacity(1); /// let mut vec = Vec::<u8>::with_capacity(1);
/// let ptr = string.as_ptr() as *mut u8; /// let ptr = vec.as_ptr() as *mut u8;
/// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR /// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
/// ``` /// ```
/// Use instead: /// Use instead:
/// ```rust /// ```rust
/// let mut string = String::with_capacity(1); /// let mut vec = Vec::<u8>::with_capacity(1);
/// let ptr = string.as_mut_ptr(); /// let ptr = vec.as_mut_ptr();
/// unsafe { ptr.write(4) }; /// unsafe { ptr.write(4) };
/// ``` /// ```
#[clippy::version = "1.66.0"] #[clippy::version = "1.66.0"]