Skip to content

Commit 909ad39

Browse files
committed
Rename alignto to align_to
1 parent 820df39 commit 909ad39

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

text/0000-is-aligned-intrinsic.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- Feature Name: alignto_intrinsic
1+
- Feature Name: align_to_intrinsic
22
- Start Date: 2017-06-20
33
- RFC PR: (leave this empty)
44
- Rust Issue: (leave this empty)
@@ -12,7 +12,7 @@ pointer `ptr` to `align`.
1212

1313
The intrinsic is reexported as a method on `*const T` and `*mut T`.
1414

15-
Also add an `unsafe fn alignto<T, U>(&[U]) -> (&[U], &[T], &[U])` library function
15+
Also add an `unsafe fn align_to<T, U>(&[U]) -> (&[U], &[T], &[U])` library function
1616
under `core::mem` and `std::mem` 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`,
@@ -82,20 +82,20 @@ 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 `alignto` and `alignto_mut` to `core::mem` and `std::mem`
85+
Add two new functions `align_to` and `align_to_mut` to `core::mem` and `std::mem`
8686
with the following signature:
8787

8888
```rust
89-
unsafe fn alignto<T, U>(&[U]) -> (&[U], &[T], &[U]) { /**/ }
90-
unsafe fn alignto_mut<T, U>(&mut [U]) -> (&mut [U], &mut [T], &mut [U]) { /**/ }
89+
unsafe fn align_to<T, U>(&[U]) -> (&[U], &[T], &[U]) { /**/ }
90+
unsafe fn align_to_mut<T, U>(&mut [U]) -> (&mut [U], &mut [T], &mut [U]) { /**/ }
9191
```
9292

93-
`alignto` can be implemented as
93+
`align_to` can be implemented as
9494

9595
```rust
96-
unsafe fn alignto<T, U>(slice: &[U]) -> (&[U], &[T], &[U]) {
96+
unsafe fn align_to<T, U>(slice: &[U]) -> (&[U], &[T], &[U]) {
9797
use core::mem::{size_of, align_of};
98-
assert!(size_of::<T>() != 0 && size_of::<U>() != 0, "don't use `alignto` with zsts");
98+
assert!(size_of::<T>() != 0 && size_of::<U>() != 0, "don't use `align_to` with zsts");
9999
if size_of::<T>() % size_of::<U>() == 0 {
100100
let align = align_of::<T>();
101101
let size = size_of::<T>();
@@ -124,7 +124,7 @@ unsafe fn alignto<T, U>(slice: &[U]) -> (&[U], &[T], &[U]) {
124124
}
125125
```
126126

127-
on all current platforms. `alignto_mut` is expanded accordingly.
127+
on all current platforms. `align_to_mut` is expanded accordingly.
128128

129129
Users of the functions must process all the returned slices and
130130
cannot rely on any behaviour except that the `&[T]`'s elements are correctly
@@ -145,8 +145,8 @@ choice:
145145

146146
1. In the case where processing the initial unaligned bits might abort the entire
147147
process, use `align_offset`
148-
2. If it is likely that all bytes are going to get processed, use `alignto`
149-
* `alignto` has a slight overhead for creating the slices in case not all
148+
2. If it is likely that all bytes are going to get processed, use `align_to`
149+
* `align_to` has a slight overhead for creating the slices in case not all
150150
slices are used
151151

152152
### Example 1 (pointers)
@@ -177,7 +177,7 @@ let align = unsafe {
177177
## Example 2 (slices)
178178

179179
The `memchr` impl in the standard library explicitly uses the three phases of
180-
the `alignto` functions:
180+
the `align_to` functions:
181181

182182
```rust
183183
// Split `text` in three parts
@@ -224,7 +224,7 @@ if len >= 2 * usize_bytes {
224224
text[offset..].iter().position(|elt| *elt == x).map(|i| offset + i)
225225
```
226226

227-
With the `alignto` function this could be written as
227+
With the `align_to` function this could be written as
228228

229229

230230
```rust
@@ -235,7 +235,7 @@ With the `alignto` 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::alignto::<(usize, usize)>(text);
238+
let (head, mid, tail) = std::mem::align_to::<(usize, usize)>(text);
239239

240240
// search up to an aligned boundary
241241
if let Some(index) = head.iter().position(|elt| *elt == x) {
@@ -264,9 +264,9 @@ tail.iter().position(|elt| *elt == x).map(|i| head.len() + mid.len() + i)
264264
## Documentation
265265

266266
A lint could be implemented which detects hand-written alignment checks and
267-
suggests to use the `alignto` function instead.
267+
suggests to use the `align_to` function instead.
268268

269-
The `std::mem::align` function's documentation should point to `std::mem::alignto`
269+
The `std::mem::align` function's documentation should point to `std::mem::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
@@ -290,5 +290,5 @@ to errors due to code duplication.
290290
[unresolved]: #unresolved-questions
291291

292292
* produce a lint in case `sizeof<T>() % sizeof<U>() != 0` and in case the expansion
293-
is not part of a monomorphisation, since in that case `alignto` is statically
293+
is not part of a monomorphisation, since in that case `align_to` is statically
294294
known to never be effective

0 commit comments

Comments
 (0)