@@ -131,6 +131,7 @@ pub fn size_of_val<T>(_val: &T) -> usize {
131
131
/// ```
132
132
#[ inline]
133
133
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
134
+ #[ deprecated( reason = "use `align_of` instead" , since = "1.1.0" ) ]
134
135
pub fn min_align_of < T > ( ) -> usize {
135
136
unsafe { intrinsics:: min_align_of :: < T > ( ) }
136
137
}
@@ -147,6 +148,7 @@ pub fn min_align_of<T>() -> usize {
147
148
#[ cfg( not( stage0) ) ]
148
149
#[ inline]
149
150
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
151
+ #[ deprecated( reason = "use `align_of_val` instead" , since = "1.1.0" ) ]
150
152
pub fn min_align_of_val < T : ?Sized > ( val : & T ) -> usize {
151
153
unsafe { intrinsics:: min_align_of_val ( val) }
152
154
}
@@ -163,44 +165,54 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
163
165
#[ cfg( stage0) ]
164
166
#[ inline]
165
167
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
168
+ #[ deprecated( reason = "use `align_of_val` instead" , since = "1.1.0" ) ]
166
169
pub fn min_align_of_val < T > ( _val : & T ) -> usize {
167
170
min_align_of :: < T > ( )
168
171
}
169
172
170
- /// Returns the alignment in memory for a type.
173
+ /// Returns the ABI-required minimum alignment of a type
171
174
///
172
- /// This function will return the alignment, in bytes, of a type in memory. If the alignment
173
- /// returned is adhered to, then the type is guaranteed to function properly.
175
+ /// This is the alignment used for struct fields. It may be smaller than the preferred alignment.
174
176
///
175
177
/// # Examples
176
178
///
177
179
/// ```
178
180
/// use std::mem;
179
181
///
180
- /// assert_eq!(4, mem::align_of ::<i32>());
182
+ /// assert_eq!(4, mem::min_align_of ::<i32>());
181
183
/// ```
182
184
#[ inline]
183
185
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
184
186
pub fn align_of < T > ( ) -> usize {
185
- // We use the preferred alignment as the default alignment for a type. This
186
- // appears to be what clang migrated towards as well:
187
- //
188
- // http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110725/044411.html
189
- unsafe { intrinsics:: pref_align_of :: < T > ( ) }
187
+ unsafe { intrinsics:: min_align_of :: < T > ( ) }
190
188
}
191
189
192
- /// Returns the alignment of the type of the value that `_val ` points to.
190
+ /// Returns the ABI-required minimum alignment of the type of the value that `val ` points to
193
191
///
194
- /// This is similar to `align_of`, but function will properly handle types such as trait objects
195
- /// (in the future), returning the alignment for an arbitrary value at runtime.
192
+ /// # Examples
193
+ ///
194
+ /// ```
195
+ /// use std::mem;
196
+ ///
197
+ /// assert_eq!(4, mem::min_align_of_val(&5i32));
198
+ /// ```
199
+ #[ cfg( not( stage0) ) ]
200
+ #[ inline]
201
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
202
+ pub fn align_of_val < T : ?Sized > ( val : & T ) -> usize {
203
+ unsafe { intrinsics:: min_align_of_val ( val) }
204
+ }
205
+
206
+ /// Returns the ABI-required minimum alignment of the type of the value that `_val` points to
196
207
///
197
208
/// # Examples
198
209
///
199
210
/// ```
200
211
/// use std::mem;
201
212
///
202
- /// assert_eq!(4, mem::align_of_val (&5i32));
213
+ /// assert_eq!(4, mem::min_align_of_val (&5i32));
203
214
/// ```
215
+ #[ cfg( stage0) ]
204
216
#[ inline]
205
217
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
206
218
pub fn align_of_val < T > ( _val : & T ) -> usize {
0 commit comments