Dataset Viewer
Auto-converted to Parquet Duplicate
repo
stringclasses
1 value
pull_number
int64
266
411
instance_id
stringclasses
8 values
issue_numbers
sequencelengths
1
1
base_commit
stringclasses
7 values
patch
stringclasses
8 values
test_patch
stringclasses
8 values
problem_statement
stringclasses
8 values
hints_text
stringclasses
6 values
created_at
stringclasses
8 values
version
stringclasses
5 values
FAIL_TO_PASS
sequencelengths
1
6
PASS_TO_PASS
sequencelengths
57
81
FAIL_TO_FAIL
sequencelengths
0
0
PASS_TO_FAIL
sequencelengths
0
0
bitflags/bitflags
411
bitflags__bitflags-411
[ "406" ]
9c4b93c931e34a5104f50e20be1bdd15bc593b0e
diff --git a/src/lib.rs b/src/lib.rs index 8f722591..b5e8911b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -38,7 +38,7 @@ bitflags! { See the docs for the `bitflags` macro for the full syntax. -Also see the [`example_generated`] module for an example of what the `bitflags` macro generates for a flags type. +Also see the [`example_generated`](./example_generated/index.html) module for an example of what the `bitflags` macro generates for a flags type. ### Externally defined flags @@ -530,6 +530,7 @@ macro_rules! bitflags { } }; ( + $(#[$outer:meta])* impl $BitFlags:ident: $T:ty { $( $(#[$inner:ident $($args:tt)*])* @@ -561,6 +562,7 @@ macro_rules! bitflags { )] const _: () = { $crate::__impl_public_bitflags! { + $(#[$outer])* $BitFlags: $T, $BitFlags { $( $(#[$inner $($args)*])* @@ -593,6 +595,7 @@ macro_rules! bitflags { #[doc(hidden)] macro_rules! __impl_bitflags { ( + $(#[$outer:meta])* $PublicBitFlags:ident: $T:ty { fn empty() $empty:block fn all() $all:block @@ -617,6 +620,7 @@ macro_rules! __impl_bitflags { } ) => { #[allow(dead_code, deprecated, unused_attributes)] + $(#[$outer])* impl $PublicBitFlags { /// Get a flags value with all bits unset. #[inline] diff --git a/src/public.rs b/src/public.rs index dc2d7267..feecdd67 100644 --- a/src/public.rs +++ b/src/public.rs @@ -26,9 +26,11 @@ macro_rules! __declare_public_bitflags { #[doc(hidden)] macro_rules! __impl_public_bitflags_forward { ( + $(#[$outer:meta])* $PublicBitFlags:ident: $T:ty, $InternalBitFlags:ident ) => { $crate::__impl_bitflags! { + $(#[$outer])* $PublicBitFlags: $T { fn empty() { Self($InternalBitFlags::empty()) @@ -128,6 +130,7 @@ macro_rules! __impl_public_bitflags_forward { #[doc(hidden)] macro_rules! __impl_public_bitflags { ( + $(#[$outer:meta])* $BitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$inner:ident $($args:tt)*])* @@ -136,6 +139,7 @@ macro_rules! __impl_public_bitflags { } ) => { $crate::__impl_bitflags! { + $(#[$outer])* $BitFlags: $T { fn empty() { Self(<$T as $crate::Bits>::EMPTY) @@ -271,7 +275,11 @@ macro_rules! __impl_public_bitflags { #[macro_export] #[doc(hidden)] macro_rules! __impl_public_bitflags_iter { - ($BitFlags:ident: $T:ty, $PublicBitFlags:ident) => { + ( + $(#[$outer:meta])* + $BitFlags:ident: $T:ty, $PublicBitFlags:ident + ) => { + $(#[$outer])* impl $BitFlags { /// Yield a set of contained flags values. /// @@ -300,6 +308,7 @@ macro_rules! __impl_public_bitflags_iter { } } + $(#[$outer:meta])* impl $crate::__private::core::iter::IntoIterator for $BitFlags { type Item = $PublicBitFlags; type IntoIter = $crate::iter::Iter<$PublicBitFlags>; @@ -315,7 +324,12 @@ macro_rules! __impl_public_bitflags_iter { #[macro_export] #[doc(hidden)] macro_rules! __impl_public_bitflags_ops { - ($PublicBitFlags:ident) => { + ( + $(#[$outer:meta])* + $PublicBitFlags:ident + ) => { + + $(#[$outer])* impl $crate::__private::core::fmt::Binary for $PublicBitFlags { fn fmt( &self, @@ -326,6 +340,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::fmt::Octal for $PublicBitFlags { fn fmt( &self, @@ -336,6 +351,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::fmt::LowerHex for $PublicBitFlags { fn fmt( &self, @@ -346,6 +362,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::fmt::UpperHex for $PublicBitFlags { fn fmt( &self, @@ -356,6 +373,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::BitOr for $PublicBitFlags { type Output = Self; @@ -366,6 +384,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::BitOrAssign for $PublicBitFlags { /// The bitwise or (`|`) of the bits in two flags values. #[inline] @@ -374,6 +393,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::BitXor for $PublicBitFlags { type Output = Self; @@ -384,6 +404,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::BitXorAssign for $PublicBitFlags { /// The bitwise exclusive-or (`^`) of the bits in two flags values. #[inline] @@ -392,6 +413,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::BitAnd for $PublicBitFlags { type Output = Self; @@ -402,6 +424,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::BitAndAssign for $PublicBitFlags { /// The bitwise and (`&`) of the bits in two flags values. #[inline] @@ -410,6 +433,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::Sub for $PublicBitFlags { type Output = Self; @@ -423,6 +447,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::SubAssign for $PublicBitFlags { /// The intersection of a source flags value with the complement of a target flags value (`&!`). /// @@ -434,6 +459,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::ops::Not for $PublicBitFlags { type Output = Self; @@ -444,6 +470,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::iter::Extend<$PublicBitFlags> for $PublicBitFlags { /// The bitwise or (`|`) of the bits in each flags value. fn extend<T: $crate::__private::core::iter::IntoIterator<Item = Self>>( @@ -456,6 +483,7 @@ macro_rules! __impl_public_bitflags_ops { } } + $(#[$outer])* impl $crate::__private::core::iter::FromIterator<$PublicBitFlags> for $PublicBitFlags { /// The bitwise or (`|`) of the bits in each flags value. fn from_iter<T: $crate::__private::core::iter::IntoIterator<Item = Self>>( @@ -476,6 +504,7 @@ macro_rules! __impl_public_bitflags_ops { #[doc(hidden)] macro_rules! __impl_public_bitflags_consts { ( + $(#[$outer:meta])* $PublicBitFlags:ident: $T:ty { $( $(#[$inner:ident $($args:tt)*])* @@ -483,6 +512,7 @@ macro_rules! __impl_public_bitflags_consts { )* } ) => { + $(#[$outer])* impl $PublicBitFlags { $( $crate::__bitflags_flag!({ @@ -500,6 +530,7 @@ macro_rules! __impl_public_bitflags_consts { )* } + $(#[$outer])* impl $crate::Flags for $PublicBitFlags { const FLAGS: &'static [$crate::Flag<$PublicBitFlags>] = &[ $(
diff --git a/tests/compile-pass/bitflags_impl_attrs.rs b/tests/compile-pass/bitflags_impl_attrs.rs new file mode 100644 index 00000000..91d89823 --- /dev/null +++ b/tests/compile-pass/bitflags_impl_attrs.rs @@ -0,0 +1,13 @@ +extern crate bitflags; + +struct Example(u64); + +bitflags::bitflags! { + /// Docs on the `impl` block. + #[allow(dead_code)] + impl Example: u64 { + const flag = 0b01; + } +} + +fn main() {}
Allow specifying attributes in `impl` mode I'm considering `cfg`-gating the use of `bitflags!` in my libraries, and to that end it would be nice if it was possible to apply attributes to the generated `impl`s as well. The naive solution would be: ```rust pub struct Flags(u8); #[cfg(feature = "bitflags")] bitflags! { impl Flags: u8 { // ... } } ``` However, that works poorly with the `doc_cfg` (and `doc_auto_cfg`) feature, as the attribute is only applied to the macro, and isn't passed down to each output item. Instead, I would like to be able to do the following: ```rust #![feature(doc_cfg)] pub struct Flags(u8); #[cfg(feature = "bitflags")] bitflags! { #[doc(cfg(feature = "bitflags"))] impl Flags: u8 { // ... } } ```
Thanks for the report @madsmtm! Anywhere attributes are allowed to be specified we should support in the macros as much as possible. I think this is just a missing piece of functionality for the impl mode.
2024-06-24T23:17:40Z
2.5
[ "tests/compile-pass/bitflags_impl_attrs.rs" ]
[ "tests::complement::cases", "tests::bits::cases", "tests::all::cases", "tests::contains::cases", "tests::difference::cases", "tests::empty::cases", "tests::eq::cases", "tests::extend::cases", "tests::extend::external::cases", "tests::flags::external::cases", "tests::from_bits::cases", "tests::flags::cases", "tests::from_bits_retain::cases", "tests::from_name::cases", "tests::intersection::cases", "tests::insert::cases", "tests::intersects::cases", "tests::is_all::cases", "tests::is_empty::cases", "tests::iter::collect::cases", "tests::iter::iter::cases", "tests::iter::iter_names::cases", "tests::parser::from_str::invalid", "tests::from_bits_truncate::cases", "tests::parser::from_str::valid", "tests::parser::from_str_strict::invalid", "tests::parser::from_str_truncate::valid", "tests::parser::from_str_strict::valid", "tests::parser::to_writer_truncate::cases", "tests::remove::cases", "tests::parser::to_writer_strict::cases", "tests::union::cases", "tests::symmetric_difference::cases", "tests::fmt::cases", "tests::parser::to_writer::cases", "tests::iter::roundtrip", "tests::parser::roundtrip_truncate", "tests::parser::roundtrip", "tests::parser::roundtrip_strict", "tests/compile-pass/bitflags_impl_repr_packed.rs", "tests/compile-pass/bitflags_nested_value.rs", "tests/compile-pass/bitflags_redefined_value.rs", "tests/compile-pass/bitflags_self_in_value.rs", "tests/compile-pass/bitflags_trait_bound_flags.rs", "tests/compile-pass/bitflags_trait_generic_iter.rs", "tests/compile-pass/bitflags_trait_precedence.rs", "tests/compile-pass/bitflags_trait_supertrait.rs", "tests/compile-pass/bitflags_trait_to_flags.rs", "tests/compile-pass/bitflags_visibility.rs", "tests/compile-pass/deprecated.rs", "tests/compile-pass/doc_alias.rs", "tests/compile-pass/flags_trait_bound_bitflags.rs", "tests/compile-pass/flags_trait_generic_iter.rs", "tests/compile-pass/flags_trait_precedence.rs", "tests/compile-pass/flags_trait_supertrait.rs", "tests/compile-pass/impl_convert_from_bits.rs", "tests/compile-pass/impl_copy.rs", "tests/compile-pass/impl_default.rs", "tests/compile-pass/impl_eq.rs", "tests/compile-pass/impl_fmt.rs", "tests/compile-pass/impl_new.rs", "tests/compile-pass/into_iter_trait_wrapped.rs", "tests/compile-pass/item_positions.rs", "tests/compile-pass/large.rs", "tests/compile-pass/missing_docs.rs", "tests/compile-pass/no_prelude.rs", "tests/compile-pass/non_snake_case.rs", "tests/compile-pass/parser_strict_non_hex_bits.rs", "tests/compile-pass/path_based_bits.rs", "tests/compile-pass/repr_c.rs", "tests/compile-pass/repr_transparent.rs", "tests/compile-pass/shadow_core.rs", "tests/compile-pass/shadow_macros.rs", "tests/compile-pass/shadow_result.rs", "tests/compile-pass/unnamed.rs" ]
[]
[]
bitflags/bitflags
355
bitflags__bitflags-355
[ "357" ]
31d3e4afefc964045156d7fe3622733f48511353
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6ebd5a74..15d1f950 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -81,6 +81,23 @@ jobs: - name: Default features run: cross test --target mips-unknown-linux-gnu + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab + + - name: Install Clippy + run: | + rustup update beta + rustup component add clippy --toolchain beta + + - name: Default features + run: | + cd ./tests/smoke-test + cargo +beta clippy + embedded: name: Build (embedded) runs-on: ubuntu-latest diff --git a/src/example_generated.rs b/src/example_generated.rs index 0fda40c0..7f8a5c5d 100644 --- a/src/example_generated.rs +++ b/src/example_generated.rs @@ -39,7 +39,7 @@ __impl_public_bitflags_forward! { } __impl_public_bitflags_iter! { - Flags + Flags: u32, Flags } __impl_public_bitflags_consts! { diff --git a/src/external.rs b/src/external.rs index f3fbac0d..103b5d1e 100644 --- a/src/external.rs +++ b/src/external.rs @@ -19,7 +19,7 @@ Next, define a macro like so: #[cfg(feature = "serde")] macro_rules! __impl_external_bitflags_my_library { ( - $InternalBitFlags:ident: $T:ty { + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$attr:ident $($args:tt)*])* $Flag:ident; @@ -35,7 +35,7 @@ macro_rules! __impl_external_bitflags_my_library { #[cfg(not(feature = "my_library"))] macro_rules! __impl_external_bitflags_my_library { ( - $InternalBitFlags:ident: $T:ty { + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$attr:ident $($args:tt)*])* $Flag:ident; @@ -55,7 +55,7 @@ Now, we add our macro call to the `__impl_external_bitflags` macro body: ```rust __impl_external_bitflags_my_library! { - $InternalBitFlags: $T { + $InternalBitFlags: $T, $PublicBitFlags { $( $(#[$attr $($args)*])* $Flag; @@ -76,6 +76,51 @@ pub(crate) mod __private { pub use bytemuck; } +/// Implements traits from external libraries for the internal bitflags type. +#[macro_export(local_inner_macros)] +#[doc(hidden)] +macro_rules! __impl_external_bitflags { + ( + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { + $( + $(#[$attr:ident $($args:tt)*])* + $Flag:ident; + )* + } + ) => { + // Any new library traits impls should be added here + // Use `serde` as an example: generate code when the feature is available, + // and a no-op when it isn't + + __impl_external_bitflags_serde! { + $InternalBitFlags: $T, $PublicBitFlags { + $( + $(#[$attr $($args)*])* + $Flag; + )* + } + } + + __impl_external_bitflags_arbitrary! { + $InternalBitFlags: $T, $PublicBitFlags { + $( + $(#[$attr $($args)*])* + $Flag; + )* + } + } + + __impl_external_bitflags_bytemuck! { + $InternalBitFlags: $T, $PublicBitFlags { + $( + $(#[$attr $($args)*])* + $Flag; + )* + } + } + }; +} + #[cfg(feature = "serde")] pub mod serde; @@ -85,11 +130,11 @@ pub mod serde; #[cfg(feature = "serde")] macro_rules! __impl_external_bitflags_serde { ( - $InternalBitFlags:ident: $T:ty { + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$attr:ident $($args:tt)*])* $Flag:ident; - )* + )* } ) => { impl $crate::__private::serde::Serialize for $InternalBitFlags { @@ -98,7 +143,7 @@ macro_rules! __impl_external_bitflags_serde { serializer: S, ) -> $crate::__private::core::result::Result<S::Ok, S::Error> { $crate::serde::serialize( - self, + &$PublicBitFlags::from_bits_retain(self.bits()), serializer, ) } @@ -108,9 +153,11 @@ macro_rules! __impl_external_bitflags_serde { fn deserialize<D: $crate::__private::serde::Deserializer<'de>>( deserializer: D, ) -> $crate::__private::core::result::Result<Self, D::Error> { - $crate::serde::deserialize( + let flags: $PublicBitFlags = $crate::serde::deserialize( deserializer, - ) + )?; + + Ok(flags.0) } } }; @@ -121,11 +168,11 @@ macro_rules! __impl_external_bitflags_serde { #[cfg(not(feature = "serde"))] macro_rules! __impl_external_bitflags_serde { ( - $InternalBitFlags:ident: $T:ty { + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$attr:ident $($args:tt)*])* $Flag:ident; - )* + )* } ) => {}; } @@ -136,58 +183,13 @@ pub mod arbitrary; #[cfg(feature = "bytemuck")] mod bytemuck; -/// Implements traits from external libraries for the internal bitflags type. -#[macro_export(local_inner_macros)] -#[doc(hidden)] -macro_rules! __impl_external_bitflags { - ( - $InternalBitFlags:ident: $T:ty { - $( - $(#[$attr:ident $($args:tt)*])* - $Flag:ident; - )* - } - ) => { - // Any new library traits impls should be added here - // Use `serde` as an example: generate code when the feature is available, - // and a no-op when it isn't - - __impl_external_bitflags_serde! { - $InternalBitFlags: $T { - $( - $(#[$attr $($args)*])* - $Flag; - )* - } - } - - __impl_external_bitflags_arbitrary! { - $InternalBitFlags: $T { - $( - $(#[$attr $($args)*])* - $Flag; - )* - } - } - - __impl_external_bitflags_bytemuck! { - $InternalBitFlags: $T { - $( - $(#[$attr $($args)*])* - $Flag; - )* - } - } - }; -} - /// Implement `Arbitrary` for the internal bitflags type. #[macro_export(local_inner_macros)] #[doc(hidden)] #[cfg(feature = "arbitrary")] macro_rules! __impl_external_bitflags_arbitrary { ( - $InternalBitFlags:ident: $T:ty { + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$attr:ident $($args:tt)*])* $Flag:ident; @@ -198,7 +200,7 @@ macro_rules! __impl_external_bitflags_arbitrary { fn arbitrary( u: &mut $crate::__private::arbitrary::Unstructured<'a>, ) -> $crate::__private::arbitrary::Result<Self> { - $crate::arbitrary::arbitrary(u) + $crate::arbitrary::arbitrary::<$PublicBitFlags>(u).map(|flags| flags.0) } } }; @@ -209,12 +211,12 @@ macro_rules! __impl_external_bitflags_arbitrary { #[cfg(not(feature = "arbitrary"))] macro_rules! __impl_external_bitflags_arbitrary { ( - $InternalBitFlags:ident: $T:ty { - $( - $(#[$attr:ident $($args:tt)*])* - $Flag:ident; - )* - } + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { + $( + $(#[$attr:ident $($args:tt)*])* + $Flag:ident; + )* + } ) => {}; } @@ -224,11 +226,11 @@ macro_rules! __impl_external_bitflags_arbitrary { #[cfg(feature = "bytemuck")] macro_rules! __impl_external_bitflags_bytemuck { ( - $InternalBitFlags:ident: $T:ty { + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$attr:ident $($args:tt)*])* - $Flag:ident; - )* + $Flag:ident; + )* } ) => { // SAFETY: $InternalBitFlags is guaranteed to have the same ABI as $T, @@ -256,11 +258,11 @@ macro_rules! __impl_external_bitflags_bytemuck { #[cfg(not(feature = "bytemuck"))] macro_rules! __impl_external_bitflags_bytemuck { ( - $InternalBitFlags:ident: $T:ty { + $InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$attr:ident $($args:tt)*])* - $Flag:ident; - )* + $Flag:ident; + )* } ) => {}; } diff --git a/src/internal.rs b/src/internal.rs index 8347b03f..c4fb6533 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -98,7 +98,7 @@ macro_rules! __impl_internal_bitflags { // The internal flags type offers a similar API to the public one __impl_public_bitflags! { - $InternalBitFlags: $T { + $InternalBitFlags: $T, $PublicBitFlags { $( $(#[$attr $($args)*])* $Flag; @@ -106,19 +106,8 @@ macro_rules! __impl_internal_bitflags { } } - __impl_public_bitflags_consts! { - $InternalBitFlags: $T { - $( - $(#[$attr $($args)*])* - #[allow( - dead_code, - deprecated, - unused_attributes, - non_upper_case_globals - )] - $Flag = $value; - )* - } + __impl_public_bitflags_iter! { + $InternalBitFlags: $T, $PublicBitFlags } impl $InternalBitFlags { @@ -127,18 +116,6 @@ macro_rules! __impl_internal_bitflags { pub fn bits_mut(&mut self) -> &mut $T { &mut self.0 } - - /// Iterate over enabled flag values. - #[inline] - pub const fn iter(&self) -> $crate::iter::Iter<$PublicBitFlags> { - $crate::iter::Iter::__private_const_new(<$PublicBitFlags as $crate::Flags>::FLAGS, $PublicBitFlags::from_bits_retain(self.0), $PublicBitFlags::from_bits_retain(self.0)) - } - - /// Iterate over enabled flag values with their stringified names. - #[inline] - pub const fn iter_names(&self) -> $crate::iter::IterNames<$PublicBitFlags> { - $crate::iter::IterNames::__private_const_new(<$PublicBitFlags as $crate::Flags>::FLAGS, $PublicBitFlags::from_bits_retain(self.0), $PublicBitFlags::from_bits_retain(self.0)) - } } }; } diff --git a/src/lib.rs b/src/lib.rs index ab278406..9a0059f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -590,7 +590,8 @@ macro_rules! bitflags { unused_attributes, unused_mut, unused_imports, - non_upper_case_globals + non_upper_case_globals, + clippy::assign_op_pattern )] const _: () = { // Declared in a "hidden" scope that can't be reached directly @@ -610,7 +611,7 @@ macro_rules! bitflags { // This is where new library trait implementations can be added __impl_external_bitflags! { - InternalBitFlags: $T { + InternalBitFlags: $T, $BitFlags { $( $(#[$inner $($args)*])* $Flag; @@ -623,7 +624,7 @@ macro_rules! bitflags { } __impl_public_bitflags_iter! { - $BitFlags + $BitFlags: $T, $BitFlags } }; @@ -657,11 +658,12 @@ macro_rules! bitflags { unused_attributes, unused_mut, unused_imports, - non_upper_case_globals + non_upper_case_globals, + clippy::assign_op_pattern )] const _: () = { __impl_public_bitflags! { - $BitFlags: $T { + $BitFlags: $T, $BitFlags { $( $(#[$inner $($args)*])* $Flag; @@ -670,7 +672,7 @@ macro_rules! bitflags { } __impl_public_bitflags_iter! { - $BitFlags + $BitFlags: $T, $BitFlags } }; diff --git a/src/public.rs b/src/public.rs index d650fc43..57ab0ea8 100644 --- a/src/public.rs +++ b/src/public.rs @@ -57,7 +57,7 @@ macro_rules! __impl_public_bitflags_forward { Self($InternalBitFlags::from_bits_retain(bits)) } - fn from_name(name){ + fn from_name(name) { match $InternalBitFlags::from_name(name) { $crate::__private::core::option::Option::Some(bits) => $crate::__private::core::option::Option::Some(Self(bits)), $crate::__private::core::option::Option::None => $crate::__private::core::option::Option::None, @@ -130,7 +130,7 @@ macro_rules! __impl_public_bitflags_forward { #[doc(hidden)] macro_rules! __impl_public_bitflags { ( - $PublicBitFlags:ident: $T:ty { + $BitFlags:ident: $T:ty, $PublicBitFlags:ident { $( $(#[$attr:ident $($args:tt)*])* $Flag:ident; @@ -138,7 +138,7 @@ macro_rules! __impl_public_bitflags { } ) => { __impl_bitflags! { - $PublicBitFlags: $T { + $BitFlags: $T { fn empty() { Self(<$T as $crate::Bits>::EMPTY) } @@ -260,7 +260,7 @@ macro_rules! __impl_public_bitflags { } } - __impl_public_bitflags_ops!($PublicBitFlags); + __impl_public_bitflags_ops!($BitFlags); }; } @@ -268,8 +268,8 @@ macro_rules! __impl_public_bitflags { #[macro_export(local_inner_macros)] #[doc(hidden)] macro_rules! __impl_public_bitflags_iter { - ($PublicBitFlags:ident) => { - impl $PublicBitFlags { + ($BitFlags:ident: $T:ty, $PublicBitFlags:ident) => { + impl $BitFlags { /// Iterate over enabled flag values. #[inline] pub const fn iter(&self) -> $crate::iter::Iter<$PublicBitFlags> { @@ -283,8 +283,8 @@ macro_rules! __impl_public_bitflags_iter { } } - impl $crate::__private::core::iter::IntoIterator for $PublicBitFlags { - type Item = Self; + impl $crate::__private::core::iter::IntoIterator for $BitFlags { + type Item = $PublicBitFlags; type IntoIter = $crate::iter::Iter<$PublicBitFlags>; fn into_iter(self) -> Self::IntoIter {
diff --git a/tests/compile-fail/bitflags_custom_bits.rs b/tests/compile-fail/bitflags_custom_bits.rs index 46fde469..b719de4f 100644 --- a/tests/compile-fail/bitflags_custom_bits.rs +++ b/tests/compile-fail/bitflags_custom_bits.rs @@ -19,7 +19,7 @@ use std::{ }, }; -use bitflags::{bitflags, Bits, parser::{ParseError, FromHex}}; +use bitflags::{bitflags, Bits, parser::{ParseError, WriteHex, ParseHex}}; // Ideally we'd actually want this to work, but currently need something like `num`'s `Zero` // With some design work it could be made possible @@ -117,12 +117,18 @@ impl Binary for MyInt { } } -impl FromHex for MyInt { - fn from_hex(input: &str) -> Result<Self, ParseError> { +impl ParseHex for MyInt { + fn parse_hex(input: &str) -> Result<Self, ParseError> { Ok(MyInt(u8::from_str_radix(input, 16).map_err(|_| ParseError::invalid_hex_flag(input))?)) } } +impl WriteHex for MyInt { + fn write_hex<W: fmt::Write>(&self, writer: W) -> fmt::Result { + LowerHex::fmt(&self.0, writer) + } +} + bitflags! { struct Flags128: MyInt { const A = MyInt(0b0000_0001u8); diff --git a/tests/compile-fail/bitflags_custom_bits.stderr b/tests/compile-fail/bitflags_custom_bits.stderr index c74c27f0..86e0392b 100644 --- a/tests/compile-fail/bitflags_custom_bits.stderr +++ b/tests/compile-fail/bitflags_custom_bits.stderr @@ -1,7 +1,7 @@ error[E0277]: the trait bound `MyInt: bitflags::traits::Primitive` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:127:22 + --> tests/compile-fail/bitflags_custom_bits.rs:133:22 | -127 | struct Flags128: MyInt { +133 | struct Flags128: MyInt { | ^^^^^ the trait `bitflags::traits::Primitive` is not implemented for `MyInt` | = help: the following other types implement trait `bitflags::traits::Primitive`: @@ -20,442 +20,457 @@ note: required by a bound in `PublicFlags::Primitive` | type Primitive: Primitive; | ^^^^^^^^^ required by this bound in `PublicFlags::Primitive` +error[E0308]: mismatched types + --> tests/compile-fail/bitflags_custom_bits.rs:128:32 + | +127 | fn write_hex<W: fmt::Write>(&self, writer: W) -> fmt::Result { + | - this type parameter +128 | LowerHex::fmt(&self.0, writer) + | ------------- ^^^^^^ expected `&mut Formatter<'_>`, found type parameter `W` + | | + | arguments to this function are incorrect + | + = note: expected mutable reference `&mut Formatter<'_>` + found type parameter `W` +note: method defined here + --> $RUST/core/src/fmt/mod.rs + error[E0277]: can't compare `MyInt` with `_` in const contexts - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt == _` | = help: the trait `~const PartialEq<_>` is not implemented for `MyInt` note: the trait `PartialEq<_>` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: can't compare `MyInt` with `_` in const contexts - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt == _` | = help: the trait `~const PartialEq<_>` is not implemented for `MyInt` note: the trait `PartialEq<_>` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitAnd` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt & MyInt` | = help: the trait `~const BitAnd` is not implemented for `MyInt` note: the trait `BitAnd` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: can't compare `MyInt` with `_` in const contexts - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt == _` | = help: the trait `~const PartialEq<_>` is not implemented for `MyInt` note: the trait `PartialEq<_>` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitOr` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt | MyInt` | = help: the trait `~const BitOr` is not implemented for `MyInt` note: the trait `BitOr` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: can't compare `MyInt` with `_` in const contexts - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt == _` | = help: the trait `~const PartialEq<_>` is not implemented for `MyInt` note: the trait `PartialEq<_>` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitOr` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt | MyInt` | = help: the trait `~const BitOr` is not implemented for `MyInt` note: the trait `BitOr` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: can't compare `MyInt` with `_` in const contexts - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt == _` | = help: the trait `~const PartialEq<_>` is not implemented for `MyInt` note: the trait `PartialEq<_>` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitAnd` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt & MyInt` | = help: the trait `~const BitAnd` is not implemented for `MyInt` note: the trait `BitAnd` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitAnd` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt & MyInt` | = help: the trait `~const BitAnd` is not implemented for `MyInt` note: the trait `BitAnd` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: can't compare `MyInt` with `_` in const contexts - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt == _` | = help: the trait `~const PartialEq<_>` is not implemented for `MyInt` note: the trait `PartialEq<_>` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitAnd` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt & MyInt` | = help: the trait `~const BitAnd` is not implemented for `MyInt` note: the trait `BitAnd` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitOr` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt | MyInt` | = help: the trait `~const BitOr` is not implemented for `MyInt` note: the trait `BitOr` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitAnd` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt & MyInt` | = help: the trait `~const BitAnd` is not implemented for `MyInt` note: the trait `BitAnd` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: Not` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ the trait `~const Not` is not implemented for `MyInt` | note: the trait `Not` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: BitXor` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ no implementation for `MyInt ^ MyInt` | = help: the trait `~const BitXor` is not implemented for `MyInt` note: the trait `BitXor` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MyInt: Not` is not satisfied - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ the trait `~const Not` is not implemented for `MyInt` | note: the trait `Not` is implemented for `MyInt`, but that implementation is not `const` - --> tests/compile-fail/bitflags_custom_bits.rs:126:1 - | -126 | / bitflags! { -127 | | struct Flags128: MyInt { -128 | | const A = MyInt(0b0000_0001u8); -129 | | const B = MyInt(0b0000_0010u8); -130 | | const C = MyInt(0b0000_0100u8); -131 | | } -132 | | } + --> tests/compile-fail/bitflags_custom_bits.rs:132:1 + | +132 | / bitflags! { +133 | | struct Flags128: MyInt { +134 | | const A = MyInt(0b0000_0001u8); +135 | | const B = MyInt(0b0000_0010u8); +136 | | const C = MyInt(0b0000_0100u8); +137 | | } +138 | | } | |_^ = note: this error originates in the macro `__impl_public_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/compile-pass/bitflags_self_in_value.rs b/tests/compile-pass/bitflags_self_in_value.rs new file mode 100644 index 00000000..2a9a4a56 --- /dev/null +++ b/tests/compile-pass/bitflags_self_in_value.rs @@ -0,0 +1,15 @@ +use bitflags::bitflags; + +bitflags! { + pub struct Flags: u32 { + const SOME_FLAG = 1 << Self::SOME_FLAG_SHIFT; + } +} + +impl Flags { + const SOME_FLAG_SHIFT: u32 = 5; +} + +fn main() { + +} diff --git a/tests/smoke-test/src/main.rs b/tests/smoke-test/src/main.rs index 9ff4305d..6f84ff33 100644 --- a/tests/smoke-test/src/main.rs +++ b/tests/smoke-test/src/main.rs @@ -1,3 +1,5 @@ +#![deny(warnings)] + use bitflags::bitflags; bitflags! {
Clippy warnings around "manual implementation of an assign operation" Hi. I've run into a new clippy lint warnings such as the following: > manual implementation of an assign operation > for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern > `#[warn(clippy::assign_op_pattern)]` on by default I'm following the example from the docs page for the use of the macro (more or less, as below). Can you enlighten me as to why this lint notification is appearing here and if there is some way to fix it? I know I can silence the warnings, it's just annoying to see it pop up whenever I run into it. ```rust bitflags! { pub struct MemoryAccess: u8 { /// None. const N = 1 << 0; /// Public read. const R = 1 << 1; /// Public write. const W = 1 << 2; /// Private read. const PR = 1 << 3; /// Private write. const PW = 1 << 4; /// Execute. const EX = 1 << 5; } } ``` Thanks!
2023-05-17T11:22:15Z
2.3
[ "tests/compile-pass/bitflags_self_in_value.rs" ]
[ "tests::bits_types", "tests::into_iter_from_iter_roundtrip", "tests::submodule::test_private", "tests::test_assignment_operators", "tests::test_binary", "tests::test_bits", "tests::test_const_fn", "tests::test_contains", "tests::test_debug", "tests::test_deprecated", "tests::test_display_from_str_roundtrip", "tests::test_empty_does_not_intersect_with_full", "tests::test_empty_bitflags", "tests::test_default", "tests::test_from_bits_retain", "tests::test_from_bits_truncate", "tests::test_from_bits_truncate_edge_cases", "tests::test_from_iterator", "tests::test_from_name", "tests::test_from_str_err", "tests::test_hash", "tests::test_in_function", "tests::test_insert", "tests::test_is_all", "tests::test_is_empty", "tests::test_extend", "tests::test_from_bits_edge_cases", "tests::test_iter", "tests::test_from_bits", "tests::test_lt", "tests::test_lowerhex", "tests::test_octal", "tests::test_disjoint_intersects", "tests::test_operators", "tests::test_ord", "tests::test_overlapping_intersects", "tests::test_pub_crate", "tests::test_pub_in_module", "tests::test_public", "tests::test_set", "tests::test_remove", "tests::test_set_ops_basic", "tests::test_operators_unchecked", "tests::test_set_ops_const", "tests::test_upperhex", "tests::test_u128_bitflags", "tests::test_zero_value_flags", "tests::test_set_ops_unchecked", "tests::test_two_empties_do_not_intersect", "tests::test_set_ops_exhaustive", "basic", "tests/compile-pass/bitflags_nested_value.rs", "tests/compile-pass/bitflags_redefined_value.rs", "tests/compile-pass/bitflags_trait_bound_flags.rs", "tests/compile-pass/bitflags_trait_generic_iter.rs", "tests/compile-pass/bitflags_trait_precedence.rs", "tests/compile-pass/bitflags_trait_supertrait.rs", "tests/compile-pass/bitflags_trait_to_flags.rs", "tests/compile-pass/bitflags_visibility.rs", "tests/compile-pass/deprecated.rs", "tests/compile-pass/doc_alias.rs", "tests/compile-pass/flags_trait_bound_bitflags.rs", "tests/compile-pass/flags_trait_generic_iter.rs", "tests/compile-pass/flags_trait_precedence.rs", "tests/compile-pass/flags_trait_supertrait.rs", "tests/compile-pass/impl_convert_from_bits.rs", "tests/compile-pass/impl_copy.rs", "tests/compile-pass/impl_default.rs", "tests/compile-pass/impl_eq.rs", "tests/compile-pass/impl_fmt.rs", "tests/compile-pass/impl_new.rs", "tests/compile-pass/into_iter_trait_wrapped.rs", "tests/compile-pass/item_positions.rs", "tests/compile-pass/large.rs", "tests/compile-pass/no_prelude.rs", "tests/compile-pass/non_snake_case.rs", "tests/compile-pass/path_based_bits.rs", "tests/compile-pass/repr_c.rs", "tests/compile-pass/repr_transparent.rs", "tests/compile-pass/shadow_core.rs", "tests/compile-pass/shadow_macros.rs" ]
[]
[]
bitflags/bitflags
351
bitflags__bitflags-351
[ "348" ]
1d8388bf4ce18afde846d220ad8b6e0dc40aae94
"diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml\nindex a32e1d55..6ebd5a74 1006(...TRUNCATED)
"diff --git a/tests/compile-fail/visibility/private_flags.rs b/tests/compile-fail/access_outside_vis(...TRUNCATED)
"Allow external impls of Bits and BitFlags\nThe `BitFlags` trait is currently sealed, and is only su(...TRUNCATED)
"As for `Bits`, it can be reasonably reduced to:\r\n\r\n```rust\r\npub trait Bits:\r\n Clone\r\n (...TRUNCATED)
2023-05-04T06:16:51Z
2.2
["tests/compile-pass/bitflags_trait_bound_flags.rs","tests/compile-pass/bitflags_trait_to_flags.rs",(...TRUNCATED)
["tests::bits_types","tests::submodule::test_private","tests::test_assignment_operators","tests::tes(...TRUNCATED)
[]
[]
bitflags/bitflags
345
bitflags__bitflags-345
[ "344" ]
cbcafa710fc31172511e62efa06ad9eb214e4734
"diff --git a/src/example_generated.rs b/src/example_generated.rs\nindex 9c1ba46a..b7589014 100644\n(...TRUNCATED)
"diff --git a/tests/compile-pass/large.rs b/tests/compile-pass/large.rs\nnew file mode 100644\nindex(...TRUNCATED)
"Bitflags reverses order of multiline doc comments\nWhen compiling code like\r\n```\r\nbitflags! {\r(...TRUNCATED)
"This should be trivially fixed by swapping the order attributes are \"pushed\" in `__declare_bitfla(...TRUNCATED)
2023-04-24T04:29:26Z
2.2
[ "tests/compile-pass/large.rs" ]
["tests::bits_types","tests::into_iter_from_iter_roundtrip","tests::submodule::test_private","tests:(...TRUNCATED)
[]
[]
bitflags/bitflags
341
bitflags__bitflags-341
[ "308" ]
dc971042c8132a5381ab3e2165983ee7f9d44c63
"diff --git a/src/lib.rs b/src/lib.rs\nindex 7ba784c5..a4a40467 100644\n--- a/src/lib.rs\n+++ b/src/(...TRUNCATED)
"diff --git a/tests/compile-pass/doc_alias.rs b/tests/compile-pass/doc_alias.rs\nnew file mode 10064(...TRUNCATED)
"Cannot use `#[doc(alias)]`\nThe following code:\r\n```rs\r\nbitflags::bitflags! {\r\n #[doc(alias (...TRUNCATED)
"This is a general problem for attributes that can't be applied to expressions now. In methods like (...TRUNCATED)
2023-04-18T00:36:26Z
2.1
[ "tests/compile-pass/doc_alias.rs" ]
["tests::bits_types","tests::into_iter_from_iter_roundtrip","tests::submodule::test_private","tests:(...TRUNCATED)
[]
[]
bitflags/bitflags
281
bitflags__bitflags-281
[ "215" ]
f38ce72d11ef3e264d4b62f360bd8a5597b916d9
"diff --git a/src/bitflags_trait.rs b/src/bitflags_trait.rs\nindex 0ffee465..440d5274 100644\n--- a/(...TRUNCATED)
"diff --git a/tests/compile-fail/cfg/multi.stderr b/tests/compile-fail/cfg/multi.stderr\ndeleted fil(...TRUNCATED)
"Debug formatting leads to less desireable output\n[Link to rust playground](https://play.rust-lang.(...TRUNCATED)
"I think the current algorithm used for debug output is to loop over all flags and append identifier(...TRUNCATED)
2022-05-03T06:59:46Z
1.3
["tests/compile-pass/cfg/redefined-value.rs","tests/compile-pass/deprecated.rs","tests/compile-pass/(...TRUNCATED)
["tests::test_assignment_operators","tests::submodule::test_private","tests::test_binary","tests::te(...TRUNCATED)
[]
[]
bitflags/bitflags
268
bitflags__bitflags-268
[ "267" ]
1aa25e1b3baf35d3d3840f12fe7e8b55adc0164a
"diff --git a/src/lib.rs b/src/lib.rs\nindex 617afea0..b24fb40b 100644\n--- a/src/lib.rs\n+++ b/src/(...TRUNCATED)
"diff --git a/tests/compile-fail/trait/custom_impl.rs b/tests/compile-fail/trait/custom_impl.rs\nind(...TRUNCATED)
"Bug: debug pretty-printing unknown flags display 0x0x\nmain.rs\r\n```rust\r\nuse bitflags::bitflags(...TRUNCATED)
2022-01-02T17:22:14Z
1.3
[ "tests/compile-pass/impls/fmt.rs" ]
["tests::submodule::test_private","tests::test_assignment_operators","tests::test_binary","tests::te(...TRUNCATED)
[]
[]
bitflags/bitflags
266
bitflags__bitflags-266
[ "265" ]
1aa25e1b3baf35d3d3840f12fe7e8b55adc0164a
"diff --git a/src/lib.rs b/src/lib.rs\nindex 617afea0..a4ca8429 100644\n--- a/src/lib.rs\n+++ b/src/(...TRUNCATED)
"diff --git a/tests/compile-pass/redefinition/result.rs b/tests/compile-pass/redefinition/result.rs\(...TRUNCATED)
"The bitflags macro is not sanitary wrt. standard library types and enumerations\nThe `bitflags` mac(...TRUNCATED)
2021-12-16T09:38:14Z
1.3
[ "tests/compile-pass/redefinition/result.rs" ]
["tests::submodule::test_private","tests::test_assignment_operators","tests::test_binary","tests::te(...TRUNCATED)
[]
[]
README.md exists but content is empty.
Downloads last month
2