remove unneeded infra and dependence on compiler msgs

This commit is contained in:
Ashley Mannix 2021-05-16 20:08:13 +10:00
parent afd25d317c
commit bbd5d4dfb4
4 changed files with 67 additions and 210 deletions

View File

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

View File

@ -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<u32> {
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()
}

View File

@ -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;
}
)+
}
$BitFlags { bits: $(<$BitFlags as __BitFlags>::$Flag)|+ }
}
// 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: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();

View File

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