intrinsics: rename min_align_of to align_of
This commit is contained in:
@@ -644,9 +644,9 @@ pub mod intrinsics {
|
||||
#[rustc_intrinsic]
|
||||
pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
|
||||
#[rustc_intrinsic]
|
||||
pub fn min_align_of<T>() -> usize;
|
||||
pub fn align_of<T>() -> usize;
|
||||
#[rustc_intrinsic]
|
||||
pub unsafe fn min_align_of_val<T: ?::Sized>(val: *const T) -> usize;
|
||||
pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize;
|
||||
#[rustc_intrinsic]
|
||||
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
||||
#[rustc_intrinsic]
|
||||
|
||||
@@ -204,11 +204,8 @@ fn main() {
|
||||
assert_eq!(intrinsics::size_of_val(a) as u8, 16);
|
||||
assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4);
|
||||
|
||||
assert_eq!(intrinsics::min_align_of::<u16>() as u8, 2);
|
||||
assert_eq!(
|
||||
intrinsics::min_align_of_val(&a) as u8,
|
||||
intrinsics::min_align_of::<&str>() as u8
|
||||
);
|
||||
assert_eq!(intrinsics::align_of::<u16>() as u8, 2);
|
||||
assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8);
|
||||
|
||||
assert!(!intrinsics::needs_drop::<u8>());
|
||||
assert!(!intrinsics::needs_drop::<[u8]>());
|
||||
|
||||
@@ -586,7 +586,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
let (size, _align) = crate::unsize::size_and_align_of(fx, layout, meta);
|
||||
ret.write_cvalue(fx, CValue::by_val(size, usize_layout));
|
||||
}
|
||||
sym::min_align_of_val => {
|
||||
sym::align_of_val => {
|
||||
intrinsic_args!(fx, args => (ptr); intrinsic);
|
||||
|
||||
let layout = fx.layout_of(generic_args.type_at(0));
|
||||
@@ -613,7 +613,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||
intrinsic_args!(fx, args => (vtable); intrinsic);
|
||||
let vtable = vtable.load_scalar(fx);
|
||||
|
||||
let align = crate::vtable::min_align_of_obj(fx, vtable);
|
||||
let align = crate::vtable::align_of_obj(fx, vtable);
|
||||
ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
|
||||
}
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ pub(crate) fn size_and_align_of<'tcx>(
|
||||
// load size/align from vtable
|
||||
(
|
||||
crate::vtable::size_of_obj(fx, info.unwrap()),
|
||||
crate::vtable::min_align_of_obj(fx, info.unwrap()),
|
||||
crate::vtable::align_of_obj(fx, info.unwrap()),
|
||||
)
|
||||
}
|
||||
ty::Slice(_) | ty::Str => {
|
||||
|
||||
@@ -31,7 +31,7 @@ pub(crate) fn size_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -> Val
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn min_align_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -> Value {
|
||||
pub(crate) fn align_of_obj(fx: &mut FunctionCx<'_, '_, '_>, vtable: Value) -> Value {
|
||||
let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize;
|
||||
fx.bcx.ins().load(
|
||||
fx.pointer_type,
|
||||
|
||||
@@ -655,9 +655,9 @@ pub mod intrinsics {
|
||||
#[rustc_intrinsic]
|
||||
pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
|
||||
#[rustc_intrinsic]
|
||||
pub fn min_align_of<T>() -> usize;
|
||||
pub fn align_of<T>() -> usize;
|
||||
#[rustc_intrinsic]
|
||||
pub unsafe fn min_align_of_val<T: ?::Sized>(val: *const T) -> usize;
|
||||
pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize;
|
||||
#[rustc_intrinsic]
|
||||
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
|
||||
#[rustc_intrinsic]
|
||||
|
||||
@@ -153,7 +153,7 @@ fn main() {
|
||||
let slice = &[0, 1] as &[i32];
|
||||
let slice_ptr = slice as *const [i32] as *const i32;
|
||||
|
||||
let align = intrinsics::min_align_of::<*const i32>();
|
||||
let align = intrinsics::align_of::<*const i32>();
|
||||
assert_eq!(slice_ptr as usize % align, 0);
|
||||
|
||||
//return;
|
||||
@@ -194,8 +194,8 @@ fn main() {
|
||||
assert_eq!(intrinsics::size_of_val(a) as u8, 8);
|
||||
assert_eq!(intrinsics::size_of_val(&0u32) as u8, 4);
|
||||
|
||||
assert_eq!(intrinsics::min_align_of::<u16>() as u8, 2);
|
||||
assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8);
|
||||
assert_eq!(intrinsics::align_of::<u16>() as u8, 2);
|
||||
assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8);
|
||||
|
||||
assert!(!intrinsics::needs_drop::<u8>());
|
||||
assert!(!intrinsics::needs_drop::<[u8]>());
|
||||
|
||||
@@ -118,7 +118,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
let (llsize, _) = size_of_val::size_and_align_of_dst(bx, tp_ty, meta);
|
||||
llsize
|
||||
}
|
||||
sym::min_align_of_val => {
|
||||
sym::align_of_val => {
|
||||
let tp_ty = fn_args.type_at(0);
|
||||
let (_, meta) = args[0].val.pointer_parts();
|
||||
let (_, llalign) = size_of_val::size_and_align_of_dst(bx, tp_ty, meta);
|
||||
|
||||
@@ -120,7 +120,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||
self.copy_op(&val, dest)?;
|
||||
}
|
||||
|
||||
sym::min_align_of_val | sym::size_of_val => {
|
||||
sym::align_of_val | sym::size_of_val => {
|
||||
// Avoid `deref_pointer` -- this is not a deref, the ptr does not have to be
|
||||
// dereferenceable!
|
||||
let place = self.ref_to_mplace(&self.read_immediate(&args[0])?)?;
|
||||
@@ -129,7 +129,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
||||
.ok_or_else(|| err_unsup_format!("`extern type` does not have known layout"))?;
|
||||
|
||||
let result = match intrinsic_name {
|
||||
sym::min_align_of_val => align.bytes(),
|
||||
sym::align_of_val => align.bytes(),
|
||||
sym::size_of_val => size.bytes(),
|
||||
_ => bug!(),
|
||||
};
|
||||
|
||||
@@ -71,7 +71,7 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
|
||||
| sym::box_new
|
||||
| sym::breakpoint
|
||||
| sym::size_of
|
||||
| sym::min_align_of
|
||||
| sym::align_of
|
||||
| sym::needs_drop
|
||||
| sym::caller_location
|
||||
| sym::add_with_overflow
|
||||
@@ -200,10 +200,8 @@ pub(crate) fn check_intrinsic_type(
|
||||
sym::abort => (0, 0, vec![], tcx.types.never),
|
||||
sym::unreachable => (0, 0, vec![], tcx.types.never),
|
||||
sym::breakpoint => (0, 0, vec![], tcx.types.unit),
|
||||
sym::size_of | sym::pref_align_of | sym::min_align_of | sym::variant_count => {
|
||||
(1, 0, vec![], tcx.types.usize)
|
||||
}
|
||||
sym::size_of_val | sym::min_align_of_val => {
|
||||
sym::size_of | sym::align_of | sym::variant_count => (1, 0, vec![], tcx.types.usize),
|
||||
sym::size_of_val | sym::align_of_val => {
|
||||
(1, 0, vec![Ty::new_imm_ptr(tcx, param(0))], tcx.types.usize)
|
||||
}
|
||||
sym::rustc_peek => (1, 0, vec![param(0)], param(0)),
|
||||
|
||||
@@ -150,12 +150,12 @@ impl<'tcx> crate::MirPass<'tcx> for LowerIntrinsics {
|
||||
});
|
||||
terminator.kind = TerminatorKind::Goto { target };
|
||||
}
|
||||
sym::size_of | sym::min_align_of => {
|
||||
sym::size_of | sym::align_of => {
|
||||
let target = target.unwrap();
|
||||
let tp_ty = generic_args.type_at(0);
|
||||
let null_op = match intrinsic.name {
|
||||
sym::size_of => NullOp::SizeOf,
|
||||
sym::min_align_of => NullOp::AlignOf,
|
||||
sym::align_of => NullOp::AlignOf,
|
||||
_ => bug!("unexpected intrinsic"),
|
||||
};
|
||||
block.statements.push(Statement {
|
||||
|
||||
@@ -429,6 +429,8 @@ symbols! {
|
||||
aggregate_raw_ptr,
|
||||
alias,
|
||||
align,
|
||||
align_of,
|
||||
align_of_val,
|
||||
alignment,
|
||||
all,
|
||||
alloc,
|
||||
@@ -1353,8 +1355,6 @@ symbols! {
|
||||
message,
|
||||
meta,
|
||||
metadata_type,
|
||||
min_align_of,
|
||||
min_align_of_val,
|
||||
min_const_fn,
|
||||
min_const_generics,
|
||||
min_const_unsafe_fn,
|
||||
@@ -2675,7 +2675,7 @@ impl Interner {
|
||||
assert_eq!(
|
||||
strings.len(),
|
||||
init.len() + extra.len(),
|
||||
"`init` or `extra` contain duplicate symbols",
|
||||
"there are duplicate symbols in the rustc symbol list and the extra symbols added by the driver",
|
||||
);
|
||||
Interner(Lock::new(InternerInner { arena: Default::default(), strings }))
|
||||
}
|
||||
|
||||
@@ -926,8 +926,7 @@ pub const unsafe fn slice_get_unchecked<
|
||||
pub fn ptr_mask<T>(ptr: *const T, mask: usize) -> *const T;
|
||||
|
||||
/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
|
||||
/// a size of `count` * `size_of::<T>()` and an alignment of
|
||||
/// `min_align_of::<T>()`
|
||||
/// a size of `count` * `size_of::<T>()` and an alignment of `align_of::<T>()`.
|
||||
///
|
||||
/// This intrinsic does not have a stable counterpart.
|
||||
/// # Safety
|
||||
@@ -941,8 +940,7 @@ pub fn ptr_mask<T>(ptr: *const T, mask: usize) -> *const T;
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
|
||||
/// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
|
||||
/// a size of `count * size_of::<T>()` and an alignment of
|
||||
/// `min_align_of::<T>()`
|
||||
/// a size of `count * size_of::<T>()` and an alignment of `align_of::<T>()`.
|
||||
///
|
||||
/// The volatile parameter is set to `true`, so it will not be optimized out
|
||||
/// unless size is equal to zero.
|
||||
@@ -952,8 +950,7 @@ pub unsafe fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T,
|
||||
#[rustc_nounwind]
|
||||
pub unsafe fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
|
||||
/// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
|
||||
/// size of `count * size_of::<T>()` and an alignment of
|
||||
/// `min_align_of::<T>()`.
|
||||
/// size of `count * size_of::<T>()` and an alignment of `align_of::<T>()`.
|
||||
///
|
||||
/// This intrinsic does not have a stable counterpart.
|
||||
/// # Safety
|
||||
@@ -2649,7 +2646,7 @@ pub const fn size_of<T>() -> usize;
|
||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||
#[rustc_intrinsic_const_stable_indirect]
|
||||
#[rustc_intrinsic]
|
||||
pub const fn min_align_of<T>() -> usize;
|
||||
pub const fn align_of<T>() -> usize;
|
||||
|
||||
/// Returns the number of variants of the type `T` cast to a `usize`;
|
||||
/// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
|
||||
@@ -2689,7 +2686,7 @@ pub const unsafe fn size_of_val<T: ?Sized>(ptr: *const T) -> usize;
|
||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_intrinsic_const_stable_indirect]
|
||||
pub const unsafe fn min_align_of_val<T: ?Sized>(ptr: *const T) -> usize;
|
||||
pub const unsafe fn align_of_val<T: ?Sized>(ptr: *const T) -> usize;
|
||||
|
||||
/// Gets a static string slice containing the name of a type.
|
||||
///
|
||||
|
||||
@@ -412,7 +412,7 @@ pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[deprecated(note = "use `align_of` instead", since = "1.2.0", suggestion = "align_of")]
|
||||
pub fn min_align_of<T>() -> usize {
|
||||
intrinsics::min_align_of::<T>()
|
||||
intrinsics::align_of::<T>()
|
||||
}
|
||||
|
||||
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
|
||||
@@ -436,7 +436,7 @@ pub fn min_align_of<T>() -> usize {
|
||||
#[deprecated(note = "use `align_of_val` instead", since = "1.2.0", suggestion = "align_of_val")]
|
||||
pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
// SAFETY: val is a reference, so it's a valid raw pointer
|
||||
unsafe { intrinsics::min_align_of_val(val) }
|
||||
unsafe { intrinsics::align_of_val(val) }
|
||||
}
|
||||
|
||||
/// Returns the [ABI]-required minimum alignment of a type in bytes.
|
||||
@@ -458,7 +458,7 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
#[rustc_promotable]
|
||||
#[rustc_const_stable(feature = "const_align_of", since = "1.24.0")]
|
||||
pub const fn align_of<T>() -> usize {
|
||||
intrinsics::min_align_of::<T>()
|
||||
intrinsics::align_of::<T>()
|
||||
}
|
||||
|
||||
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
|
||||
@@ -477,10 +477,9 @@ pub const fn align_of<T>() -> usize {
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_align_of_val", since = "1.85.0")]
|
||||
#[allow(deprecated)]
|
||||
pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
// SAFETY: val is a reference, so it's a valid raw pointer
|
||||
unsafe { intrinsics::min_align_of_val(val) }
|
||||
unsafe { intrinsics::align_of_val(val) }
|
||||
}
|
||||
|
||||
/// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to in
|
||||
@@ -527,7 +526,7 @@ pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||
pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||
// SAFETY: the caller must provide a valid raw pointer
|
||||
unsafe { intrinsics::min_align_of_val(val) }
|
||||
unsafe { intrinsics::align_of_val(val) }
|
||||
}
|
||||
|
||||
/// Returns `true` if dropping values of type `T` matters.
|
||||
@@ -637,8 +636,6 @@ pub const fn needs_drop<T: ?Sized>() -> bool {
|
||||
#[inline(always)]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated_in_future)]
|
||||
#[allow(deprecated)]
|
||||
#[rustc_diagnostic_item = "mem_zeroed"]
|
||||
#[track_caller]
|
||||
#[rustc_const_stable(feature = "const_mem_zeroed", since = "1.75.0")]
|
||||
@@ -677,8 +674,6 @@ pub const unsafe fn zeroed<T>() -> T {
|
||||
#[must_use]
|
||||
#[deprecated(since = "1.39.0", note = "use `mem::MaybeUninit` instead")]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(deprecated_in_future)]
|
||||
#[allow(deprecated)]
|
||||
#[rustc_diagnostic_item = "mem_uninitialized"]
|
||||
#[track_caller]
|
||||
pub unsafe fn uninitialized<T>() -> T {
|
||||
|
||||
@@ -76,7 +76,6 @@ generate! {
|
||||
Visitor,
|
||||
Weak,
|
||||
abs,
|
||||
align_of,
|
||||
ambiguous_glob_reexports,
|
||||
append,
|
||||
arg,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
let mut _0: usize;
|
||||
|
||||
bb0: {
|
||||
- _0 = std::intrinsics::min_align_of::<T>() -> [return: bb1, unwind unreachable];
|
||||
- _0 = std::intrinsics::align_of::<T>() -> [return: bb1, unwind unreachable];
|
||||
+ _0 = AlignOf(T);
|
||||
+ goto -> bb1;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
let mut _0: usize;
|
||||
|
||||
bb0: {
|
||||
- _0 = std::intrinsics::min_align_of::<T>() -> [return: bb1, unwind unreachable];
|
||||
- _0 = std::intrinsics::align_of::<T>() -> [return: bb1, unwind unreachable];
|
||||
+ _0 = AlignOf(T);
|
||||
+ goto -> bb1;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ pub fn size_of<T>() -> usize {
|
||||
pub fn align_of<T>() -> usize {
|
||||
// CHECK-LABEL: fn align_of(
|
||||
// CHECK: {{_.*}} = AlignOf(T);
|
||||
core::intrinsics::min_align_of::<T>()
|
||||
core::intrinsics::align_of::<T>()
|
||||
}
|
||||
|
||||
// EMIT_MIR lower_intrinsics.forget.LowerIntrinsics.diff
|
||||
|
||||
@@ -39,7 +39,7 @@ fn vec_deref_to_slice(_1: &Vec<u8>) -> &[u8] {
|
||||
}
|
||||
scope 15 (inlined std::mem::size_of::<u8>) {
|
||||
}
|
||||
scope 16 (inlined align_of::<u8>) {
|
||||
scope 16 (inlined std::mem::align_of::<u8>) {
|
||||
}
|
||||
scope 17 (inlined slice_from_raw_parts::<u8>) {
|
||||
debug data => _3;
|
||||
|
||||
@@ -39,7 +39,7 @@ fn vec_deref_to_slice(_1: &Vec<u8>) -> &[u8] {
|
||||
}
|
||||
scope 15 (inlined std::mem::size_of::<u8>) {
|
||||
}
|
||||
scope 16 (inlined align_of::<u8>) {
|
||||
scope 16 (inlined std::mem::align_of::<u8>) {
|
||||
}
|
||||
scope 17 (inlined slice_from_raw_parts::<u8>) {
|
||||
debug data => _3;
|
||||
|
||||
@@ -8,4 +8,4 @@ pub const unsafe fn size_of_val<T>(x: *const T) -> usize;
|
||||
#[unstable(feature = "unstable", issue = "42")]
|
||||
#[rustc_const_unstable(feature = "unstable", issue = "42")]
|
||||
#[rustc_intrinsic]
|
||||
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize;
|
||||
pub const unsafe fn align_of_val<T>(x: *const T) -> usize;
|
||||
|
||||
@@ -18,5 +18,5 @@ static FOO: Foo = Foo::C;
|
||||
fn main() {
|
||||
assert_eq!(FOO, Foo::C);
|
||||
assert_eq!(mem::size_of::<Foo>(), 12);
|
||||
assert_eq!(mem::min_align_of::<Foo>(), 4);
|
||||
assert_eq!(mem::align_of::<Foo>(), 4);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#![feature(extern_types)]
|
||||
#![feature(core_intrinsics)]
|
||||
|
||||
use std::intrinsics::{min_align_of_val, size_of_val};
|
||||
use std::intrinsics::{align_of_val, size_of_val};
|
||||
|
||||
extern "C" {
|
||||
type Opaque;
|
||||
}
|
||||
|
||||
const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR layout
|
||||
const _ALIGN: usize = unsafe { min_align_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR layout
|
||||
const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) }; //~ ERROR layout
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -7,8 +7,8 @@ LL | const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque
|
||||
error[E0080]: `extern type` does not have known layout
|
||||
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:11:32
|
||||
|
|
||||
LL | const _ALIGN: usize = unsafe { min_align_of_val(&4 as *const i32 as *const Opaque) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_ALIGN` failed here
|
||||
LL | const _ALIGN: usize = unsafe { align_of_val(&4 as *const i32 as *const Opaque) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_ALIGN` failed here
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ const fn const_main() {
|
||||
unstable_intrinsic::size_of_val(&x);
|
||||
//~^ERROR: unstable library feature `unstable`
|
||||
//~|ERROR: not yet stable as a const intrinsic
|
||||
unstable_intrinsic::min_align_of_val(&x);
|
||||
unstable_intrinsic::align_of_val(&x);
|
||||
//~^ERROR: unstable library feature `unstable`
|
||||
//~|ERROR: not yet stable as a const intrinsic
|
||||
|
||||
size_of_val(&x);
|
||||
//~^ERROR: cannot use `#[feature(local)]`
|
||||
min_align_of_val(&x);
|
||||
align_of_val(&x);
|
||||
//~^ERROR: cannot use `#[feature(local)]`
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,7 @@ pub const unsafe fn size_of_val<T>(x: *const T) -> usize;
|
||||
#[unstable(feature = "local", issue = "42")]
|
||||
#[rustc_const_unstable(feature = "local", issue = "42")]
|
||||
#[rustc_intrinsic]
|
||||
pub const unsafe fn min_align_of_val<T>(x: *const T) -> usize;
|
||||
pub const unsafe fn align_of_val<T>(x: *const T) -> usize;
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_stable(feature = "const_intrinsic_copy", since = "1.63.0")]
|
||||
|
||||
@@ -11,8 +11,8 @@ LL | unstable_intrinsic::size_of_val(&x);
|
||||
error[E0658]: use of unstable library feature `unstable`
|
||||
--> $DIR/const-unstable-intrinsic.rs:20:9
|
||||
|
|
||||
LL | unstable_intrinsic::min_align_of_val(&x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | unstable_intrinsic::align_of_val(&x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
|
||||
= help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
@@ -29,11 +29,11 @@ help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
LL + #![feature(unstable)]
|
||||
|
|
||||
|
||||
error: `min_align_of_val` is not yet stable as a const intrinsic
|
||||
error: `align_of_val` is not yet stable as a const intrinsic
|
||||
--> $DIR/const-unstable-intrinsic.rs:20:9
|
||||
|
|
||||
LL | unstable_intrinsic::min_align_of_val(&x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | unstable_intrinsic::align_of_val(&x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: add `#![feature(unstable)]` to the crate attributes to enable
|
||||
|
|
||||
@@ -55,8 +55,8 @@ LL | const fn const_main() {
|
||||
error: const function that might be (indirectly) exposed to stable cannot use `#[feature(local)]`
|
||||
--> $DIR/const-unstable-intrinsic.rs:26:9
|
||||
|
|
||||
LL | min_align_of_val(&x);
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
LL | align_of_val(&x);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: if the function is not (yet) meant to be exposed to stable const contexts, add `#[rustc_const_unstable]`
|
||||
|
|
||||
|
||||
@@ -23,12 +23,12 @@ use std::intrinsics as rusti;
|
||||
mod m {
|
||||
#[cfg(target_arch = "x86")]
|
||||
pub fn main() {
|
||||
assert_eq!(crate::rusti::min_align_of::<u64>(), 4);
|
||||
assert_eq!(crate::rusti::align_of::<u64>(), 4);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "x86"))]
|
||||
pub fn main() {
|
||||
assert_eq!(crate::rusti::min_align_of::<u64>(), 8);
|
||||
assert_eq!(crate::rusti::align_of::<u64>(), 8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,21 +36,21 @@ mod m {
|
||||
mod m {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub fn main() {
|
||||
assert_eq!(crate::rusti::min_align_of::<u64>(), 8);
|
||||
assert_eq!(crate::rusti::align_of::<u64>(), 8);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
mod m {
|
||||
pub fn main() {
|
||||
assert_eq!(crate::rusti::min_align_of::<u64>(), 8);
|
||||
assert_eq!(crate::rusti::align_of::<u64>(), 8);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_family = "wasm")]
|
||||
mod m {
|
||||
pub fn main() {
|
||||
assert_eq!(crate::rusti::min_align_of::<u64>(), 8);
|
||||
assert_eq!(crate::rusti::align_of::<u64>(), 8);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ error[E0080]: the type `MySlice<[bool]>` has an unknown layout
|
||||
LL | static CHECK: () = assert!(align_of::<P2>() == 1);
|
||||
| ^^^^^^^^^^^^^^^^ evaluation of `CHECK` failed inside this call
|
||||
|
|
||||
note: inside `align_of::<P2>`
|
||||
note: inside `std::mem::align_of::<P2>`
|
||||
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
use std::mem;
|
||||
|
||||
/// `T` should satisfy `size_of T (mod min_align_of T) === 0` to be stored at `Vec<T>` properly
|
||||
/// `T` should satisfy `size_of T (mod align_of T) === 0` to be stored at `Vec<T>` properly
|
||||
/// Please consult the issue #20460
|
||||
fn check<T>() {
|
||||
assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0);
|
||||
assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0);
|
||||
assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0);
|
||||
assert_eq!(mem::size_of::<T>() % mem::align_of::<T>(), 0);
|
||||
assert_eq!(mem::size_of::<T>() % mem::align_of::<T>(), 0);
|
||||
assert_eq!(mem::size_of::<T>() % mem::align_of::<T>(), 0);
|
||||
}
|
||||
|
||||
#[repr(simd)]
|
||||
|
||||
@@ -11,7 +11,7 @@ fn addr_of<T>(ptr: &T) -> usize {
|
||||
fn is_aligned<T>(ptr: &T) -> bool {
|
||||
unsafe {
|
||||
let addr: usize = mem::transmute(ptr);
|
||||
(addr % mem::min_align_of::<T>()) == 0
|
||||
(addr % mem::align_of::<T>()) == 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@ pub fn main() {
|
||||
// Send it through the shape code
|
||||
let y = format!("{:?}", x);
|
||||
|
||||
println!("align inner = {:?}", intrinsics::min_align_of::<Inner>());
|
||||
println!("align inner = {:?}", intrinsics::align_of::<Inner>());
|
||||
println!("size outer = {:?}", mem::size_of::<Outer>());
|
||||
println!("y = {:?}", y);
|
||||
|
||||
// per clang/gcc the alignment of `inner` is 4 on x86.
|
||||
assert_eq!(intrinsics::min_align_of::<Inner>(), m::align());
|
||||
assert_eq!(intrinsics::align_of::<Inner>(), m::align());
|
||||
|
||||
// per clang/gcc the size of `outer` should be 12
|
||||
// because `inner`s alignment was 4.
|
||||
|
||||
@@ -84,12 +84,12 @@ pub fn main() {
|
||||
|
||||
let y = format!("{:?}", x);
|
||||
|
||||
println!("align inner = {:?}", intrinsics::min_align_of::<Inner>());
|
||||
println!("align inner = {:?}", intrinsics::align_of::<Inner>());
|
||||
println!("size outer = {:?}", mem::size_of::<Outer>());
|
||||
println!("y = {:?}", y);
|
||||
|
||||
// per clang/gcc the alignment of `Inner` is 4 on x86.
|
||||
assert_eq!(intrinsics::min_align_of::<Inner>(), m::m::align());
|
||||
assert_eq!(intrinsics::align_of::<Inner>(), m::m::align());
|
||||
|
||||
// per clang/gcc the size of `Outer` should be 12
|
||||
// because `Inner`s alignment was 4.
|
||||
|
||||
@@ -19,7 +19,7 @@ fn mk_rec() -> Rec {
|
||||
|
||||
fn is_u64_aligned(u: &Tag<u64>) -> bool {
|
||||
let p: usize = unsafe { mem::transmute(u) };
|
||||
let u64_align = std::mem::min_align_of::<u64>();
|
||||
let u64_align = std::mem::align_of::<u64>();
|
||||
return (p & (u64_align - 1)) == 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ fn variant_data_is_aligned<A,B>(amnt: usize, u: &Tag<A,B>) -> bool {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let u64_align = std::mem::min_align_of::<u64>();
|
||||
let u64_align = std::mem::align_of::<u64>();
|
||||
let x = mk_rec(22u64, 23u64);
|
||||
assert!(is_aligned(u64_align, &x.tA));
|
||||
assert!(variant_data_is_aligned(u64_align, &x.tA));
|
||||
|
||||
@@ -19,7 +19,7 @@ fn mk_rec() -> Rec {
|
||||
|
||||
fn is_u64_aligned(u: &Tag) -> bool {
|
||||
let p: usize = unsafe { mem::transmute(u) };
|
||||
let u64_align = std::mem::min_align_of::<u64>();
|
||||
let u64_align = std::mem::align_of::<u64>();
|
||||
return (p & (u64_align - 1)) == 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user