Skip to content

Commit bfdbab2

Browse files
committed
Add repr(transparent) to the newtypes.
This comes from the suggestion [here]. [here]: rust-lang/rust#76969 (comment)
1 parent a84f5b8 commit bfdbab2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/unsafe_handle.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ pub trait FromUnsafeSocket {
349349
/// Note that this doesn't implement `Into*` or `From*` traits, as those imply
350350
/// ownership transfers, and this type is non-owning.
351351
#[derive(Copy, Clone)]
352+
#[repr(transparent)]
352353
pub struct UnsafeHandle(InnerFileOrSocket);
353354

354355
/// A non-owning unsafe I/O handle which on Windows is limited to handling what
@@ -358,6 +359,7 @@ pub struct UnsafeHandle(InnerFileOrSocket);
358359
///
359360
/// [`RawHandle`]: https://doc.rust-lang.org/std/os/windows/io/type.RawHandle.html
360361
#[derive(Copy, Clone)]
362+
#[repr(transparent)]
361363
pub struct UnsafeFile(InnerFile);
362364

363365
/// A non-owning unsafe I/O handle which on Windows is limited to handling what
@@ -368,20 +370,23 @@ pub struct UnsafeFile(InnerFile);
368370
///
369371
/// [`RawSocket`]: https://doc.rust-lang.org/std/os/windows/io/type.RawSocket.html
370372
#[derive(Copy, Clone)]
373+
#[repr(transparent)]
371374
pub struct UnsafeSocket(InnerSocket);
372375

373376
/// A non-owning unsafe I/O handle that implements [`Read`]. `Read` functions
374377
/// are considered safe, so this type requires `unsafe` to construct.
375378
///
376379
/// Like [`UnsafeHandle`], this doesn't implement `Into*` or `From*` traits.
377380
#[derive(Copy, Clone)]
381+
#[repr(transparent)]
378382
pub struct UnsafeReadable(InnerFileOrSocket);
379383

380384
/// A non-owning unsafe I/O handle that implements [`Write`]. `Write` functions
381385
/// considered are safe, so this type requires `unsafe` to construct.
382386
///
383387
/// Like [`UnsafeHandle`], this doesn't implement `Into*` or `From*` traits.
384388
#[derive(Copy, Clone)]
389+
#[repr(transparent)]
385390
pub struct UnsafeWriteable(InnerFileOrSocket);
386391

387392
/// Posix-ish platforms use a single "file descriptor" type for all the kinds

0 commit comments

Comments
 (0)