Skip to content

Commit e49877c

Browse files
committed
Address comments and move align_to to slice module
1 parent 909ad39 commit e49877c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

text/0000-is-aligned-intrinsic.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pointer `ptr` to `align`.
1313
The intrinsic is reexported as a method on `*const T` and `*mut T`.
1414

1515
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
1717
the unaligned prefix, the aligned center part and the unaligned trailing elements.
1818
The function is unsafe because it produces a `&T` to the memory location of a `U`,
1919
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.
8282
Add a new method `align_offset` to `*const T` and `*mut T`, which forwards to the
8383
`align_offset` intrinsic.
8484

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`
8686
with the following signature:
8787

8888
```rust
@@ -170,7 +170,7 @@ With the `align_offset` method the code can be changed to
170170
let ptr = v.as_ptr();
171171
let align = unsafe {
172172
// 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)
174174
};
175175
```
176176

@@ -235,7 +235,7 @@ With the `align_to` function this could be written as
235235
let len = text.len();
236236
let ptr = text.as_ptr();
237237

238-
let (head, mid, tail) = std::mem::align_to::<(usize, usize)>(text);
238+
let (head, mid, tail) = std::slice::align_to::<(usize, usize), _>(text);
239239

240240
// search up to an aligned boundary
241241
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)
263263

264264
## Documentation
265265

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
267267
suggests to use the `align_to` function instead.
268268

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`
270270
in order to increase the visibility of the function. The documentation of
271271
`std::mem::align` should note that it is unidiomatic to manually align pointers,
272272
since that might not be supported on all platforms and is prone to implementation

0 commit comments

Comments
 (0)