From 293df63dffa14749dadc5384115281281073c916 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 20 Dec 2023 13:35:17 -0800 Subject: [PATCH] Add repr(transparent) to hyper_context --- src/ffi/task.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ffi/task.rs b/src/ffi/task.rs index f53a7b1f5a..9f79d706d5 100644 --- a/src/ffi/task.rs +++ b/src/ffi/task.rs @@ -127,6 +127,7 @@ struct TaskFuture { /// its only purpose is to provide access to the waker. See `hyper_waker`. /// /// Corresponding Rust type: +#[repr(transparent)] // we transmute references pub struct hyper_context<'a>(Context<'a>); /// A waker that is saved and used to waken a pending task. @@ -500,7 +501,7 @@ where impl hyper_context<'_> { pub(crate) fn wrap<'a, 'b>(cx: &'a mut Context<'b>) -> &'a mut hyper_context<'b> { - // A struct with only one field has the same layout as that field. + // A repr(transparent) struct has the same layout its dataful field. unsafe { std::mem::transmute::<&mut Context<'_>, &mut hyper_context<'_>>(cx) } } }