1
- - Feature Name: alignto_intrinsic
1
+ - Feature Name: align_to_intrinsic
2
2
- Start Date: 2017-06-20
3
3
- RFC PR: (leave this empty)
4
4
- Rust Issue: (leave this empty)
@@ -12,7 +12,7 @@ pointer `ptr` to `align`.
12
12
13
13
The intrinsic is reexported as a method on ` *const T ` and ` *mut T ` .
14
14
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
16
16
under ` core::mem ` and ` std::mem ` 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 ` ,
@@ -82,20 +82,20 @@ 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 ` 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 `
86
86
with the following signature:
87
87
88
88
``` 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 ]) { /**/ }
91
91
```
92
92
93
- ` alignto ` can be implemented as
93
+ ` align_to ` can be implemented as
94
94
95
95
``` rust
96
- unsafe fn alignto <T , U >(slice : & [U ]) -> (& [U ], & [T ], & [U ]) {
96
+ unsafe fn align_to <T , U >(slice : & [U ]) -> (& [U ], & [T ], & [U ]) {
97
97
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" );
99
99
if size_of :: <T >() % size_of :: <U >() == 0 {
100
100
let align = align_of :: <T >();
101
101
let size = size_of :: <T >();
@@ -124,7 +124,7 @@ unsafe fn alignto<T, U>(slice: &[U]) -> (&[U], &[T], &[U]) {
124
124
}
125
125
```
126
126
127
- on all current platforms. ` alignto_mut ` is expanded accordingly.
127
+ on all current platforms. ` align_to_mut ` is expanded accordingly.
128
128
129
129
Users of the functions must process all the returned slices and
130
130
cannot rely on any behaviour except that the ` &[T] ` 's elements are correctly
@@ -145,8 +145,8 @@ choice:
145
145
146
146
1 . In the case where processing the initial unaligned bits might abort the entire
147
147
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
150
150
slices are used
151
151
152
152
### Example 1 (pointers)
@@ -177,7 +177,7 @@ let align = unsafe {
177
177
## Example 2 (slices)
178
178
179
179
The ` memchr ` impl in the standard library explicitly uses the three phases of
180
- the ` alignto ` functions:
180
+ the ` align_to ` functions:
181
181
182
182
``` rust
183
183
// Split `text` in three parts
@@ -224,7 +224,7 @@ if len >= 2 * usize_bytes {
224
224
text [offset .. ]. iter (). position (| elt | * elt == x ). map (| i | offset + i )
225
225
```
226
226
227
- With the ` alignto ` function this could be written as
227
+ With the ` align_to ` function this could be written as
228
228
229
229
230
230
``` rust
@@ -235,7 +235,7 @@ With the `alignto` 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 :: alignto :: <(usize , usize )>(text );
238
+ let (head , mid , tail ) = std :: mem :: 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 ) {
@@ -264,9 +264,9 @@ tail.iter().position(|elt| *elt == x).map(|i| head.len() + mid.len() + i)
264
264
## Documentation
265
265
266
266
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.
268
268
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 `
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
@@ -290,5 +290,5 @@ to errors due to code duplication.
290
290
[ unresolved ] : #unresolved-questions
291
291
292
292
* 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
294
294
known to never be effective
0 commit comments