Repository: bitflags/bitflags
Pull request #247 (2021-07-19 17:45:36)

Fix regression & simplify tests
This fixes a regression introduced in #246 (see https://github.com/bitflags/bitflags/pull/246#discussion_r672290205), by reverting the specific change, along with adding a test case.

I also took the opportunity to move the tests in `test_suite` back into the crate tests (instead of having a workspace with a `test_suite` crate). AFAICT, this happened because it needed extra features that shouldn't leak, but that isn't the case anymore. This makes it easier to run the tests (just `cargo test` in the main directory).

I also removed `appveyor.yml` from the `exclude` list in `Cargo.toml`, I'm not sure why it was there in the first place though.


Patch:
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 2bb37c1..ffe0eda 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -54,28 +54,3 @@ jobs:
         with:
           command: build
           args: -Z avoid-dev-deps --features example_generated --target thumbv6m-none-eabi
-
-  suite:
-    name: Test suite
-    runs-on: ubuntu-latest
-    strategy:
-      fail-fast: true
-      matrix:
-        rust:
-          - nightly
-    steps:
-      - name: Checkout sources
-        uses: actions/checkout@v2
-
-      - name: Install Rust toolchain
-        uses: actions-rs/toolchain@v1
-        with:
-          profile: minimal
-          toolchain: ${{ matrix.rust }}
-          override: true
-
-      - name: Default features
-        uses: actions-rs/cargo@v1
-        with:
-          command: test
-          args: -p test_suite
\ No newline at end of file
diff --git a/Cargo.toml b/Cargo.toml
index c6e8c9e..44d0f19 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,10 +1,10 @@
 [package]
-
 name = "bitflags"
 # NB: When modifying, also modify:
 #   1. html_root_url in lib.rs
 #   2. number in readme (for breaking changes)
 version = "1.2.1"
+edition = "2018"
 authors = ["The Rust Project Developers"]
 license = "MIT/Apache-2.0"
 keywords = ["bit", "bitmask", "bitflags", "flags"]
@@ -16,22 +16,22 @@ categories = ["no-std"]
 description = """
 A macro to generate structures which behave like bitflags.
 """
-exclude = [
-    "appveyor.yml",
-    "bors.toml"
-]
+exclude = ["bors.toml"]
 
 [dependencies]
 core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' }
 compiler_builtins = { version = '0.1.2', optional = true }
 
+[dev-dependencies]
+trybuild = "1.0"
+serde = "1.0"
+serde_derive = "1.0"
+serde_json = "1.0"
+
 [features]
 default = []
 example_generated = []
 rustc-dep-of-std = ["core", "compiler_builtins"]
 
 [package.metadata.docs.rs]
-features = [ "example_generated" ]
-
-[workspace]
-members = ["test_suite"]
+features = ["example_generated"]
diff --git a/src/lib.rs b/src/lib.rs
index fbbac76..1070afd 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -246,6 +246,9 @@
 #![cfg_attr(not(test), no_std)]
 #![doc(html_root_url = "https://docs.rs/bitflags/1.2.1")]
 
+#[doc(hidden)]
+pub extern crate core as _core;
+
 /// The macro used to generate the flag structures.
 ///
 /// See the [crate level docs](../bitflags/index.html) for complete documentation.
@@ -394,8 +397,8 @@ macro_rules! __impl_bitflags {
             )*
         }
     ) => {
-        impl core::fmt::Debug for $BitFlags {
-            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
+        impl $crate::_core::fmt::Debug for $BitFlags {
+            fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
                 // This convoluted approach is to handle #[cfg]-based flag
                 // omission correctly. For example it needs to support:
                 //
@@ -448,7 +451,7 @@ macro_rules! __impl_bitflags {
                     }
                     first = false;
                     f.write_str("0x")?;
-                    core::fmt::LowerHex::fmt(&extra_bits, f)?;
+                    $crate::_core::fmt::LowerHex::fmt(&extra_bits, f)?;
                 }
                 if first {
                     f.write_str("(empty)")?;
@@ -456,24 +459,24 @@ macro_rules! __impl_bitflags {
                 Ok(())
             }
         }
-        impl core::fmt::Binary for $BitFlags {
-            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
-                core::fmt::Binary::fmt(&self.bits, f)
+        impl $crate::_core::fmt::Binary for $BitFlags {
+            fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
+                $crate::_core::fmt::Binary::fmt(&self.bits, f)
             }
         }
-        impl core::fmt::Octal for $BitFlags {
-            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
-                core::fmt::Octal::fmt(&self.bits, f)
+        impl $crate::_core::fmt::Octal for $BitFlags {
+            fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
+                $crate::_core::fmt::Octal::fmt(&self.bits, f)
             }
         }
-        impl core::fmt::LowerHex for $BitFlags {
-            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
-                core::fmt::LowerHex::fmt(&self.bits, f)
+        impl $crate::_core::fmt::LowerHex for $BitFlags {
+            fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
+                $crate::_core::fmt::LowerHex::fmt(&self.bits, f)
             }
         }
-        impl core::fmt::UpperHex for $BitFlags {
-            fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
-                core::fmt::UpperHex::fmt(&self.bits, f)
+        impl $crate::_core::fmt::UpperHex for $BitFlags {
+            fn fmt(&self, f: &mut $crate::_core::fmt::Formatter) -> $crate::_core::fmt::Result {
+                $crate::_core::fmt::UpperHex::fmt(&self.bits, f)
             }
         }
 
@@ -512,11 +515,11 @@ macro_rules! __impl_bitflags {
             /// Convert from underlying bit representation, unless that
             /// representation contains bits that do not correspond to a flag.
             #[inline]
-            pub const fn from_bits(bits: $T) -> core::option::Option<$BitFlags> {
+            pub const fn from_bits(bits: $T) -> $crate::_core::option::Option<$BitFlags> {
                 if (bits & !$BitFlags::all().bits()) == 0 {
-                    core::option::Option::Some($BitFlags { bits })
+                    $crate::_core::option::Option::Some($BitFlags { bits })
                 } else {
-                    core::option::Option::None
+                    $crate::_core::option::Option::None
                 }
             }
 
@@ -596,7 +599,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::BitOr for $BitFlags {
+        impl $crate::_core::ops::BitOr for $BitFlags {
             type Output = $BitFlags;
 
             /// Returns the union of the two sets of flags.
@@ -606,7 +609,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::BitOrAssign for $BitFlags {
+        impl $crate::_core::ops::BitOrAssign for $BitFlags {
 
             /// Adds the set of flags.
             #[inline]
@@ -615,7 +618,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::BitXor for $BitFlags {
+        impl $crate::_core::ops::BitXor for $BitFlags {
             type Output = $BitFlags;
 
             /// Returns the left flags, but with all the right flags toggled.
@@ -625,7 +628,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::BitXorAssign for $BitFlags {
+        impl $crate::_core::ops::BitXorAssign for $BitFlags {
 
             /// Toggles the set of flags.
             #[inline]
@@ -634,7 +637,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::BitAnd for $BitFlags {
+        impl $crate::_core::ops::BitAnd for $BitFlags {
             type Output = $BitFlags;
 
             /// Returns the intersection between the two sets of flags.
@@ -644,7 +647,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::BitAndAssign for $BitFlags {
+        impl $crate::_core::ops::BitAndAssign for $BitFlags {
 
             /// Disables all flags disabled in the set.
             #[inline]
@@ -653,7 +656,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::Sub for $BitFlags {
+        impl $crate::_core::ops::Sub for $BitFlags {
             type Output = $BitFlags;
 
             /// Returns the set difference of the two sets of flags.
@@ -663,7 +666,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::SubAssign for $BitFlags {
+        impl $crate::_core::ops::SubAssign for $BitFlags {
 
             /// Disables all flags enabled in the set.
             #[inline]
@@ -672,7 +675,7 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::ops::Not for $BitFlags {
+        impl $crate::_core::ops::Not for $BitFlags {
             type Output = $BitFlags;
 
             /// Returns the complement of this set of flags.
@@ -682,16 +685,16 @@ macro_rules! __impl_bitflags {
             }
         }
 
-        impl core::iter::Extend<$BitFlags> for $BitFlags {
-            fn extend<T: core::iter::IntoIterator<Item=$BitFlags>>(&mut self, iterator: T) {
+        impl $crate::_core::iter::Extend<$BitFlags> for $BitFlags {
+            fn extend<T: $crate::_core::iter::IntoIterator<Item=$BitFlags>>(&mut self, iterator: T) {
                 for item in iterator {
                     self.insert(item)
                 }
             }
         }
 
-        impl core::iter::FromIterator<$BitFlags> for $BitFlags {
-            fn from_iter<T: core::iter::IntoIterator<Item=$BitFlags>>(iterator: T) -> $BitFlags {
+        impl $crate::_core::iter::FromIterator<$BitFlags> for $BitFlags {
+            fn from_iter<T: $crate::_core::iter::IntoIterator<Item=$BitFlags>>(iterator: T) -> $BitFlags {
                 let mut result = Self::empty();
                 result.extend(iterator);
                 result


Test patch:
diff --git a/test_suite/Cargo.toml b/test_suite/Cargo.toml
deleted file mode 100644
index ac459d5..0000000
--- a/test_suite/Cargo.toml
+++ /dev/null
@@ -1,11 +0,0 @@
-[project]
-name = "test_suite"
-version = "0.0.0"
-edition = "2018"
-
-[dependencies]
-bitflags = { path = "../" }
-trybuild = "1.0"
-serde = "1.0"
-serde_derive = "1.0"
-serde_json = "1.0"
diff --git a/test_suite/tests/compile-fail/private_flags.rs b/tests/compile-fail/private_flags.rs
similarity index 91%
rename from test_suite/tests/compile-fail/private_flags.rs
rename to tests/compile-fail/private_flags.rs
index b542cb1..85a5b18 100644
--- a/test_suite/tests/compile-fail/private_flags.rs
+++ b/tests/compile-fail/private_flags.rs
@@ -1,5 +1,5 @@
 mod example {
-    use bitflags::bitflags
+    use bitflags::bitflags;
 
     bitflags! {
         pub struct Flags1: u32 {
diff --git a/test_suite/tests/compiletest.rs b/tests/compiletest.rs
similarity index 100%
rename from test_suite/tests/compiletest.rs
rename to tests/compiletest.rs
diff --git a/test_suite/tests/conflicting_trait_impls.rs b/tests/conflicting_trait_impls.rs
similarity index 100%
rename from test_suite/tests/conflicting_trait_impls.rs
rename to tests/conflicting_trait_impls.rs
diff --git a/test_suite/tests/external.rs b/tests/external.rs
similarity index 100%
rename from test_suite/tests/external.rs
rename to tests/external.rs
diff --git a/test_suite/tests/external_no_std.rs b/tests/external_no_std.rs
similarity index 100%
rename from test_suite/tests/external_no_std.rs
rename to tests/external_no_std.rs
diff --git a/tests/redefine_core.rs b/tests/redefine_core.rs
new file mode 100644
index 0000000..12685f5
--- /dev/null
+++ b/tests/redefine_core.rs
@@ -0,0 +1,9 @@
+use bitflags::bitflags;
+
+// ensure that no naming conflicts happen
+mod core {}
+mod _core {}
+
+bitflags! {
+    struct Test: u8 {}
+}
diff --git a/test_suite/tests/serde.rs b/tests/serde.rs
similarity index 100%
rename from test_suite/tests/serde.rs
rename to tests/serde.rs
diff --git a/test_suite/tests/u128_bitflags.rs b/tests/u128_bitflags.rs
similarity index 96%
rename from test_suite/tests/u128_bitflags.rs
rename to tests/u128_bitflags.rs
index 8ed1546..7501db7 100644
--- a/test_suite/tests/u128_bitflags.rs
+++ b/tests/u128_bitflags.rs
@@ -1,5 +1,3 @@
-#![cfg(feature = "unstable")]
-
 use bitflags::bitflags;
 
 bitflags! {