Skip to content

Commit 187b8f2

Browse files
fix(ffi): add repr(transparent) to hyper_context (#3191)
The default representation does not guarantee the absence of initial padding, which is necessary for the transmute to be sound.
1 parent ed99c09 commit 187b8f2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/ffi/task.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct TaskFuture {
6666
}
6767

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

7172
/// A waker that is saved and used to waken a pending task.
@@ -378,7 +379,7 @@ where
378379

379380
impl hyper_context<'_> {
380381
pub(crate) fn wrap<'a, 'b>(cx: &'a mut Context<'b>) -> &'a mut hyper_context<'b> {
381-
// A struct with only one field has the same layout as that field.
382+
// A repr(transparent) struct with only one field has the same layout as that field.
382383
unsafe { std::mem::transmute::<&mut Context<'_>, &mut hyper_context<'_>>(cx) }
383384
}
384385
}

0 commit comments

Comments
 (0)