mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-15 13:36:49 +00:00
Rollup merge of #133762 - RalfJung:const-size-of-val, r=workingjubilee
stabilize const_{size,align}_of_val FCP passed [here](https://github.com/rust-lang/rust/issues/46571#issuecomment-2460285288). Fixes https://github.com/rust-lang/rust/issues/46571.
This commit is contained in:
commit
f224ad85ff
@ -179,6 +179,7 @@ impl Layout {
|
||||
/// or other unsized type like a slice).
|
||||
#[stable(feature = "alloc_layout", since = "1.28.0")]
|
||||
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
|
||||
#[rustc_const_stable_indirect]
|
||||
#[must_use]
|
||||
#[inline]
|
||||
pub const fn for_value<T: ?Sized>(t: &T) -> Self {
|
||||
@ -215,7 +216,6 @@ impl Layout {
|
||||
/// [trait object]: ../../book/ch17-02-trait-objects.html
|
||||
/// [extern type]: ../../unstable-book/language-features/extern-types.html
|
||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||
#[rustc_const_unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||
#[must_use]
|
||||
pub const unsafe fn for_value_raw<T: ?Sized>(t: *const T) -> Self {
|
||||
// SAFETY: we pass along the prerequisites of these functions to the caller
|
||||
|
@ -4099,6 +4099,7 @@ pub const fn variant_count<T>() -> usize {
|
||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_intrinsic_must_be_overridden]
|
||||
#[rustc_intrinsic_const_stable_indirect]
|
||||
pub const unsafe fn size_of_val<T: ?Sized>(_ptr: *const T) -> usize {
|
||||
unreachable!()
|
||||
}
|
||||
@ -4114,6 +4115,7 @@ pub const unsafe fn size_of_val<T: ?Sized>(_ptr: *const T) -> usize {
|
||||
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||
#[rustc_intrinsic]
|
||||
#[rustc_intrinsic_must_be_overridden]
|
||||
#[rustc_intrinsic_const_stable_indirect]
|
||||
pub const unsafe fn min_align_of_val<T: ?Sized>(_ptr: *const T) -> usize {
|
||||
unreachable!()
|
||||
}
|
||||
|
@ -333,7 +333,7 @@ pub const fn size_of<T>() -> usize {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
|
||||
#[rustc_const_stable(feature = "const_size_of_val", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of_val")]
|
||||
pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
// SAFETY: `val` is a reference, so it's a valid raw pointer
|
||||
@ -390,7 +390,6 @@ pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||
#[rustc_const_unstable(feature = "const_size_of_val_raw", issue = "46571")]
|
||||
pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
||||
// SAFETY: the caller must provide a valid raw pointer
|
||||
unsafe { intrinsics::size_of_val(val) }
|
||||
@ -485,7 +484,7 @@ pub const fn align_of<T>() -> usize {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
|
||||
#[rustc_const_stable(feature = "const_align_of_val", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[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
|
||||
@ -534,7 +533,6 @@ pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "layout_for_ptr", issue = "69835")]
|
||||
#[rustc_const_unstable(feature = "const_align_of_val_raw", issue = "46571")]
|
||||
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) }
|
||||
|
@ -13,7 +13,6 @@
|
||||
#![feature(bigint_helper_methods)]
|
||||
#![feature(cell_update)]
|
||||
#![feature(clone_to_uninit)]
|
||||
#![feature(const_align_of_val_raw)]
|
||||
#![feature(const_black_box)]
|
||||
#![feature(const_eval_select)]
|
||||
#![feature(const_nonnull_new)]
|
||||
|
@ -1,6 +1,5 @@
|
||||
#![feature(extern_types)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(const_size_of_val, const_align_of_val)]
|
||||
|
||||
use std::intrinsics::{min_align_of_val, size_of_val};
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:11:31
|
||||
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:10:31
|
||||
|
|
||||
LL | const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
|
||||
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:32
|
||||
--> $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) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
|
||||
|
@ -1,7 +1,6 @@
|
||||
//@ run-pass
|
||||
|
||||
#![feature(const_size_of_val, const_align_of_val)]
|
||||
#![feature(const_size_of_val_raw, const_align_of_val_raw, layout_for_ptr)]
|
||||
#![feature(layout_for_ptr)]
|
||||
|
||||
use std::{mem, ptr};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user