Skip to content

Commit

Permalink
add #[repr(transparent)] for the the FFI layout
Browse files Browse the repository at this point in the history
  • Loading branch information
flier committed May 20, 2021
1 parent 1e41c29 commit 869ff95
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/lib.rs
Expand Up @@ -418,6 +418,7 @@ macro_rules! __bitflags {
}
) => {
$(#[$outer])*
#[repr(transparent)]
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
$($vis)* struct $BitFlags {
bits: $T,
Expand Down Expand Up @@ -588,7 +589,7 @@ macro_rules! __impl_bitflags {
)*
}
}
}
}

/// Returns the raw value of the flags currently stored.
#[inline]
Expand Down Expand Up @@ -1018,12 +1019,12 @@ mod tests {
unsafe { Flags::from_bits_unchecked(0b1001) },
(extra | Flags::A)
);

let extra = unsafe { EmptyFlags::from_bits_unchecked(0b1000) };
assert_eq!(
unsafe { EmptyFlags::from_bits_unchecked(0b1000) },
(extra | EmptyFlags::empty())
);
unsafe { EmptyFlags::from_bits_unchecked(0b1000) },
(extra | EmptyFlags::empty())
);
}

#[test]
Expand Down Expand Up @@ -1286,10 +1287,7 @@ mod tests {
"A | B | C | ABC | 0xb8"
);

assert_eq!(
format!("{:?}", EmptyFlags::empty()),
"(empty)"
);
assert_eq!(format!("{:?}", EmptyFlags::empty()), "(empty)");
}

#[test]
Expand Down

0 comments on commit 869ff95

Please sign in to comment.