Skip to content

Commit 6efe566

Browse files
committed
Mark RawBitFlags as unsafe
An implementation that lies about ALL_BITS could allow creating an invalid value of the underlying enum type. This is not a semver break as the trait is marked _internal.
1 parent 7d751b3 commit 6efe566

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

enumflags_derive/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fn gen_enumflags(ast: &mut ItemEnum, default: Vec<Ident>) -> Result<TokenStream,
336336
}
337337
}
338338

339-
impl ::enumflags2::_internal::RawBitFlags for #ident {
339+
unsafe impl ::enumflags2::_internal::RawBitFlags for #ident {
340340
type Numeric = #repr;
341341

342342
const EMPTY: Self::Numeric = 0;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub trait BitFlag: Copy + Clone + 'static + _internal::RawBitFlags {
188188
pub mod _internal {
189189
/// A trait automatically implemented by `#[bitflags]` to make the enum
190190
/// a valid type parameter for `BitFlags<T>`.
191-
pub trait RawBitFlags: Copy + Clone + 'static {
191+
pub unsafe trait RawBitFlags: Copy + Clone + 'static {
192192
/// The underlying integer type.
193193
type Numeric: BitFlagNum;
194194

0 commit comments

Comments
 (0)