From 5e79588a0940417edcadf44c8675e889224c6769 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 16 May 2021 16:00:43 +1000 Subject: [PATCH 1/3] update MSRV based on current impl --- .github/workflows/rust.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a7042f5a..5e69670d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,7 +16,7 @@ jobs: - stable - beta - nightly - - 1.32.0 + - 1.45.0 steps: - name: Checkout sources uses: actions/checkout@v2 diff --git a/README.md b/README.md index f447afbf..9eb9a3ee 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,4 @@ extern crate bitflags; ## Rust Version Support -The minimum supported Rust version is 1.20 due to use of associated constants. +The minimum supported Rust version is 1.45 due to use of associated constants and const functions. From afd25d317c0274ac74cbdaccc170c99cfc4e6723 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 16 May 2021 16:05:05 +1000 Subject: [PATCH 2/3] bump to 1.46.0 --- .github/workflows/rust.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 5e69670d..2bb37c1a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -16,7 +16,7 @@ jobs: - stable - beta - nightly - - 1.45.0 + - 1.46.0 steps: - name: Checkout sources uses: actions/checkout@v2 diff --git a/README.md b/README.md index 9eb9a3ee..486e4eca 100644 --- a/README.md +++ b/README.md @@ -30,4 +30,4 @@ extern crate bitflags; ## Rust Version Support -The minimum supported Rust version is 1.45 due to use of associated constants and const functions. +The minimum supported Rust version is 1.46 due to use of associated constants and const functions. From bbd5d4dfb4addabf8346105a2d257b9bfae8f14d Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Sun, 16 May 2021 20:08:13 +1000 Subject: [PATCH 3/3] remove unneeded infra and dependence on compiler msgs --- Cargo.toml | 1 - build.rs | 44 ---- src/lib.rs | 212 ++++++------------ .../tests/compile-fail/private_flags.stderr | 18 -- 4 files changed, 66 insertions(+), 209 deletions(-) delete mode 100644 build.rs delete mode 100644 test_suite/tests/compile-fail/private_flags.stderr diff --git a/Cargo.toml b/Cargo.toml index c3fdf183..c6e8c9e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ exclude = [ "appveyor.yml", "bors.toml" ] -build = "build.rs" [dependencies] core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' } diff --git a/build.rs b/build.rs deleted file mode 100644 index 67abc09d..00000000 --- a/build.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::env; -use std::process::Command; -use std::str::{self, FromStr}; - -fn main() { - let minor = match rustc_minor_version() { - Some(minor) => minor, - None => return, - }; - - // const fn stabilized in Rust 1.31: - if minor >= 31 { - println!("cargo:rustc-cfg=bitflags_const_fn"); - } -} - -fn rustc_minor_version() -> Option { - let rustc = match env::var_os("RUSTC") { - Some(rustc) => rustc, - None => return None, - }; - - let output = match Command::new(rustc).arg("--version").output() { - Ok(output) => output, - Err(_) => return None, - }; - - let version = match str::from_utf8(&output.stdout) { - Ok(version) => version, - Err(_) => return None, - }; - - let mut pieces = version.split('.'); - if pieces.next() != Some("rustc 1") { - return None; - } - - let next = match pieces.next() { - Some(next) => next, - None => return None, - }; - - u32::from_str(next).ok() -} diff --git a/src/lib.rs b/src/lib.rs index e3493600..9e5ac8dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -436,61 +436,7 @@ macro_rules! __bitflags { #[macro_export(local_inner_macros)] #[doc(hidden)] -#[cfg(bitflags_const_fn)] -macro_rules! __fn_bitflags { - ( - $(# $attr_args:tt)* - const fn $($item:tt)* - ) => { - $(# $attr_args)* - const fn $($item)* - }; - ( - $(# $attr_args:tt)* - pub const fn $($item:tt)* - ) => { - $(# $attr_args)* - pub const fn $($item)* - }; - ( - $(# $attr_args:tt)* - pub const unsafe fn $($item:tt)* - ) => { - $(# $attr_args)* - pub const unsafe fn $($item)* - }; -} - -#[macro_export(local_inner_macros)] -#[doc(hidden)] -#[cfg(not(bitflags_const_fn))] -macro_rules! __fn_bitflags { - ( - $(# $attr_args:tt)* - const fn $($item:tt)* - ) => { - $(# $attr_args)* - fn $($item)* - }; - ( - $(# $attr_args:tt)* - pub const fn $($item:tt)* - ) => { - $(# $attr_args)* - pub fn $($item)* - }; - ( - $(# $attr_args:tt)* - pub const unsafe fn $($item:tt)* - ) => { - $(# $attr_args)* - pub unsafe fn $($item)* - }; -} - -#[macro_export(local_inner_macros)] -#[doc(hidden)] -macro_rules! __all_bitflags { +macro_rules! __impl_all_bitflags { ( $BitFlags:ident: $T:ty { $( @@ -499,41 +445,28 @@ macro_rules! __all_bitflags { )+ } ) => { - __fn_bitflags! { - /// Returns the set containing all flags. - #[inline] - pub const fn all() -> $BitFlags { - // See `Debug::fmt` for why this approach is taken. - #[allow(non_snake_case)] - trait __BitFlags { - $( - const $Flag: $T = 0; - )+ - } - impl __BitFlags for $BitFlags { - $( - __impl_bitflags! { - #[allow(deprecated)] - $(? #[$attr $($args)*])* - const $Flag: $T = Self::$Flag.bits; - } - )+ + // See `Debug::fmt` for why this approach is taken. + #[allow(non_snake_case)] + trait __BitFlags { + $( + const $Flag: $T = 0; + )+ + } + impl __BitFlags for $BitFlags { + $( + __impl_bitflags! { + #[allow(deprecated)] + $(? #[$attr $($args)*])* + const $Flag: $T = Self::$Flag.bits; } - $BitFlags { bits: $(<$BitFlags as __BitFlags>::$Flag)|+ } - } + )+ } + $BitFlags { bits: $(<$BitFlags as __BitFlags>::$Flag)|+ } }; ( - $BitFlags:ident: $T:ty { - } + $BitFlags:ident: $T:ty { } ) => { - __fn_bitflags! { - /// Returns the set containing all flags. - #[inline] - pub const fn all() -> $BitFlags { - $BitFlags { bits: 0 } - } - } + $BitFlags { bits: 0 } }; } @@ -638,15 +571,16 @@ macro_rules! __impl_bitflags { pub const $Flag: $BitFlags = $BitFlags { bits: $value }; )* - __fn_bitflags! { - /// Returns an empty set of flags. - #[inline] - pub const fn empty() -> $BitFlags { - $BitFlags { bits: 0 } - } + /// Returns an empty set of flags. + #[inline] + pub const fn empty() -> $BitFlags { + $BitFlags { bits: 0 } } - __all_bitflags! { + /// Returns the set containing all flags. + #[inline] + pub const fn all() -> $BitFlags { + __impl_all_bitflags! { $BitFlags: $T { $( $(#[$attr $($args)*])* @@ -654,13 +588,12 @@ macro_rules! __impl_bitflags { )* } } + } - __fn_bitflags! { - /// Returns the raw value of the flags currently stored. - #[inline] - pub const fn bits(&self) -> $T { - self.bits - } + /// Returns the raw value of the flags currently stored. + #[inline] + pub const fn bits(&self) -> $T { + self.bits } /// Convert from underlying bit representation, unless that @@ -674,63 +607,51 @@ macro_rules! __impl_bitflags { } } - __fn_bitflags! { - /// Convert from underlying bit representation, dropping any bits - /// that do not correspond to flags. - #[inline] - pub const fn from_bits_truncate(bits: $T) -> $BitFlags { - $BitFlags { bits: bits & $BitFlags::all().bits } - } + /// Convert from underlying bit representation, dropping any bits + /// that do not correspond to flags. + #[inline] + pub const fn from_bits_truncate(bits: $T) -> $BitFlags { + $BitFlags { bits: bits & $BitFlags::all().bits } } - __fn_bitflags! { - /// Convert from underlying bit representation, preserving all - /// bits (even those not corresponding to a defined flag). - /// - /// # Safety - /// - /// The caller of the `bitflags!` macro can chose to allow or - /// disallow extra bits for their bitflags type. - /// - /// The caller of `from_bits_unchecked()` has to ensure that - /// all bits correspond to a defined flag or that extra bits - /// are valid for this bitflags type. - #[inline] - pub const unsafe fn from_bits_unchecked(bits: $T) -> $BitFlags { - $BitFlags { bits } - } + /// Convert from underlying bit representation, preserving all + /// bits (even those not corresponding to a defined flag). + /// + /// # Safety + /// + /// The caller of the `bitflags!` macro can chose to allow or + /// disallow extra bits for their bitflags type. + /// + /// The caller of `from_bits_unchecked()` has to ensure that + /// all bits correspond to a defined flag or that extra bits + /// are valid for this bitflags type. + #[inline] + pub const unsafe fn from_bits_unchecked(bits: $T) -> $BitFlags { + $BitFlags { bits } } - __fn_bitflags! { - /// Returns `true` if no flags are currently stored. - #[inline] - pub const fn is_empty(&self) -> bool { - self.bits() == $BitFlags::empty().bits() - } + /// Returns `true` if no flags are currently stored. + #[inline] + pub const fn is_empty(&self) -> bool { + self.bits() == $BitFlags::empty().bits() } - __fn_bitflags! { - /// Returns `true` if all flags are currently set. - #[inline] - pub const fn is_all(&self) -> bool { - $BitFlags::all().bits | self.bits == self.bits - } + /// Returns `true` if all flags are currently set. + #[inline] + pub const fn is_all(&self) -> bool { + $BitFlags::all().bits | self.bits == self.bits } - __fn_bitflags! { - /// Returns `true` if there are flags common to both `self` and `other`. - #[inline] - pub const fn intersects(&self, other: $BitFlags) -> bool { - !$BitFlags{ bits: self.bits & other.bits}.is_empty() - } + /// Returns `true` if there are flags common to both `self` and `other`. + #[inline] + pub const fn intersects(&self, other: $BitFlags) -> bool { + !$BitFlags{ bits: self.bits & other.bits}.is_empty() } - __fn_bitflags! { - /// Returns `true` all of the flags in `other` are contained within `self`. - #[inline] - pub const fn contains(&self, other: $BitFlags) -> bool { - (self.bits & other.bits) == other.bits - } + /// Returns `true` all of the flags in `other` are contained within `self`. + #[inline] + pub const fn contains(&self, other: $BitFlags) -> bool { + (self.bits & other.bits) == other.bits } /// Inserts the specified flags in-place. @@ -1262,7 +1183,6 @@ mod tests { assert_eq!(m1, e1); } - #[cfg(bitflags_const_fn)] #[test] fn test_const_fn() { const _M1: Flags = Flags::empty(); diff --git a/test_suite/tests/compile-fail/private_flags.stderr b/test_suite/tests/compile-fail/private_flags.stderr deleted file mode 100644 index 2bdf1acb..00000000 --- a/test_suite/tests/compile-fail/private_flags.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error[E0603]: struct `Flags2` is private - --> $DIR/private_flags.rs:18:26 - | -18 | let flag2 = example::Flags2::FLAG_B; - | ^^^^^^ private struct - | -note: the struct `Flags2` is defined here - --> $DIR/private_flags.rs:5:5 - | -5 | / bitflags! { -6 | | pub struct Flags1: u32 { -7 | | const FLAG_A = 0b00000001; -8 | | } -... | -12 | | } -13 | | } - | |_____^ - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)