Skip to content

Add #[track_caller] for some function in core::mem. #86664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ impl<T> MaybeUninit<T> {
#[rustc_const_unstable(feature = "const_maybe_uninit_assume_init", issue = "none")]
#[inline(always)]
#[rustc_diagnostic_item = "assume_init"]
#[track_caller]
pub const unsafe fn assume_init(self) -> T {
// SAFETY: the caller must guarantee that `self` is initialized.
// This also means that `self` must be a `value` variant.
Expand Down Expand Up @@ -690,6 +691,7 @@ impl<T> MaybeUninit<T> {
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
#[rustc_const_unstable(feature = "maybe_uninit_extra", issue = "63567")]
#[inline(always)]
#[track_caller]
pub const unsafe fn assume_init_read(&self) -> T {
// SAFETY: the caller must guarantee that `self` is initialized.
// Reading from `self.as_ptr()` is safe since `self` should be initialized.
Expand Down Expand Up @@ -937,6 +939,7 @@ impl<T> MaybeUninit<T> {
/// ```
#[unstable(feature = "maybe_uninit_array_assume_init", issue = "80908")]
#[inline(always)]
#[track_caller]
pub unsafe fn array_assume_init<const N: usize>(array: [Self; N]) -> [T; N] {
// SAFETY:
// * The caller guarantees that all elements of the array are initialized
Expand Down
2 changes: 2 additions & 0 deletions library/core/src/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ pub const fn needs_drop<T>() -> bool {
#[allow(deprecated_in_future)]
#[allow(deprecated)]
#[rustc_diagnostic_item = "mem_zeroed"]
#[track_caller]
pub unsafe fn zeroed<T>() -> T {
// SAFETY: the caller must guarantee that an all-zero value is valid for `T`.
unsafe {
Expand Down Expand Up @@ -657,6 +658,7 @@ pub unsafe fn zeroed<T>() -> T {
#[allow(deprecated_in_future)]
#[allow(deprecated)]
#[rustc_diagnostic_item = "mem_uninitialized"]
#[track_caller]
pub unsafe fn uninitialized<T>() -> T {
// SAFETY: the caller must guarantee that an unitialized value is valid for `T`.
unsafe {
Expand Down
12 changes: 2 additions & 10 deletions src/test/ui/consts/assume-type-intrinsics.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
error: any use of this value will cause an error
--> $SRC_DIR/core/src/mem/maybe_uninit.rs:LL:COL
|
LL | intrinsics::assert_inhabited::<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| aborted execution: attempted to instantiate uninhabited type `!`
| inside `MaybeUninit::<!>::assume_init` at $SRC_DIR/core/src/mem/maybe_uninit.rs:LL:COL
| inside `_BAD` at $DIR/assume-type-intrinsics.rs:11:9
|
::: $DIR/assume-type-intrinsics.rs:10:5
--> $DIR/assume-type-intrinsics.rs:11:9
|
LL | / const _BAD: () = unsafe {
LL | | MaybeUninit::<!>::uninit().assume_init();
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to instantiate uninhabited type `!`
LL | | };
| |______-
|
Expand Down