Remove rustc_bitflags; use the bitflags crate
This commit is contained in:
parent
e788fa7b6c
commit
231d9e7e5d
23 changed files with 190 additions and 646 deletions
32
src/Cargo.lock
generated
32
src/Cargo.lock
generated
|
@ -130,6 +130,11 @@ name = "bitflags"
|
|||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bootstrap"
|
||||
version = "0.0.0"
|
||||
|
@ -1418,6 +1423,7 @@ name = "rustc"
|
|||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"arena 0.0.0",
|
||||
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"flate2 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fmt_macros 0.0.0",
|
||||
"graphviz 0.0.0",
|
||||
|
@ -1425,7 +1431,6 @@ dependencies = [
|
|||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_back 0.0.0",
|
||||
"rustc_bitflags 0.0.0",
|
||||
"rustc_const_math 0.0.0",
|
||||
"rustc_data_structures 0.0.0",
|
||||
"rustc_errors 0.0.0",
|
||||
|
@ -1466,7 +1471,8 @@ dependencies = [
|
|||
name = "rustc_apfloat"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"rustc_bitflags 0.0.0",
|
||||
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_cratesio_shim 0.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1489,10 +1495,6 @@ dependencies = [
|
|||
"syntax 0.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_bitflags"
|
||||
version = "0.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_borrowck"
|
||||
version = "0.0.0"
|
||||
|
@ -1530,6 +1532,13 @@ dependencies = [
|
|||
"syntax 0.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_cratesio_shim"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc_data_structures"
|
||||
version = "0.0.0"
|
||||
|
@ -1610,9 +1619,10 @@ dependencies = [
|
|||
name = "rustc_llvm"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"build_helper 0.1.0",
|
||||
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_bitflags 0.0.0",
|
||||
"rustc_cratesio_shim 0.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1648,10 +1658,10 @@ dependencies = [
|
|||
name = "rustc_mir"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"graphviz 0.0.0",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc 0.0.0",
|
||||
"rustc_bitflags 0.0.0",
|
||||
"rustc_const_eval 0.0.0",
|
||||
"rustc_const_math 0.0.0",
|
||||
"rustc_data_structures 0.0.0",
|
||||
|
@ -1740,6 +1750,7 @@ dependencies = [
|
|||
name = "rustc_trans"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"flate2 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jobserver 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -1750,7 +1761,6 @@ dependencies = [
|
|||
"rustc-demangle 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_allocator 0.0.0",
|
||||
"rustc_back 0.0.0",
|
||||
"rustc_bitflags 0.0.0",
|
||||
"rustc_const_math 0.0.0",
|
||||
"rustc_data_structures 0.0.0",
|
||||
"rustc_errors 0.0.0",
|
||||
|
@ -2073,8 +2083,9 @@ dependencies = [
|
|||
name = "syntax"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc_cratesio_shim 0.0.0",
|
||||
"rustc_data_structures 0.0.0",
|
||||
"rustc_errors 0.0.0",
|
||||
"serialize 0.0.0",
|
||||
|
@ -2451,6 +2462,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d"
|
||||
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
|
||||
"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5"
|
||||
"checksum bitflags 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5cde24d1b2e2216a726368b2363a273739c91f4e3eb4e0dd12d672d396ad989"
|
||||
"checksum bufstream 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f382711e76b9de6c744cc00d0497baba02fb00a787f088c879f01d09468e32"
|
||||
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
|
||||
"checksum clap 2.26.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2267a8fdd4dce6956ba6649e130f62fb279026e5e84b92aa939ac8f85ce3f9f0"
|
||||
|
|
|
@ -10,13 +10,13 @@ crate-type = ["dylib"]
|
|||
|
||||
[dependencies]
|
||||
arena = { path = "../libarena" }
|
||||
bitflags = "1.0"
|
||||
fmt_macros = { path = "../libfmt_macros" }
|
||||
graphviz = { path = "../libgraphviz" }
|
||||
jobserver = "0.1"
|
||||
log = "0.3"
|
||||
owning_ref = "0.3.3"
|
||||
rustc_back = { path = "../librustc_back" }
|
||||
rustc_bitflags = { path = "../librustc_bitflags" }
|
||||
rustc_const_math = { path = "../librustc_const_math" }
|
||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||
rustc_errors = { path = "../librustc_errors" }
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#![recursion_limit="256"]
|
||||
|
||||
extern crate arena;
|
||||
#[macro_use] extern crate bitflags;
|
||||
extern crate core;
|
||||
extern crate fmt_macros;
|
||||
extern crate getopts;
|
||||
|
@ -56,7 +57,6 @@ extern crate rustc_errors as errors;
|
|||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
extern crate syntax_pos;
|
||||
#[macro_use] #[no_link] extern crate rustc_bitflags;
|
||||
extern crate jobserver;
|
||||
|
||||
extern crate serialize as rustc_serialize; // used by deriving
|
||||
|
|
|
@ -399,35 +399,35 @@ pub struct CReaderCacheKey {
|
|||
// check whether the type has various kinds of types in it without
|
||||
// recursing over the type itself.
|
||||
bitflags! {
|
||||
flags TypeFlags: u32 {
|
||||
const HAS_PARAMS = 1 << 0,
|
||||
const HAS_SELF = 1 << 1,
|
||||
const HAS_TY_INFER = 1 << 2,
|
||||
const HAS_RE_INFER = 1 << 3,
|
||||
const HAS_RE_SKOL = 1 << 4,
|
||||
const HAS_RE_EARLY_BOUND = 1 << 5,
|
||||
const HAS_FREE_REGIONS = 1 << 6,
|
||||
const HAS_TY_ERR = 1 << 7,
|
||||
const HAS_PROJECTION = 1 << 8,
|
||||
pub struct TypeFlags: u32 {
|
||||
const HAS_PARAMS = 1 << 0;
|
||||
const HAS_SELF = 1 << 1;
|
||||
const HAS_TY_INFER = 1 << 2;
|
||||
const HAS_RE_INFER = 1 << 3;
|
||||
const HAS_RE_SKOL = 1 << 4;
|
||||
const HAS_RE_EARLY_BOUND = 1 << 5;
|
||||
const HAS_FREE_REGIONS = 1 << 6;
|
||||
const HAS_TY_ERR = 1 << 7;
|
||||
const HAS_PROJECTION = 1 << 8;
|
||||
|
||||
// FIXME: Rename this to the actual property since it's used for generators too
|
||||
const HAS_TY_CLOSURE = 1 << 9,
|
||||
const HAS_TY_CLOSURE = 1 << 9;
|
||||
|
||||
// true if there are "names" of types and regions and so forth
|
||||
// that are local to a particular fn
|
||||
const HAS_LOCAL_NAMES = 1 << 10,
|
||||
const HAS_LOCAL_NAMES = 1 << 10;
|
||||
|
||||
// Present if the type belongs in a local type context.
|
||||
// Only set for TyInfer other than Fresh.
|
||||
const KEEP_IN_LOCAL_TCX = 1 << 11,
|
||||
const KEEP_IN_LOCAL_TCX = 1 << 11;
|
||||
|
||||
// Is there a projection that does not involve a bound region?
|
||||
// Currently we can't normalize projections w/ bound regions.
|
||||
const HAS_NORMALIZABLE_PROJECTION = 1 << 12,
|
||||
const HAS_NORMALIZABLE_PROJECTION = 1 << 12;
|
||||
|
||||
const NEEDS_SUBST = TypeFlags::HAS_PARAMS.bits |
|
||||
TypeFlags::HAS_SELF.bits |
|
||||
TypeFlags::HAS_RE_EARLY_BOUND.bits,
|
||||
TypeFlags::HAS_RE_EARLY_BOUND.bits;
|
||||
|
||||
// Flags representing the nominal content of a type,
|
||||
// computed by FlagsComputation. If you add a new nominal
|
||||
|
@ -443,7 +443,7 @@ bitflags! {
|
|||
TypeFlags::HAS_PROJECTION.bits |
|
||||
TypeFlags::HAS_TY_CLOSURE.bits |
|
||||
TypeFlags::HAS_LOCAL_NAMES.bits |
|
||||
TypeFlags::KEEP_IN_LOCAL_TCX.bits,
|
||||
TypeFlags::KEEP_IN_LOCAL_TCX.bits;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1259,13 +1259,13 @@ pub struct Destructor {
|
|||
}
|
||||
|
||||
bitflags! {
|
||||
flags AdtFlags: u32 {
|
||||
const NO_ADT_FLAGS = 0,
|
||||
const IS_ENUM = 1 << 0,
|
||||
const IS_PHANTOM_DATA = 1 << 1,
|
||||
const IS_FUNDAMENTAL = 1 << 2,
|
||||
const IS_UNION = 1 << 3,
|
||||
const IS_BOX = 1 << 4,
|
||||
pub struct AdtFlags: u32 {
|
||||
const NO_ADT_FLAGS = 0;
|
||||
const IS_ENUM = 1 << 0;
|
||||
const IS_PHANTOM_DATA = 1 << 1;
|
||||
const IS_FUNDAMENTAL = 1 << 2;
|
||||
const IS_UNION = 1 << 3;
|
||||
const IS_BOX = 1 << 4;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1358,18 +1358,18 @@ pub enum AdtKind { Struct, Union, Enum }
|
|||
|
||||
bitflags! {
|
||||
#[derive(RustcEncodable, RustcDecodable, Default)]
|
||||
flags ReprFlags: u8 {
|
||||
const IS_C = 1 << 0,
|
||||
const IS_PACKED = 1 << 1,
|
||||
const IS_SIMD = 1 << 2,
|
||||
pub struct ReprFlags: u8 {
|
||||
const IS_C = 1 << 0;
|
||||
const IS_PACKED = 1 << 1;
|
||||
const IS_SIMD = 1 << 2;
|
||||
// Internal only for now. If true, don't reorder fields.
|
||||
const IS_LINEAR = 1 << 3,
|
||||
const IS_LINEAR = 1 << 3;
|
||||
|
||||
// Any of these flags being set prevent field reordering optimisation.
|
||||
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits |
|
||||
ReprFlags::IS_PACKED.bits |
|
||||
ReprFlags::IS_SIMD.bits |
|
||||
ReprFlags::IS_LINEAR.bits,
|
||||
ReprFlags::IS_LINEAR.bits;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ use ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
|
|||
use ty::{Slice, TyS};
|
||||
use ty::subst::Kind;
|
||||
|
||||
use std::fmt;
|
||||
use std::iter;
|
||||
use std::cmp::Ordering;
|
||||
use syntax::abi;
|
||||
|
@ -577,12 +576,6 @@ impl<T> Binder<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TypeFlags {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{:x}", self.bits)
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents the projection of an associated type. In explicit UFCS
|
||||
/// form this would be written `<T as Trait<..>>::N`.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
|
||||
|
|
|
@ -8,4 +8,5 @@ name = "rustc_apfloat"
|
|||
path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
rustc_bitflags = { path = "../librustc_bitflags" }
|
||||
bitflags = "1.0"
|
||||
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
|
||||
|
|
|
@ -53,13 +53,17 @@
|
|||
#![cfg_attr(not(stage0), feature(const_min_value))]
|
||||
#![cfg_attr(not(stage0), feature(const_max_value))]
|
||||
|
||||
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_cratesio_shim;
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_bitflags;
|
||||
extern crate bitflags;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
use std::ops::{Neg, Add, Sub, Mul, Div, Rem};
|
||||
use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign, BitOrAssign};
|
||||
use std::ops::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
|
||||
use std::str::FromStr;
|
||||
|
||||
bitflags! {
|
||||
|
@ -67,20 +71,13 @@ bitflags! {
|
|||
///
|
||||
/// UNDERFLOW or OVERFLOW are always returned or-ed with INEXACT.
|
||||
#[must_use]
|
||||
#[derive(Debug)]
|
||||
flags Status: u8 {
|
||||
const OK = 0x00,
|
||||
const INVALID_OP = 0x01,
|
||||
const DIV_BY_ZERO = 0x02,
|
||||
const OVERFLOW = 0x04,
|
||||
const UNDERFLOW = 0x08,
|
||||
const INEXACT = 0x10
|
||||
}
|
||||
}
|
||||
|
||||
impl BitOrAssign for Status {
|
||||
fn bitor_assign(&mut self, rhs: Self) {
|
||||
*self = *self | rhs;
|
||||
pub struct Status: u8 {
|
||||
const OK = 0x00;
|
||||
const INVALID_OP = 0x01;
|
||||
const DIV_BY_ZERO = 0x02;
|
||||
const OVERFLOW = 0x04;
|
||||
const UNDERFLOW = 0x08;
|
||||
const INEXACT = 0x10;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
[package]
|
||||
authors = ["The Rust Project Developers"]
|
||||
name = "rustc_bitflags"
|
||||
version = "0.0.0"
|
||||
|
||||
[lib]
|
||||
name = "rustc_bitflags"
|
||||
path = "lib.rs"
|
||||
doctest = false
|
|
@ -1,494 +0,0 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
|
||||
#![no_std]
|
||||
#![deny(warnings)]
|
||||
|
||||
//! A typesafe bitmask flag generator.
|
||||
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
/// The `bitflags!` macro generates a `struct` that holds a set of C-style
|
||||
/// bitmask flags. It is useful for creating typesafe wrappers for C APIs.
|
||||
///
|
||||
/// The flags should only be defined for integer types, otherwise unexpected
|
||||
/// type errors may occur at compile time.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```{.rust}
|
||||
/// #![feature(rustc_private)]
|
||||
/// #[macro_use] extern crate rustc_bitflags;
|
||||
///
|
||||
/// bitflags! {
|
||||
/// flags Flags: u32 {
|
||||
/// const FLAG_A = 0b00000001,
|
||||
/// const FLAG_B = 0b00000010,
|
||||
/// const FLAG_C = 0b00000100,
|
||||
/// const FLAG_ABC = Flags::FLAG_A.bits
|
||||
/// | Flags::FLAG_B.bits
|
||||
/// | Flags::FLAG_C.bits,
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let e1 = Flags::FLAG_A | Flags::FLAG_C;
|
||||
/// let e2 = Flags::FLAG_B | Flags::FLAG_C;
|
||||
/// assert!((e1 | e2) == Flags::FLAG_ABC); // union
|
||||
/// assert!((e1 & e2) == Flags::FLAG_C); // intersection
|
||||
/// assert!((e1 - e2) == Flags::FLAG_A); // set difference
|
||||
/// assert!(!e2 == Flags::FLAG_A); // set complement
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// The generated `struct`s can also be extended with type and trait implementations:
|
||||
///
|
||||
/// ```{.rust}
|
||||
/// #![feature(rustc_private)]
|
||||
/// #[macro_use] extern crate rustc_bitflags;
|
||||
///
|
||||
/// use std::fmt;
|
||||
///
|
||||
/// bitflags! {
|
||||
/// flags Flags: u32 {
|
||||
/// const FLAG_A = 0b00000001,
|
||||
/// const FLAG_B = 0b00000010,
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl Flags {
|
||||
/// pub fn clear(&mut self) {
|
||||
/// self.bits = 0; // The `bits` field can be accessed from within the
|
||||
/// // same module where the `bitflags!` macro was invoked.
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl fmt::Debug for Flags {
|
||||
/// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
/// write!(f, "hi!")
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// fn main() {
|
||||
/// let mut flags = Flags::FLAG_A | Flags::FLAG_B;
|
||||
/// flags.clear();
|
||||
/// assert!(flags.is_empty());
|
||||
/// assert_eq!(format!("{:?}", flags), "hi!");
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// # Attributes
|
||||
///
|
||||
/// Attributes can be attached to the generated `struct` by placing them
|
||||
/// before the `flags` keyword.
|
||||
///
|
||||
/// # Derived traits
|
||||
///
|
||||
/// The `PartialEq` and `Clone` traits are automatically derived for the `struct` using
|
||||
/// the `deriving` attribute. Additional traits can be derived by providing an
|
||||
/// explicit `deriving` attribute on `flags`.
|
||||
///
|
||||
/// # Operators
|
||||
///
|
||||
/// The following operator traits are implemented for the generated `struct`:
|
||||
///
|
||||
/// - `BitOr`: union
|
||||
/// - `BitAnd`: intersection
|
||||
/// - `BitXor`: toggle
|
||||
/// - `Sub`: set difference
|
||||
/// - `Not`: set complement
|
||||
///
|
||||
/// # Methods
|
||||
///
|
||||
/// The following methods are defined for the generated `struct`:
|
||||
///
|
||||
/// - `empty`: an empty set of flags
|
||||
/// - `all`: the set of all flags
|
||||
/// - `bits`: the raw value of the flags currently stored
|
||||
/// - `from_bits`: convert from underlying bit representation, unless that
|
||||
/// representation contains bits that do not correspond to a flag
|
||||
/// - `from_bits_truncate`: convert from underlying bit representation, dropping
|
||||
/// any bits that do not correspond to flags
|
||||
/// - `is_empty`: `true` if no flags are currently stored
|
||||
/// - `is_all`: `true` if all flags are currently set
|
||||
/// - `intersects`: `true` if there are flags common to both `self` and `other`
|
||||
/// - `contains`: `true` all of the flags in `other` are contained within `self`
|
||||
/// - `insert`: inserts the specified flags in-place
|
||||
/// - `remove`: removes the specified flags in-place
|
||||
/// - `toggle`: the specified flags will be inserted if not present, and removed
|
||||
/// if they are.
|
||||
#[macro_export]
|
||||
macro_rules! bitflags {
|
||||
($(#[$attr:meta])* flags $BitFlags:ident: $T:ty {
|
||||
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+
|
||||
}) => {
|
||||
#[derive(Copy, PartialEq, Eq, Clone, PartialOrd, Ord, Hash)]
|
||||
$(#[$attr])*
|
||||
pub struct $BitFlags {
|
||||
bits: $T,
|
||||
}
|
||||
|
||||
impl $BitFlags {
|
||||
$($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags { bits: $value };)+
|
||||
|
||||
/// Returns an empty set of flags.
|
||||
#[inline]
|
||||
pub fn empty() -> $BitFlags {
|
||||
$BitFlags { bits: 0 }
|
||||
}
|
||||
|
||||
/// Returns the set containing all flags.
|
||||
#[inline]
|
||||
pub fn all() -> $BitFlags {
|
||||
$BitFlags { bits: $($value)|+ }
|
||||
}
|
||||
|
||||
/// Returns the raw value of the flags currently stored.
|
||||
#[inline]
|
||||
pub fn bits(&self) -> $T {
|
||||
self.bits
|
||||
}
|
||||
|
||||
/// Convert from underlying bit representation, unless that
|
||||
/// representation contains bits that do not correspond to a flag.
|
||||
#[inline]
|
||||
pub fn from_bits(bits: $T) -> ::std::option::Option<$BitFlags> {
|
||||
if (bits & !$BitFlags::all().bits()) != 0 {
|
||||
::std::option::Option::None
|
||||
} else {
|
||||
::std::option::Option::Some($BitFlags { bits: bits })
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert from underlying bit representation, dropping any bits
|
||||
/// that do not correspond to flags.
|
||||
#[inline]
|
||||
pub fn from_bits_truncate(bits: $T) -> $BitFlags {
|
||||
$BitFlags { bits: bits } & $BitFlags::all()
|
||||
}
|
||||
|
||||
/// Returns `true` if no flags are currently stored.
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
*self == $BitFlags::empty()
|
||||
}
|
||||
|
||||
/// Returns `true` if all flags are currently set.
|
||||
#[inline]
|
||||
pub fn is_all(&self) -> bool {
|
||||
*self == $BitFlags::all()
|
||||
}
|
||||
|
||||
/// Returns `true` if there are flags common to both `self` and `other`.
|
||||
#[inline]
|
||||
pub fn intersects(&self, other: $BitFlags) -> bool {
|
||||
!(*self & other).is_empty()
|
||||
}
|
||||
|
||||
/// Returns `true` if all of the flags in `other` are contained within `self`.
|
||||
#[inline]
|
||||
pub fn contains(&self, other: $BitFlags) -> bool {
|
||||
(*self & other) == other
|
||||
}
|
||||
|
||||
/// Inserts the specified flags in-place.
|
||||
#[inline]
|
||||
pub fn insert(&mut self, other: $BitFlags) {
|
||||
self.bits |= other.bits;
|
||||
}
|
||||
|
||||
/// Removes the specified flags in-place.
|
||||
#[inline]
|
||||
pub fn remove(&mut self, other: $BitFlags) {
|
||||
self.bits &= !other.bits;
|
||||
}
|
||||
|
||||
/// Toggles the specified flags in-place.
|
||||
#[inline]
|
||||
pub fn toggle(&mut self, other: $BitFlags) {
|
||||
self.bits ^= other.bits;
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::BitOr for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the union of the two sets of flags.
|
||||
#[inline]
|
||||
fn bitor(self, other: $BitFlags) -> $BitFlags {
|
||||
$BitFlags { bits: self.bits | other.bits }
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::BitXor for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the left flags, but with all the right flags toggled.
|
||||
#[inline]
|
||||
fn bitxor(self, other: $BitFlags) -> $BitFlags {
|
||||
$BitFlags { bits: self.bits ^ other.bits }
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::BitAnd for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the intersection between the two sets of flags.
|
||||
#[inline]
|
||||
fn bitand(self, other: $BitFlags) -> $BitFlags {
|
||||
$BitFlags { bits: self.bits & other.bits }
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Sub for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the set difference of the two sets of flags.
|
||||
#[inline]
|
||||
fn sub(self, other: $BitFlags) -> $BitFlags {
|
||||
$BitFlags { bits: self.bits & !other.bits }
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::ops::Not for $BitFlags {
|
||||
type Output = $BitFlags;
|
||||
|
||||
/// Returns the complement of this set of flags.
|
||||
#[inline]
|
||||
fn not(self) -> $BitFlags {
|
||||
$BitFlags { bits: !self.bits } & $BitFlags::all()
|
||||
}
|
||||
}
|
||||
};
|
||||
($(#[$attr:meta])* flags $BitFlags:ident: $T:ty {
|
||||
$($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+,
|
||||
}) => {
|
||||
bitflags! {
|
||||
$(#[$attr])*
|
||||
flags $BitFlags: $T {
|
||||
$($(#[$Flag_attr])* const $Flag = $value),+
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(non_upper_case_globals)]
|
||||
mod tests {
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::option::Option::{None, Some};
|
||||
|
||||
bitflags! {
|
||||
#[doc = "> The first principle is that you must not fool yourself — and"]
|
||||
#[doc = "> you are the easiest person to fool."]
|
||||
#[doc = "> "]
|
||||
#[doc = "> - Richard Feynman"]
|
||||
flags Flags: u32 {
|
||||
const FlagA = 0b00000001,
|
||||
#[doc = "<pcwalton> macros are way better at generating code than trans is"]
|
||||
const FlagB = 0b00000010,
|
||||
const FlagC = 0b00000100,
|
||||
#[doc = "* cmr bed"]
|
||||
#[doc = "* strcat table"]
|
||||
#[doc = "<strcat> wait what?"]
|
||||
const FlagABC = Flags::FlagA.bits
|
||||
| Flags::FlagB.bits
|
||||
| Flags::FlagC.bits,
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
flags AnotherSetOfFlags: i8 {
|
||||
const AnotherFlag = -1,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_bits() {
|
||||
assert_eq!(Flags::empty().bits(), 0b00000000);
|
||||
assert_eq!(Flags::FlagA.bits(), 0b00000001);
|
||||
assert_eq!(Flags::FlagABC.bits(), 0b00000111);
|
||||
|
||||
assert_eq!(AnotherSetOfFlags::empty().bits(), 0b00);
|
||||
assert_eq!(AnotherSetOfFlags::AnotherFlag.bits(), !0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_bits() {
|
||||
assert!(Flags::from_bits(0) == Some(Flags::empty()));
|
||||
assert!(Flags::from_bits(0b1) == Some(Flags::FlagA));
|
||||
assert!(Flags::from_bits(0b10) == Some(Flags::FlagB));
|
||||
assert!(Flags::from_bits(0b11) == Some(Flags::FlagA | Flags::FlagB));
|
||||
assert!(Flags::from_bits(0b1000) == None);
|
||||
|
||||
assert!(AnotherSetOfFlags::from_bits(!0) == Some(AnotherSetOfFlags::AnotherFlag));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_bits_truncate() {
|
||||
assert!(Flags::from_bits_truncate(0) == Flags::empty());
|
||||
assert!(Flags::from_bits_truncate(0b1) == Flags::FlagA);
|
||||
assert!(Flags::from_bits_truncate(0b10) == Flags::FlagB);
|
||||
assert!(Flags::from_bits_truncate(0b11) == (Flags::FlagA | Flags::FlagB));
|
||||
assert!(Flags::from_bits_truncate(0b1000) == Flags::empty());
|
||||
assert!(Flags::from_bits_truncate(0b1001) == Flags::FlagA);
|
||||
|
||||
assert!(AnotherSetOfFlags::from_bits_truncate(0) == AnotherSetOfFlags::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_empty() {
|
||||
assert!(Flags::empty().is_empty());
|
||||
assert!(!Flags::FlagA.is_empty());
|
||||
assert!(!Flags::FlagABC.is_empty());
|
||||
|
||||
assert!(!AnotherSetOfFlags::AnotherFlag.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_all() {
|
||||
assert!(Flags::all().is_all());
|
||||
assert!(!Flags::FlagA.is_all());
|
||||
assert!(Flags::FlagABC.is_all());
|
||||
|
||||
assert!(AnotherSetOfFlags::AnotherFlag.is_all());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_two_empties_do_not_intersect() {
|
||||
let e1 = Flags::empty();
|
||||
let e2 = Flags::empty();
|
||||
assert!(!e1.intersects(e2));
|
||||
|
||||
assert!(AnotherSetOfFlags::AnotherFlag.intersects(AnotherSetOfFlags::AnotherFlag));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty_does_not_intersect_with_full() {
|
||||
let e1 = Flags::empty();
|
||||
let e2 = Flags::FlagABC;
|
||||
assert!(!e1.intersects(e2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_disjoint_intersects() {
|
||||
let e1 = Flags::FlagA;
|
||||
let e2 = Flags::FlagB;
|
||||
assert!(!e1.intersects(e2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_overlapping_intersects() {
|
||||
let e1 = Flags::FlagA;
|
||||
let e2 = Flags::FlagA | Flags::FlagB;
|
||||
assert!(e1.intersects(e2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_contains() {
|
||||
let e1 = Flags::FlagA;
|
||||
let e2 = Flags::FlagA | Flags::FlagB;
|
||||
assert!(!e1.contains(e2));
|
||||
assert!(e2.contains(e1));
|
||||
assert!(Flags::FlagABC.contains(e2));
|
||||
|
||||
assert!(AnotherSetOfFlags::AnotherFlag.contains(AnotherSetOfFlags::AnotherFlag));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_insert() {
|
||||
let mut e1 = Flags::FlagA;
|
||||
let e2 = Flags::FlagA | Flags::FlagB;
|
||||
e1.insert(e2);
|
||||
assert!(e1 == e2);
|
||||
|
||||
let mut e3 = AnotherSetOfFlags::empty();
|
||||
e3.insert(AnotherSetOfFlags::AnotherFlag);
|
||||
assert!(e3 == AnotherSetOfFlags::AnotherFlag);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove() {
|
||||
let mut e1 = Flags::FlagA | Flags::FlagB;
|
||||
let e2 = Flags::FlagA | Flags::FlagC;
|
||||
e1.remove(e2);
|
||||
assert!(e1 == Flags::FlagB);
|
||||
|
||||
let mut e3 = AnotherSetOfFlags::AnotherFlag;
|
||||
e3.remove(AnotherSetOfFlags::AnotherFlag);
|
||||
assert!(e3 == AnotherSetOfFlags::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_operators() {
|
||||
let e1 = Flags::FlagA | Flags::FlagC;
|
||||
let e2 = Flags::FlagB | Flags::FlagC;
|
||||
assert!((e1 | e2) == Flags::FlagABC); // union
|
||||
assert!((e1 & e2) == Flags::FlagC); // intersection
|
||||
assert!((e1 - e2) == Flags::FlagA); // set difference
|
||||
assert!(!e2 == Flags::FlagA); // set complement
|
||||
assert!(e1 ^ e2 == Flags::FlagA | Flags::FlagB); // toggle
|
||||
let mut e3 = e1;
|
||||
e3.toggle(e2);
|
||||
assert!(e3 == Flags::FlagA | Flags::FlagB);
|
||||
|
||||
let mut m4 = AnotherSetOfFlags::empty();
|
||||
m4.toggle(AnotherSetOfFlags::empty());
|
||||
assert!(m4 == AnotherSetOfFlags::empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_lt() {
|
||||
let mut a = Flags::empty();
|
||||
let mut b = Flags::empty();
|
||||
|
||||
assert!(!(a < b) && !(b < a));
|
||||
b = Flags::FlagB;
|
||||
assert!(a < b);
|
||||
a = Flags::FlagC;
|
||||
assert!(!(a < b) && b < a);
|
||||
b = Flags::FlagC | Flags::FlagB;
|
||||
assert!(a < b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ord() {
|
||||
let mut a = Flags::empty();
|
||||
let mut b = Flags::empty();
|
||||
|
||||
assert!(a <= b && a >= b);
|
||||
a = Flags::FlagA;
|
||||
assert!(a > b && a >= b);
|
||||
assert!(b < a && b <= a);
|
||||
b = Flags::FlagB;
|
||||
assert!(b > a && b >= a);
|
||||
assert!(a < b && a <= b);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hash() {
|
||||
let mut x = Flags::empty();
|
||||
let mut y = Flags::empty();
|
||||
assert!(hash(&x) == hash(&y));
|
||||
x = Flags::all();
|
||||
y = Flags::FlagABC;
|
||||
assert!(hash(&x) == hash(&y));
|
||||
}
|
||||
|
||||
fn hash<T: Hash>(t: &T) -> u64 {
|
||||
let mut s = DefaultHasher::new();
|
||||
t.hash(&mut s);
|
||||
s.finish()
|
||||
}
|
||||
}
|
23
src/librustc_cratesio_shim/Cargo.toml
Normal file
23
src/librustc_cratesio_shim/Cargo.toml
Normal file
|
@ -0,0 +1,23 @@
|
|||
# This crate exists to allow rustc to link certain crates from crates.io into
|
||||
# the distribution. This doesn't work normally because:
|
||||
#
|
||||
# - Cargo always builds dependencies as rlibs:
|
||||
# https://github.com/rust-lang/cargo/issues/629
|
||||
# - rustc wants to avoid multiple definitions of the same symbol, so it refuses
|
||||
# to link multiple dylibs containing the same rlib
|
||||
# - multiple dylibs depend on the same crates.io crates
|
||||
#
|
||||
# This solution works by including all the conflicting rlibs in a single dylib,
|
||||
# which is then linked into all dylibs that depend on these crates.io crates.
|
||||
# The result is that each rlib only appears once, and things work!
|
||||
|
||||
[package]
|
||||
authors = ["The Rust Project Developers"]
|
||||
name = "rustc_cratesio_shim"
|
||||
version = "0.0.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["dylib"]
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.0"
|
14
src/librustc_cratesio_shim/src/lib.rs
Normal file
14
src/librustc_cratesio_shim/src/lib.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// See Cargo.toml for a comment explaining this crate.
|
||||
#![allow(unused_extern_crates)]
|
||||
|
||||
extern crate bitflags;
|
|
@ -13,7 +13,8 @@ crate-type = ["dylib"]
|
|||
static-libstdcpp = []
|
||||
|
||||
[dependencies]
|
||||
rustc_bitflags = { path = "../librustc_bitflags" }
|
||||
bitflags = "1.0"
|
||||
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
|
||||
|
||||
[build-dependencies]
|
||||
build_helper = { path = "../build_helper" }
|
||||
|
|
|
@ -454,26 +454,26 @@ pub mod debuginfo {
|
|||
// These values **must** match with LLVMRustDIFlags!!
|
||||
bitflags! {
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default)]
|
||||
flags DIFlags: ::libc::uint32_t {
|
||||
const FlagZero = 0,
|
||||
const FlagPrivate = 1,
|
||||
const FlagProtected = 2,
|
||||
const FlagPublic = 3,
|
||||
const FlagFwdDecl = (1 << 2),
|
||||
const FlagAppleBlock = (1 << 3),
|
||||
const FlagBlockByrefStruct = (1 << 4),
|
||||
const FlagVirtual = (1 << 5),
|
||||
const FlagArtificial = (1 << 6),
|
||||
const FlagExplicit = (1 << 7),
|
||||
const FlagPrototyped = (1 << 8),
|
||||
const FlagObjcClassComplete = (1 << 9),
|
||||
const FlagObjectPointer = (1 << 10),
|
||||
const FlagVector = (1 << 11),
|
||||
const FlagStaticMember = (1 << 12),
|
||||
const FlagLValueReference = (1 << 13),
|
||||
const FlagRValueReference = (1 << 14),
|
||||
const FlagMainSubprogram = (1 << 21),
|
||||
#[derive(Default)]
|
||||
pub struct DIFlags: ::libc::uint32_t {
|
||||
const FlagZero = 0;
|
||||
const FlagPrivate = 1;
|
||||
const FlagProtected = 2;
|
||||
const FlagPublic = 3;
|
||||
const FlagFwdDecl = (1 << 2);
|
||||
const FlagAppleBlock = (1 << 3);
|
||||
const FlagBlockByrefStruct = (1 << 4);
|
||||
const FlagVirtual = (1 << 5);
|
||||
const FlagArtificial = (1 << 6);
|
||||
const FlagExplicit = (1 << 7);
|
||||
const FlagPrototyped = (1 << 8);
|
||||
const FlagObjcClassComplete = (1 << 9);
|
||||
const FlagObjectPointer = (1 << 10);
|
||||
const FlagVector = (1 << 11);
|
||||
const FlagStaticMember = (1 << 12);
|
||||
const FlagLValueReference = (1 << 13);
|
||||
const FlagRValueReference = (1 << 14);
|
||||
const FlagMainSubprogram = (1 << 21);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,10 +24,13 @@
|
|||
#![feature(link_args)]
|
||||
#![feature(static_nobundle)]
|
||||
|
||||
extern crate libc;
|
||||
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_cratesio_shim;
|
||||
|
||||
#[macro_use]
|
||||
#[no_link]
|
||||
extern crate rustc_bitflags;
|
||||
extern crate bitflags;
|
||||
extern crate libc;
|
||||
|
||||
pub use self::IntPredicate::*;
|
||||
pub use self::RealPredicate::*;
|
||||
|
|
|
@ -9,6 +9,7 @@ path = "lib.rs"
|
|||
crate-type = ["dylib"]
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.0"
|
||||
graphviz = { path = "../libgraphviz" }
|
||||
log = "0.3"
|
||||
rustc = { path = "../librustc" }
|
||||
|
@ -16,6 +17,5 @@ rustc_const_eval = { path = "../librustc_const_eval" }
|
|||
rustc_const_math = { path = "../librustc_const_math" }
|
||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||
rustc_errors = { path = "../librustc_errors" }
|
||||
rustc_bitflags = { path = "../librustc_bitflags" }
|
||||
syntax = { path = "../libsyntax" }
|
||||
syntax_pos = { path = "../libsyntax_pos" }
|
||||
|
|
|
@ -24,6 +24,8 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
|
|||
#![feature(collection_placement)]
|
||||
#![feature(nonzero)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate graphviz as dot;
|
||||
#[macro_use]
|
||||
|
@ -31,9 +33,6 @@ extern crate rustc;
|
|||
extern crate rustc_data_structures;
|
||||
extern crate rustc_errors;
|
||||
#[macro_use]
|
||||
#[no_link]
|
||||
extern crate rustc_bitflags;
|
||||
#[macro_use]
|
||||
extern crate syntax;
|
||||
extern crate syntax_pos;
|
||||
extern crate rustc_const_math;
|
||||
|
|
|
@ -41,38 +41,38 @@ use std::usize;
|
|||
use super::promote_consts::{self, Candidate, TempState};
|
||||
|
||||
bitflags! {
|
||||
flags Qualif: u8 {
|
||||
struct Qualif: u8 {
|
||||
// Constant containing interior mutability (UnsafeCell).
|
||||
const MUTABLE_INTERIOR = 1 << 0,
|
||||
const MUTABLE_INTERIOR = 1 << 0;
|
||||
|
||||
// Constant containing an ADT that implements Drop.
|
||||
const NEEDS_DROP = 1 << 1,
|
||||
const NEEDS_DROP = 1 << 1;
|
||||
|
||||
// Function argument.
|
||||
const FN_ARGUMENT = 1 << 2,
|
||||
const FN_ARGUMENT = 1 << 2;
|
||||
|
||||
// Static lvalue or move from a static.
|
||||
const STATIC = 1 << 3,
|
||||
const STATIC = 1 << 3;
|
||||
|
||||
// Reference to a static.
|
||||
const STATIC_REF = 1 << 4,
|
||||
const STATIC_REF = 1 << 4;
|
||||
|
||||
// Not constant at all - non-`const fn` calls, asm!,
|
||||
// pointer comparisons, ptr-to-int casts, etc.
|
||||
const NOT_CONST = 1 << 5,
|
||||
const NOT_CONST = 1 << 5;
|
||||
|
||||
// Refers to temporaries which cannot be promoted as
|
||||
// promote_consts decided they weren't simple enough.
|
||||
const NOT_PROMOTABLE = 1 << 6,
|
||||
const NOT_PROMOTABLE = 1 << 6;
|
||||
|
||||
// Borrows of temporaries can be promoted only
|
||||
// if they have none of the above qualifications.
|
||||
const NEVER_PROMOTE = 0b111_1111,
|
||||
const NEVER_PROMOTE = 0b111_1111;
|
||||
|
||||
// Const items can only have MUTABLE_INTERIOR
|
||||
// and NOT_PROMOTABLE without producing an error.
|
||||
const CONST_ERROR = !Qualif::MUTABLE_INTERIOR.bits &
|
||||
!Qualif::NOT_PROMOTABLE.bits
|
||||
!Qualif::NOT_PROMOTABLE.bits;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ crate-type = ["dylib"]
|
|||
test = false
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.0"
|
||||
num_cpus = "1.0"
|
||||
flate2 = "0.2"
|
||||
jobserver = "0.1.5"
|
||||
|
@ -19,7 +20,6 @@ rustc-demangle = "0.1.4"
|
|||
rustc = { path = "../librustc" }
|
||||
rustc_allocator = { path = "../librustc_allocator" }
|
||||
rustc_back = { path = "../librustc_back" }
|
||||
rustc_bitflags = { path = "../librustc_bitflags" }
|
||||
rustc_const_math = { path = "../librustc_const_math" }
|
||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||
rustc_errors = { path = "../librustc_errors" }
|
||||
|
|
|
@ -65,17 +65,17 @@ pub use self::attr_impl::ArgAttribute;
|
|||
mod attr_impl {
|
||||
// The subset of llvm::Attribute needed for arguments, packed into a bitfield.
|
||||
bitflags! {
|
||||
#[derive(Default, Debug)]
|
||||
flags ArgAttribute : u16 {
|
||||
const ByVal = 1 << 0,
|
||||
const NoAlias = 1 << 1,
|
||||
const NoCapture = 1 << 2,
|
||||
const NonNull = 1 << 3,
|
||||
const ReadOnly = 1 << 4,
|
||||
const SExt = 1 << 5,
|
||||
const StructRet = 1 << 6,
|
||||
const ZExt = 1 << 7,
|
||||
const InReg = 1 << 8,
|
||||
#[derive(Default)]
|
||||
pub struct ArgAttribute: u16 {
|
||||
const ByVal = 1 << 0;
|
||||
const NoAlias = 1 << 1;
|
||||
const NoCapture = 1 << 2;
|
||||
const NonNull = 1 << 3;
|
||||
const ReadOnly = 1 << 4;
|
||||
const SExt = 1 << 5;
|
||||
const StructRet = 1 << 6;
|
||||
const ZExt = 1 << 7;
|
||||
const InReg = 1 << 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
use rustc::dep_graph::WorkProduct;
|
||||
use syntax_pos::symbol::Symbol;
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
extern crate flate2;
|
||||
extern crate libc;
|
||||
extern crate owning_ref;
|
||||
|
@ -48,9 +50,6 @@ extern crate rustc_incremental;
|
|||
extern crate rustc_llvm as llvm;
|
||||
extern crate rustc_platform_intrinsics as intrinsics;
|
||||
extern crate rustc_const_math;
|
||||
#[macro_use]
|
||||
#[no_link]
|
||||
extern crate rustc_bitflags;
|
||||
extern crate rustc_demangle;
|
||||
extern crate jobserver;
|
||||
extern crate num_cpus;
|
||||
|
|
|
@ -9,9 +9,10 @@ path = "lib.rs"
|
|||
crate-type = ["dylib"]
|
||||
|
||||
[dependencies]
|
||||
bitflags = "1.0"
|
||||
serialize = { path = "../libserialize" }
|
||||
log = "0.3"
|
||||
bitflags = "0.8"
|
||||
syntax_pos = { path = "../libsyntax_pos" }
|
||||
rustc_cratesio_shim = { path = "../librustc_cratesio_shim" }
|
||||
rustc_errors = { path = "../librustc_errors" }
|
||||
rustc_data_structures = { path = "../librustc_data_structures" }
|
||||
|
|
|
@ -24,9 +24,13 @@
|
|||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(i128_type)]
|
||||
|
||||
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate rustc_cratesio_shim;
|
||||
|
||||
#[macro_use] extern crate bitflags;
|
||||
extern crate serialize;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate bitflags;
|
||||
extern crate std_unicode;
|
||||
pub extern crate rustc_errors as errors;
|
||||
extern crate syntax_pos;
|
||||
|
|
|
@ -64,9 +64,9 @@ use std::path::{self, Path, PathBuf};
|
|||
use std::slice;
|
||||
|
||||
bitflags! {
|
||||
pub flags Restrictions: u8 {
|
||||
const RESTRICTION_STMT_EXPR = 1 << 0,
|
||||
const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1,
|
||||
pub struct Restrictions: u8 {
|
||||
const STMT_EXPR = 1 << 0;
|
||||
const NO_STRUCT_LITERAL = 1 << 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2240,7 +2240,7 @@ impl<'a> Parser<'a> {
|
|||
let e = if self.token.can_begin_expr()
|
||||
&& !(self.token == token::OpenDelim(token::Brace)
|
||||
&& self.restrictions.contains(
|
||||
RESTRICTION_NO_STRUCT_LITERAL)) {
|
||||
Restrictions::NO_STRUCT_LITERAL)) {
|
||||
Some(self.parse_expr()?)
|
||||
} else {
|
||||
None
|
||||
|
@ -2275,7 +2275,7 @@ impl<'a> Parser<'a> {
|
|||
// This is a struct literal, unless we're prohibited
|
||||
// from parsing struct literals here.
|
||||
let prohibited = self.restrictions.contains(
|
||||
RESTRICTION_NO_STRUCT_LITERAL
|
||||
Restrictions::NO_STRUCT_LITERAL
|
||||
);
|
||||
if !prohibited {
|
||||
return self.parse_struct_expr(lo, pth, attrs);
|
||||
|
@ -2669,7 +2669,7 @@ impl<'a> Parser<'a> {
|
|||
token::Ident(..) if self.token.is_keyword(keywords::In) => {
|
||||
self.bump();
|
||||
let place = self.parse_expr_res(
|
||||
RESTRICTION_NO_STRUCT_LITERAL,
|
||||
Restrictions::NO_STRUCT_LITERAL,
|
||||
None,
|
||||
)?;
|
||||
let blk = self.parse_block()?;
|
||||
|
@ -2737,7 +2737,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let cur_op_span = self.span;
|
||||
let restrictions = if op.is_assign_like() {
|
||||
self.restrictions & RESTRICTION_NO_STRUCT_LITERAL
|
||||
self.restrictions & Restrictions::NO_STRUCT_LITERAL
|
||||
} else {
|
||||
self.restrictions
|
||||
};
|
||||
|
@ -2800,13 +2800,13 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let rhs = match op.fixity() {
|
||||
Fixity::Right => self.with_res(
|
||||
restrictions - RESTRICTION_STMT_EXPR,
|
||||
restrictions - Restrictions::STMT_EXPR,
|
||||
|this| {
|
||||
this.parse_assoc_expr_with(op.precedence(),
|
||||
LhsExpr::NotYetParsed)
|
||||
}),
|
||||
Fixity::Left => self.with_res(
|
||||
restrictions - RESTRICTION_STMT_EXPR,
|
||||
restrictions - Restrictions::STMT_EXPR,
|
||||
|this| {
|
||||
this.parse_assoc_expr_with(op.precedence() + 1,
|
||||
LhsExpr::NotYetParsed)
|
||||
|
@ -2814,7 +2814,7 @@ impl<'a> Parser<'a> {
|
|||
// We currently have no non-associative operators that are not handled above by
|
||||
// the special cases. The code is here only for future convenience.
|
||||
Fixity::None => self.with_res(
|
||||
restrictions - RESTRICTION_STMT_EXPR,
|
||||
restrictions - Restrictions::STMT_EXPR,
|
||||
|this| {
|
||||
this.parse_assoc_expr_with(op.precedence() + 1,
|
||||
LhsExpr::NotYetParsed)
|
||||
|
@ -2989,7 +2989,7 @@ impl<'a> Parser<'a> {
|
|||
if self.token.can_begin_expr() {
|
||||
// parse `for i in 1.. { }` as infinite loop, not as `for i in (1..{})`.
|
||||
if self.token == token::OpenDelim(token::Brace) {
|
||||
return !self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL);
|
||||
return !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL);
|
||||
}
|
||||
true
|
||||
} else {
|
||||
|
@ -3003,7 +3003,7 @@ impl<'a> Parser<'a> {
|
|||
return self.parse_if_let_expr(attrs);
|
||||
}
|
||||
let lo = self.prev_span;
|
||||
let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
|
||||
let cond = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
|
||||
|
||||
// Verify that the parsed `if` condition makes sense as a condition. If it is a block, then
|
||||
// verify that the last statement is either an implicit return (no `;`) or an explicit
|
||||
|
@ -3034,7 +3034,7 @@ impl<'a> Parser<'a> {
|
|||
self.expect_keyword(keywords::Let)?;
|
||||
let pat = self.parse_pat()?;
|
||||
self.expect(&token::Eq)?;
|
||||
let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
|
||||
let expr = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
|
||||
let thn = self.parse_block()?;
|
||||
let (hi, els) = if self.eat_keyword(keywords::Else) {
|
||||
let expr = self.parse_else_expr()?;
|
||||
|
@ -3056,7 +3056,7 @@ impl<'a> Parser<'a> {
|
|||
let decl_hi = self.prev_span;
|
||||
let body = match decl.output {
|
||||
FunctionRetTy::Default(_) => {
|
||||
let restrictions = self.restrictions - RESTRICTION_STMT_EXPR;
|
||||
let restrictions = self.restrictions - Restrictions::STMT_EXPR;
|
||||
self.parse_expr_res(restrictions, None)?
|
||||
},
|
||||
_ => {
|
||||
|
@ -3091,7 +3091,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let pat = self.parse_pat()?;
|
||||
self.expect_keyword(keywords::In)?;
|
||||
let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
|
||||
let expr = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
|
||||
let (iattrs, loop_block) = self.parse_inner_attrs_and_block()?;
|
||||
attrs.extend(iattrs);
|
||||
|
||||
|
@ -3106,7 +3106,7 @@ impl<'a> Parser<'a> {
|
|||
if self.token.is_keyword(keywords::Let) {
|
||||
return self.parse_while_let_expr(opt_ident, span_lo, attrs);
|
||||
}
|
||||
let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
|
||||
let cond = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
|
||||
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
|
||||
attrs.extend(iattrs);
|
||||
let span = span_lo.to(body.span);
|
||||
|
@ -3120,7 +3120,7 @@ impl<'a> Parser<'a> {
|
|||
self.expect_keyword(keywords::Let)?;
|
||||
let pat = self.parse_pat()?;
|
||||
self.expect(&token::Eq)?;
|
||||
let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL, None)?;
|
||||
let expr = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, None)?;
|
||||
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
|
||||
attrs.extend(iattrs);
|
||||
let span = span_lo.to(body.span);
|
||||
|
@ -3150,7 +3150,7 @@ impl<'a> Parser<'a> {
|
|||
fn parse_match_expr(&mut self, mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
|
||||
let match_span = self.prev_span;
|
||||
let lo = self.prev_span;
|
||||
let discriminant = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL,
|
||||
let discriminant = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL,
|
||||
None)?;
|
||||
if let Err(mut e) = self.expect(&token::OpenDelim(token::Brace)) {
|
||||
if self.token == token::Token::Semi {
|
||||
|
@ -3198,7 +3198,7 @@ impl<'a> Parser<'a> {
|
|||
None
|
||||
};
|
||||
self.expect(&token::FatArrow)?;
|
||||
let expr = self.parse_expr_res(RESTRICTION_STMT_EXPR, None)?;
|
||||
let expr = self.parse_expr_res(Restrictions::STMT_EXPR, None)?;
|
||||
|
||||
let require_comma = classify::expr_requires_semi_to_be_stmt(&expr)
|
||||
&& self.token != token::CloseDelim(token::Brace);
|
||||
|
@ -3789,7 +3789,7 @@ impl<'a> Parser<'a> {
|
|||
self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace)) &&
|
||||
|
||||
// prevent `while catch {} {}`, `if catch {} {} else {}`, etc.
|
||||
!self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL)
|
||||
!self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL)
|
||||
}
|
||||
|
||||
fn is_union_item(&self) -> bool {
|
||||
|
@ -3911,7 +3911,7 @@ impl<'a> Parser<'a> {
|
|||
self.mk_expr(lo.to(hi), ExprKind::Path(None, pth), ThinVec::new())
|
||||
};
|
||||
|
||||
let expr = self.with_res(RESTRICTION_STMT_EXPR, |this| {
|
||||
let expr = self.with_res(Restrictions::STMT_EXPR, |this| {
|
||||
let expr = this.parse_dot_or_call_expr_with(expr, lo, attrs.into())?;
|
||||
this.parse_assoc_expr_with(0, LhsExpr::AlreadyParsed(expr))
|
||||
})?;
|
||||
|
@ -4052,7 +4052,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
// Remainder are line-expr stmts.
|
||||
let e = self.parse_expr_res(
|
||||
RESTRICTION_STMT_EXPR, Some(attrs.into()))?;
|
||||
Restrictions::STMT_EXPR, Some(attrs.into()))?;
|
||||
Stmt {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: lo.to(e.span),
|
||||
|
@ -4065,7 +4065,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
/// Is this expression a successfully-parsed statement?
|
||||
fn expr_is_complete(&mut self, e: &Expr) -> bool {
|
||||
self.restrictions.contains(RESTRICTION_STMT_EXPR) &&
|
||||
self.restrictions.contains(Restrictions::STMT_EXPR) &&
|
||||
!classify::expr_requires_semi_to_be_stmt(e)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue