Skip to content

Commit d9c2957

Browse files
committed
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`
2 parents d2f1b2c + 8f979af commit d9c2957

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

clippy_lints/src/casts/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -625,14 +625,14 @@ declare_clippy_lint! {
625625
///
626626
/// ### Example
627627
/// ```rust
628-
/// let string = String::with_capacity(1);
629-
/// let ptr = string.as_ptr() as *mut u8;
628+
/// let mut vec = Vec::<u8>::with_capacity(1);
629+
/// let ptr = vec.as_ptr() as *mut u8;
630630
/// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
631631
/// ```
632632
/// Use instead:
633633
/// ```rust
634-
/// let mut string = String::with_capacity(1);
635-
/// let ptr = string.as_mut_ptr();
634+
/// let mut vec = Vec::<u8>::with_capacity(1);
635+
/// let ptr = vec.as_mut_ptr();
636636
/// unsafe { ptr.write(4) };
637637
/// ```
638638
#[clippy::version = "1.66.0"]

0 commit comments

Comments
 (0)