@@ -13,7 +13,7 @@ pointer `ptr` to `align`.
13
13
The intrinsic is reexported as a method on ` *const T ` and ` *mut T ` .
14
14
15
15
Also add an ` unsafe fn align_to<T, U>(&[U]) -> (&[U], &[T], &[U]) ` library function
16
- under ` core::mem ` and ` std::mem ` that simplifies the common use case, returning
16
+ under ` core::slice ` and ` std::slice ` that simplifies the common use case, returning
17
17
the unaligned prefix, the aligned center part and the unaligned trailing elements.
18
18
The function is unsafe because it produces a ` &T ` to the memory location of a ` U ` ,
19
19
which might expose padding bytes or violate invariants of ` T ` or ` U ` .
@@ -82,7 +82,7 @@ Usually one should pass in the result of an `align_of` call.
82
82
Add a new method ` align_offset ` to ` *const T ` and ` *mut T ` , which forwards to the
83
83
` align_offset ` intrinsic.
84
84
85
- Add two new functions ` align_to ` and ` align_to_mut ` to ` core::mem ` and ` std::mem `
85
+ Add two new functions ` align_to ` and ` align_to_mut ` to ` core::slice ` and ` std::slice `
86
86
with the following signature:
87
87
88
88
``` rust
@@ -170,7 +170,7 @@ With the `align_offset` method the code can be changed to
170
170
let ptr = v . as_ptr ();
171
171
let align = unsafe {
172
172
// the offset is safe, because `index` is guaranteed inbounds
173
- ptr . offset (index ). align_offset (usize_bytes );
173
+ ptr . offset (index ). align_offset (usize_bytes )
174
174
};
175
175
```
176
176
@@ -235,7 +235,7 @@ With the `align_to` function this could be written as
235
235
let len = text . len ();
236
236
let ptr = text . as_ptr ();
237
237
238
- let (head , mid , tail ) = std :: mem :: align_to :: <(usize , usize )>(text );
238
+ let (head , mid , tail ) = std :: slice :: align_to :: <(usize , usize ), _ >(text );
239
239
240
240
// search up to an aligned boundary
241
241
if let Some (index ) = head . iter (). position (| elt | * elt == x ) {
@@ -263,10 +263,10 @@ tail.iter().position(|elt| *elt == x).map(|i| head.len() + mid.len() + i)
263
263
264
264
## Documentation
265
265
266
- A lint could be implemented which detects hand-written alignment checks and
266
+ A lint could be added to ` clippy ` which detects hand-written alignment checks and
267
267
suggests to use the ` align_to ` function instead.
268
268
269
- The ` std::mem::align ` function's documentation should point to ` std::mem ::align_to `
269
+ The ` std::mem::align ` function's documentation should point to ` std::slice ::align_to `
270
270
in order to increase the visibility of the function. The documentation of
271
271
` std::mem::align ` should note that it is unidiomatic to manually align pointers,
272
272
since that might not be supported on all platforms and is prone to implementation
0 commit comments