Skip to content

Commit

Permalink
Auto merge of rust-lang#10629 - Alexendoo:as-ptr-cast-mut-docs-ub, r=…
Browse files Browse the repository at this point in the history
…Jarcho

Fix UB in `as_ptr_cast_mut` documentation

changelog: none

Fixes rust-lang#10628

There's no `String::as_mut_ptr` surprisingly, so the example is actually calling `str::as_mut_ptr` on an empty `str`
  • Loading branch information
bors committed Apr 12, 2023
2 parents d2f1b2c + 8f979af commit d9c2957
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/casts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,14 @@ declare_clippy_lint! {
///
/// ### Example
/// ```rust
/// let string = String::with_capacity(1);
/// let ptr = string.as_ptr() as *mut u8;
/// let mut vec = Vec::<u8>::with_capacity(1);
/// let ptr = vec.as_ptr() as *mut u8;
/// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
/// ```
/// Use instead:
/// ```rust
/// let mut string = String::with_capacity(1);
/// let ptr = string.as_mut_ptr();
/// let mut vec = Vec::<u8>::with_capacity(1);
/// let ptr = vec.as_mut_ptr();
/// unsafe { ptr.write(4) };
/// ```
#[clippy::version = "1.66.0"]
Expand Down

0 comments on commit d9c2957

Please sign in to comment.