Skip to content

Commit 763209e

Browse files
Rollup merge of rust-lang#140719 - wyfo:patch-1, r=lcnr
fix typo in autorefs lint doc example The documentation is talking about other way using only raw pointers, but the example was use `std::slice::from_raw_parts_mut` which also create a reference. `std::ptr::slice_from_raw_parts_mut` should be used instead, and it also highlights the benefit of raw pointer manipulation compared to dereference, as the function doesn't need to be unsafe anymore. Moreover, [`unsafe_op_in_unsafe_fn`](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html) warning has been enabled since Edition 2024, so I've updated the examples to use unsafe blocks.
2 parents 6e2c39b + 49ac393 commit 763209e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

compiler/rustc_lint/src/autorefs.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ declare_lint! {
1515
///
1616
/// ```rust
1717
/// unsafe fn fun(ptr: *mut [u8]) -> *mut [u8] {
18-
/// &raw mut (*ptr)[..16]
19-
/// // ^^^^^^ this calls `IndexMut::index_mut(&mut ..., ..16)`,
20-
/// // implicitly creating a reference
18+
/// unsafe { &raw mut (*ptr)[..16] }
19+
/// // ^^^^^^ this calls `IndexMut::index_mut(&mut ..., ..16)`,
20+
/// // implicitly creating a reference
2121
/// }
2222
/// ```
2323
///
@@ -34,17 +34,17 @@ declare_lint! {
3434
///
3535
/// ```rust
3636
/// unsafe fn fun(ptr: *mut [u8]) -> *mut [u8] {
37-
/// &raw mut (&mut *ptr)[..16]
37+
/// unsafe { &raw mut (&mut *ptr)[..16] }
3838
/// }
3939
/// ```
4040
///
4141
/// Otherwise try to find an alternative way to achive your goals using only raw pointers:
4242
///
4343
/// ```rust
44-
/// use std::slice;
44+
/// use std::ptr;
4545
///
46-
/// unsafe fn fun(ptr: *mut [u8]) -> *mut [u8] {
47-
/// slice::from_raw_parts_mut(ptr.cast(), 16)
46+
/// fn fun(ptr: *mut [u8]) -> *mut [u8] {
47+
/// ptr::slice_from_raw_parts_mut(ptr.cast(), 16)
4848
/// }
4949
/// ```
5050
pub DANGEROUS_IMPLICIT_AUTOREFS,

0 commit comments

Comments
 (0)