Repository: bitflags/bitflags (Rust)

Issue:
bitflags 2.3.0 breaks flags that refer to constants in separate impl blocks via `Self`
Hi!

The short of it is that the code below compiles with bitflags 2.2.1 but fails to compile with bitflags 2.3.0. 
```rust
use bitflags::bitflags;

bitflags! {
    pub struct Flags: u32 {
        const SOME_FLAG = 1 << Self::SOME_FLAG_SHIFT;
    }
}

impl Flags {
    const SOME_FLAG_SHIFT: u32 = 5;
}
```

<details>
<summary>The error message emitted by rustc, in case it helps.</summary>

```
error[E0599]: no associated item named `SOME_FLAG_SHIFT` found for struct `InternalBitFlags` in the current scope
 --> src/lib.rs:5:38
  |
3 | / bitflags! {
4 | |     pub struct Flags: u32 {
5 | |         const SOME_FLAG = 1 << Self::SOME_FLAG_SHIFT;
  | |                                      ^^^^^^^^^^^^^^^
  | |                                      |
  | |                                      associated item not found in `InternalBitFlags`
  | |                                      help: there is an associated constant with a similar name: `SOME_FLAG`
6 | |     }
7 | | }
  | |_- associated item `SOME_FLAG_SHIFT` not found for this struct

For more information about this error, try `rustc --explain E0599`.
error: could not compile `bitflags-regression` (lib) due to previous error
```

</details>

I'm not sure how niche this pattern is but it did break the `perf-event-data` crate.
Clippy Lint Failures
The latest version of bitflags v2.3.0 appears to generate code that clippy complains about.

In particular https://rust-lang.github.io/rust-clippy/master/index.html#assign_op_pattern

I have worked around this in our project, but this feels like something that should probably be fixed upstream
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!


Discussion:
Thanks for the report @Phantomical! This looks like a regression in that we now add flags to both the overall type and the internally generated one, so `Self` refers to a different type in those cases. We should fix that up by not implementing the `Flags` trait on that internally generated type and working around any places we expect it.

Relevant workaround is https://github.com/apache/arrow-rs/pull/4233
❤️  thank you @KodrAus !
I've added `clippy` to our CI now so we should be far less likely to trigger these lints in releases in the future 🙏

Believe it or not I did search first, that didn't come up. Seems like I was searching for the wrong thing there.

Diolch.
We have some rather ad-hoc treatment of lints and warnings that `bitflags`'s own code may generate. I've (finally) added a `clippy` step to our CI so we should stop triggering lints in your code so regularly 😅 



Patch:
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 {


Test patch:
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! {