Skip to content
/ rust Public
forked from rust-lang/rust
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df66045

Browse files
authoredDec 3, 2024
Rollup merge of rust-lang#133762 - RalfJung:const-size-of-val, r=workingjubilee
stabilize const_{size,align}_of_val FCP passed [here](rust-lang#46571 (comment)). Fixes rust-lang#46571.
2 parents 712e0e3 + 2b88e4c commit df66045

7 files changed

+8
-11
lines changed
 

‎library/core/src/alloc/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ impl Layout {
179179
/// or other unsized type like a slice).
180180
#[stable(feature = "alloc_layout", since = "1.28.0")]
181181
#[rustc_const_unstable(feature = "const_alloc_layout", issue = "67521")]
182+
#[rustc_const_stable_indirect]
182183
#[must_use]
183184
#[inline]
184185
pub const fn for_value<T: ?Sized>(t: &T) -> Self {
@@ -215,7 +216,6 @@ impl Layout {
215216
/// [trait object]: ../../book/ch17-02-trait-objects.html
216217
/// [extern type]: ../../unstable-book/language-features/extern-types.html
217218
#[unstable(feature = "layout_for_ptr", issue = "69835")]
218-
#[rustc_const_unstable(feature = "layout_for_ptr", issue = "69835")]
219219
#[must_use]
220220
pub const unsafe fn for_value_raw<T: ?Sized>(t: *const T) -> Self {
221221
// SAFETY: we pass along the prerequisites of these functions to the caller

‎library/core/src/intrinsics/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4099,6 +4099,7 @@ pub const fn variant_count<T>() -> usize {
40994099
#[unstable(feature = "core_intrinsics", issue = "none")]
41004100
#[rustc_intrinsic]
41014101
#[rustc_intrinsic_must_be_overridden]
4102+
#[rustc_intrinsic_const_stable_indirect]
41024103
pub const unsafe fn size_of_val<T: ?Sized>(_ptr: *const T) -> usize {
41034104
unreachable!()
41044105
}
@@ -4114,6 +4115,7 @@ pub const unsafe fn size_of_val<T: ?Sized>(_ptr: *const T) -> usize {
41144115
#[unstable(feature = "core_intrinsics", issue = "none")]
41154116
#[rustc_intrinsic]
41164117
#[rustc_intrinsic_must_be_overridden]
4118+
#[rustc_intrinsic_const_stable_indirect]
41174119
pub const unsafe fn min_align_of_val<T: ?Sized>(_ptr: *const T) -> usize {
41184120
unreachable!()
41194121
}

‎library/core/src/mem/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub const fn size_of<T>() -> usize {
333333
#[inline]
334334
#[must_use]
335335
#[stable(feature = "rust1", since = "1.0.0")]
336-
#[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
336+
#[rustc_const_stable(feature = "const_size_of_val", since = "CURRENT_RUSTC_VERSION")]
337337
#[cfg_attr(not(test), rustc_diagnostic_item = "mem_size_of_val")]
338338
pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
339339
// 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 {
390390
#[inline]
391391
#[must_use]
392392
#[unstable(feature = "layout_for_ptr", issue = "69835")]
393-
#[rustc_const_unstable(feature = "const_size_of_val_raw", issue = "46571")]
394393
pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
395394
// SAFETY: the caller must provide a valid raw pointer
396395
unsafe { intrinsics::size_of_val(val) }
@@ -485,7 +484,7 @@ pub const fn align_of<T>() -> usize {
485484
#[inline]
486485
#[must_use]
487486
#[stable(feature = "rust1", since = "1.0.0")]
488-
#[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
487+
#[rustc_const_stable(feature = "const_align_of_val", since = "CURRENT_RUSTC_VERSION")]
489488
#[allow(deprecated)]
490489
pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
491490
// 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 {
534533
#[inline]
535534
#[must_use]
536535
#[unstable(feature = "layout_for_ptr", issue = "69835")]
537-
#[rustc_const_unstable(feature = "const_align_of_val_raw", issue = "46571")]
538536
pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
539537
// SAFETY: the caller must provide a valid raw pointer
540538
unsafe { intrinsics::min_align_of_val(val) }

‎library/core/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![feature(bigint_helper_methods)]
1414
#![feature(cell_update)]
1515
#![feature(clone_to_uninit)]
16-
#![feature(const_align_of_val_raw)]
1716
#![feature(const_black_box)]
1817
#![feature(const_eval_select)]
1918
#![feature(const_nonnull_new)]

‎tests/ui/consts/const-size_of_val-align_of_val-extern-type.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(extern_types)]
22
#![feature(core_intrinsics)]
3-
#![feature(const_size_of_val, const_align_of_val)]
43

54
use std::intrinsics::{min_align_of_val, size_of_val};
65

‎tests/ui/consts/const-size_of_val-align_of_val-extern-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:11:31
2+
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:10:31
33
|
44
LL | const _SIZE: usize = unsafe { size_of_val(&4 as *const i32 as *const Opaque) };
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout
66

77
error[E0080]: evaluation of constant value failed
8-
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:12:32
8+
--> $DIR/const-size_of_val-align_of_val-extern-type.rs:11:32
99
|
1010
LL | const _ALIGN: usize = unsafe { min_align_of_val(&4 as *const i32 as *const Opaque) };
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `extern type` does not have known layout

‎tests/ui/consts/const-size_of_val-align_of_val.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ run-pass
22

3-
#![feature(const_size_of_val, const_align_of_val)]
4-
#![feature(const_size_of_val_raw, const_align_of_val_raw, layout_for_ptr)]
3+
#![feature(layout_for_ptr)]
54

65
use std::{mem, ptr};
76

0 commit comments

Comments
 (0)
Please sign in to comment.