Merge pull request #247 from konsumlamm/fix-core

Fix regression & simplify tests
This commit is contained in:
Ashley Mannix 2021-08-04 08:47:38 +10:00 committed by GitHub
commit 195bf052e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 53 additions and 79 deletions

View File

@ -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

View File

@ -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"]

View File

@ -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

View File

@ -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"

View File

@ -1,5 +1,5 @@
mod example {
use bitflags::bitflags
use bitflags::bitflags;
bitflags! {
pub struct Flags1: u32 {

9
tests/redefine_core.rs Normal file
View File

@ -0,0 +1,9 @@
use bitflags::bitflags;
// ensure that no naming conflicts happen
mod core {}
mod _core {}
bitflags! {
struct Test: u8 {}
}

View File

@ -1,5 +1,3 @@
#![cfg(feature = "unstable")]
use bitflags::bitflags;
bitflags! {