Skip to content

Commit

Permalink
fix(ffi): add repr(transparent) to hyper_context
Browse files Browse the repository at this point in the history
The default representation does not guarantee the absence of initial
padding, which is necessary for the transmute to be sound.
  • Loading branch information
LegionMammal978 committed Apr 2, 2023
1 parent 47f614f commit ad3a135
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ffi/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ struct TaskFuture {
}

/// An async context for a task that contains the related waker.
#[repr(transparent)]
pub struct hyper_context<'a>(Context<'a>);

/// A waker that is saved and used to waken a pending task.
Expand Down Expand Up @@ -378,7 +379,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 with only one field has the same layout as that field.
unsafe { std::mem::transmute::<&mut Context<'_>, &mut hyper_context<'_>>(cx) }
}
}
Expand Down

0 comments on commit ad3a135

Please sign in to comment.