Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression & simplify tests #247

Merged
merged 2 commits into from Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/rust.yml
Expand Up @@ -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
18 changes: 9 additions & 9 deletions 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"]
Expand All @@ -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"]
65 changes: 34 additions & 31 deletions src/lib.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
//
Expand Down Expand Up @@ -448,32 +451,32 @@ 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)")?;
}
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)
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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.
Expand All @@ -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]
Expand All @@ -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.
Expand All @@ -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]
Expand All @@ -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.
Expand All @@ -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]
Expand All @@ -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.
Expand All @@ -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]
Expand All @@ -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.
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions test_suite/Cargo.toml

This file was deleted.

@@ -1,5 +1,5 @@
mod example {
use bitflags::bitflags
use bitflags::bitflags;

bitflags! {
pub struct Flags1: u32 {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions 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 {}
}
File renamed without changes.
2 changes: 0 additions & 2 deletions test_suite/tests/u128_bitflags.rs → tests/u128_bitflags.rs
@@ -1,5 +1,3 @@
#![cfg(feature = "unstable")]

use bitflags::bitflags;

bitflags! {
Expand Down