Fix example

This commit is contained in:
Nilstrieb 2022-10-01 20:31:54 +02:00
parent 169ef781f9
commit 2b944d0c38
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View File

@ -608,13 +608,13 @@ declare_clippy_lint! {
/// ### Example
/// ```rust
/// let string = String::with_capacity(1);
/// let ptr = string.as_ptr() as *mut _;
/// let ptr = string.as_ptr() as *mut u8;
/// unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
/// ```
/// Use instead:
/// ```rust
/// let mut string = String::with_capacity(1);
/// let string = string.as_mut_ptr();
/// let ptr = string.as_mut_ptr();
/// unsafe { ptr.write(4) };
/// ```
#[clippy::version = "1.66.0"]

View File

@ -8,12 +8,12 @@ mutability is used, making it unlikely that having it as a mutable pointer is co
### Example
```
let string = String::with_capacity(1);
let ptr = string.as_ptr() as *mut _;
let ptr = string.as_ptr() as *mut u8;
unsafe { ptr.write(4) }; // UNDEFINED BEHAVIOUR
```
Use instead:
```
let mut string = String::with_capacity(1);
let string = string.as_mut_ptr();
let ptr = string.as_mut_ptr();
unsafe { ptr.write(4) };
```