Skip to content
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

Use ManuallyDrop instead of mem::forget #2765

Merged
merged 1 commit into from
Oct 18, 2023
Merged
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
13 changes: 6 additions & 7 deletions tracing/src/instrument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::span::Span;
use core::{
future::Future,
marker::Sized,
mem::{self, ManuallyDrop},
mem::ManuallyDrop,
pin::Pin,
task::{Context, Poll},
};
Expand Down Expand Up @@ -392,12 +392,11 @@ impl<T> Instrumented<T> {
///
/// Note that this drops the span.
pub fn into_inner(self) -> T {
// To manually destructure `Instrumented` without `Drop`, we save
// pointers to the fields and use `mem::forget` to leave those pointers
// valid.
let span: *const Span = &self.span;
let inner: *const ManuallyDrop<T> = &self.inner;
mem::forget(self);
// To manually destructure `Instrumented` without `Drop`, we
// move it into a ManuallyDrop and use pointers to its fields
let this = ManuallyDrop::new(self);
let span: *const Span = &this.span;
let inner: *const ManuallyDrop<T> = &this.inner;
// SAFETY: Those pointers are valid for reads, because `Drop` didn't
// run, and properly aligned, because `Instrumented` isn't
// `#[repr(packed)]`.
Expand Down
Loading