Skip to content

Commit

Permalink
Remove unnecessary unsafe code
Browse files Browse the repository at this point in the history
  • Loading branch information
meithecatte committed Mar 24, 2022
1 parent 7af4376 commit 7d751b3
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions enumflags_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,45 +293,46 @@ fn gen_enumflags(ast: &mut ItemEnum, default: Vec<Ident>) -> Result<TokenStream,
));
}

let std_path = quote_spanned!(span => ::enumflags2::_internal::core);
let std = quote_spanned!(span => ::enumflags2::_internal::core);
let variant_names = ast.variants.iter().map(|v| &v.ident).collect::<Vec<_>>();

Ok(quote_spanned! {
span =>
#ast
#(#deferred)*
impl #std_path::ops::Not for #ident {
impl #std::ops::Not for #ident {
type Output = ::enumflags2::BitFlags<Self>;
#[inline(always)]
fn not(self) -> Self::Output {
use ::enumflags2::{BitFlags, _internal::RawBitFlags};
unsafe { BitFlags::from_bits_unchecked(self.bits()).not() }
use ::enumflags2::BitFlags;
BitFlags::from_flag(self).not()
}
}

impl #std_path::ops::BitOr for #ident {
impl #std::ops::BitOr for #ident {
type Output = ::enumflags2::BitFlags<Self>;
#[inline(always)]
fn bitor(self, other: Self) -> Self::Output {
use ::enumflags2::{BitFlags, _internal::RawBitFlags};
unsafe { BitFlags::from_bits_unchecked(self.bits() | other.bits())}
use ::enumflags2::BitFlags;
BitFlags::from_flag(self) | other
}
}

impl #std_path::ops::BitAnd for #ident {
impl #std::ops::BitAnd for #ident {
type Output = ::enumflags2::BitFlags<Self>;
#[inline(always)]
fn bitand(self, other: Self) -> Self::Output {
use ::enumflags2::{BitFlags, _internal::RawBitFlags};
unsafe { BitFlags::from_bits_unchecked(self.bits() & other.bits())}
use ::enumflags2::BitFlags;
BitFlags::from_flag(self) & other
}
}

impl #std_path::ops::BitXor for #ident {
impl #std::ops::BitXor for #ident {
type Output = ::enumflags2::BitFlags<Self>;
#[inline(always)]
fn bitxor(self, other: Self) -> Self::Output {
#std_path::convert::Into::<Self::Output>::into(self) ^ #std_path::convert::Into::<Self::Output>::into(other)
use ::enumflags2::BitFlags;
BitFlags::from_flag(self) ^ other
}
}

Expand Down

0 comments on commit 7d751b3

Please sign in to comment.