|
4 | 4 | //! types, initializing and manipulating memory.
|
5 | 5 |
|
6 | 6 | #![stable(feature = "rust1", since = "1.0.0")]
|
| 7 | +#![cfg_attr(bootstrap, allow(unused_unsafe))] |
7 | 8 |
|
8 | 9 | use crate::clone;
|
9 | 10 | use crate::cmp;
|
@@ -333,7 +334,8 @@ pub const fn size_of<T>() -> usize {
|
333 | 334 | #[stable(feature = "rust1", since = "1.0.0")]
|
334 | 335 | #[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
|
335 | 336 | pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
|
336 |
| - intrinsics::size_of_val(val) |
| 337 | + // SAFETY: `val` is a reference, so it's a valid raw pointer |
| 338 | + unsafe { intrinsics::size_of_val(val) } |
337 | 339 | }
|
338 | 340 |
|
339 | 341 | /// Returns the size of the pointed-to value in bytes.
|
@@ -381,7 +383,8 @@ pub const fn size_of_val<T: ?Sized>(val: &T) -> usize {
|
381 | 383 | #[unstable(feature = "layout_for_ptr", issue = "69835")]
|
382 | 384 | #[rustc_const_unstable(feature = "const_size_of_val_raw", issue = "46571")]
|
383 | 385 | pub const unsafe fn size_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
384 |
| - intrinsics::size_of_val(val) |
| 386 | + // SAFETY: the caller must provide a valid raw pointer |
| 387 | + unsafe { intrinsics::size_of_val(val) } |
385 | 388 | }
|
386 | 389 |
|
387 | 390 | /// Returns the [ABI]-required minimum alignment of a type.
|
@@ -425,7 +428,8 @@ pub fn min_align_of<T>() -> usize {
|
425 | 428 | #[stable(feature = "rust1", since = "1.0.0")]
|
426 | 429 | #[rustc_deprecated(reason = "use `align_of_val` instead", since = "1.2.0")]
|
427 | 430 | pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
|
428 |
| - intrinsics::min_align_of_val(val) |
| 431 | + // SAFETY: val is a reference, so it's a valid raw pointer |
| 432 | + unsafe { intrinsics::min_align_of_val(val) } |
429 | 433 | }
|
430 | 434 |
|
431 | 435 | /// Returns the [ABI]-required minimum alignment of a type.
|
@@ -469,7 +473,8 @@ pub const fn align_of<T>() -> usize {
|
469 | 473 | #[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
|
470 | 474 | #[allow(deprecated)]
|
471 | 475 | pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
|
472 |
| - intrinsics::min_align_of_val(val) |
| 476 | + // SAFETY: val is a reference, so it's a valid raw pointer |
| 477 | + unsafe { intrinsics::min_align_of_val(val) } |
473 | 478 | }
|
474 | 479 |
|
475 | 480 | /// Returns the [ABI]-required minimum alignment of the type of the value that `val` points to.
|
@@ -513,7 +518,8 @@ pub const fn align_of_val<T: ?Sized>(val: &T) -> usize {
|
513 | 518 | #[unstable(feature = "layout_for_ptr", issue = "69835")]
|
514 | 519 | #[rustc_const_unstable(feature = "const_align_of_val_raw", issue = "46571")]
|
515 | 520 | pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
|
516 |
| - intrinsics::min_align_of_val(val) |
| 521 | + // SAFETY: the caller must provide a valid raw pointer |
| 522 | + unsafe { intrinsics::min_align_of_val(val) } |
517 | 523 | }
|
518 | 524 |
|
519 | 525 | /// Returns `true` if dropping values of type `T` matters.
|
|
0 commit comments