1
Fork 0

Remove the #[allow(non_uppercase_statics)] attr from bitflags!

This commit is contained in:
P1start 2014-10-06 16:08:35 +13:00
parent e3ca987f74
commit 8e58771965
2 changed files with 37 additions and 42 deletions

View file

@ -24,22 +24,22 @@
/// ```{.rust} /// ```{.rust}
/// bitflags! { /// bitflags! {
/// flags Flags: u32 { /// flags Flags: u32 {
/// static FlagA = 0x00000001, /// static FLAG_A = 0x00000001,
/// static FlagB = 0x00000010, /// static FLAG_B = 0x00000010,
/// static FlagC = 0x00000100, /// static FLAG_C = 0x00000100,
/// static FlagABC = FlagA.bits /// static FLAG_ABC = FLAG_A.bits
/// | FlagB.bits /// | FLAG_B.bits
/// | FlagC.bits, /// | FLAG_C.bits,
/// } /// }
/// } /// }
/// ///
/// fn main() { /// fn main() {
/// let e1 = FlagA | FlagC; /// let e1 = FLAG_A | FLAG_C;
/// let e2 = FlagB | FlagC; /// let e2 = FLAG_B | FLAG_C;
/// assert!((e1 | e2) == FlagABC); // union /// assert!((e1 | e2) == FLAG_ABC); // union
/// assert!((e1 & e2) == FlagC); // intersection /// assert!((e1 & e2) == FLAG_C); // intersection
/// assert!((e1 - e2) == FlagA); // set difference /// assert!((e1 - e2) == FLAG_A); // set difference
/// assert!(!e2 == FlagA); // set complement /// assert!(!e2 == FLAG_A); // set complement
/// } /// }
/// ``` /// ```
/// ///
@ -50,8 +50,8 @@
/// ///
/// bitflags! { /// bitflags! {
/// flags Flags: u32 { /// flags Flags: u32 {
/// static FlagA = 0x00000001, /// static FLAG_A = 0x00000001,
/// static FlagB = 0x00000010, /// static FLAG_B = 0x00000010,
/// } /// }
/// } /// }
/// ///
@ -69,7 +69,7 @@
/// } /// }
/// ///
/// fn main() { /// fn main() {
/// let mut flags = FlagA | FlagB; /// let mut flags = FLAG_A | FLAG_B;
/// flags.clear(); /// flags.clear();
/// assert!(flags.is_empty()); /// assert!(flags.is_empty());
/// assert_eq!(format!("{}", flags).as_slice(), "hi!"); /// assert_eq!(format!("{}", flags).as_slice(), "hi!");
@ -123,10 +123,7 @@ macro_rules! bitflags {
bits: $T, bits: $T,
} }
$( $($(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value };)+
#[allow(non_uppercase_statics)]
$(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value };
)+
impl $BitFlags { impl $BitFlags {
/// Returns an empty set of flags. /// Returns an empty set of flags.
@ -243,16 +240,14 @@ macro_rules! bitflags {
bitflags! { bitflags! {
$(#[$attr])* $(#[$attr])*
flags $BitFlags: $T { flags $BitFlags: $T {
$( $($(#[$Flag_attr])* static $Flag = $value),+
#[allow(non_uppercase_statics)]
$(#[$Flag_attr])* static $Flag = $value
),+
} }
} }
}; };
} }
#[cfg(test)] #[cfg(test)]
#[allow(non_uppercase_statics)]
mod tests { mod tests {
use hash; use hash;
use option::{Some, None}; use option::{Some, None};

View file

@ -91,10 +91,10 @@ use std::iter;
bitflags! { bitflags! {
flags Restrictions: u8 { flags Restrictions: u8 {
static Unrestricted = 0b0000, static UNRESTRICTED = 0b0000,
static RestrictionStmtExpr = 0b0001, static RESTRICTION_STMT_EXPR = 0b0001,
static RestrictionNoBarOp = 0b0010, static RESTRICTION_NO_BAR_OP = 0b0010,
static RestrictionNoStructLiteral = 0b0100 static RESTRICTION_NO_STRUCT_LITERAL = 0b0100
} }
} }
@ -383,7 +383,7 @@ impl<'a> Parser<'a> {
buffer_start: 0, buffer_start: 0,
buffer_end: 0, buffer_end: 0,
tokens_consumed: 0, tokens_consumed: 0,
restrictions: Unrestricted, restrictions: UNRESTRICTED,
quote_depth: 0, quote_depth: 0,
obsolete_set: HashSet::new(), obsolete_set: HashSet::new(),
mod_path_stack: Vec::new(), mod_path_stack: Vec::new(),
@ -2242,7 +2242,7 @@ impl<'a> Parser<'a> {
if self.token == token::LBRACE { if self.token == token::LBRACE {
// This is a struct literal, unless we're prohibited // This is a struct literal, unless we're prohibited
// from parsing struct literals here. // from parsing struct literals here.
if !self.restrictions.contains(RestrictionNoStructLiteral) { if !self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL) {
// It's a struct literal. // It's a struct literal.
self.bump(); self.bump();
let mut fields = Vec::new(); let mut fields = Vec::new();
@ -2771,7 +2771,7 @@ impl<'a> Parser<'a> {
// Prevent dynamic borrow errors later on by limiting the // Prevent dynamic borrow errors later on by limiting the
// scope of the borrows. // scope of the borrows.
if self.token == token::BINOP(token::OR) && if self.token == token::BINOP(token::OR) &&
self.restrictions.contains(RestrictionNoBarOp) { self.restrictions.contains(RESTRICTION_NO_BAR_OP) {
return lhs; return lhs;
} }
@ -2812,7 +2812,7 @@ impl<'a> Parser<'a> {
pub fn parse_assign_expr(&mut self) -> P<Expr> { pub fn parse_assign_expr(&mut self) -> P<Expr> {
let lo = self.span.lo; let lo = self.span.lo;
let lhs = self.parse_binops(); let lhs = self.parse_binops();
let restrictions = self.restrictions & RestrictionNoStructLiteral; let restrictions = self.restrictions & RESTRICTION_NO_STRUCT_LITERAL;
match self.token { match self.token {
token::EQ => { token::EQ => {
self.bump(); self.bump();
@ -2850,7 +2850,7 @@ impl<'a> Parser<'a> {
return self.parse_if_let_expr(); return self.parse_if_let_expr();
} }
let lo = self.last_span.lo; let lo = self.last_span.lo;
let cond = self.parse_expr_res(RestrictionNoStructLiteral); let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
let thn = self.parse_block(); let thn = self.parse_block();
let mut els: Option<P<Expr>> = None; let mut els: Option<P<Expr>> = None;
let mut hi = thn.span.hi; let mut hi = thn.span.hi;
@ -2868,7 +2868,7 @@ impl<'a> Parser<'a> {
self.expect_keyword(keywords::Let); self.expect_keyword(keywords::Let);
let pat = self.parse_pat(); let pat = self.parse_pat();
self.expect(&token::EQ); self.expect(&token::EQ);
let expr = self.parse_expr_res(RestrictionNoStructLiteral); let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
let thn = self.parse_block(); let thn = self.parse_block();
let (hi, els) = if self.eat_keyword(keywords::Else) { let (hi, els) = if self.eat_keyword(keywords::Else) {
let expr = self.parse_else_expr(); let expr = self.parse_else_expr();
@ -2928,7 +2928,7 @@ impl<'a> Parser<'a> {
let lo = self.last_span.lo; let lo = self.last_span.lo;
let pat = self.parse_pat(); let pat = self.parse_pat();
self.expect_keyword(keywords::In); self.expect_keyword(keywords::In);
let expr = self.parse_expr_res(RestrictionNoStructLiteral); let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
let loop_block = self.parse_block(); let loop_block = self.parse_block();
let hi = self.span.hi; let hi = self.span.hi;
@ -2937,7 +2937,7 @@ impl<'a> Parser<'a> {
pub fn parse_while_expr(&mut self, opt_ident: Option<ast::Ident>) -> P<Expr> { pub fn parse_while_expr(&mut self, opt_ident: Option<ast::Ident>) -> P<Expr> {
let lo = self.last_span.lo; let lo = self.last_span.lo;
let cond = self.parse_expr_res(RestrictionNoStructLiteral); let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
let body = self.parse_block(); let body = self.parse_block();
let hi = body.span.hi; let hi = body.span.hi;
return self.mk_expr(lo, hi, ExprWhile(cond, body, opt_ident)); return self.mk_expr(lo, hi, ExprWhile(cond, body, opt_ident));
@ -2952,7 +2952,7 @@ impl<'a> Parser<'a> {
fn parse_match_expr(&mut self) -> P<Expr> { fn parse_match_expr(&mut self) -> P<Expr> {
let lo = self.last_span.lo; let lo = self.last_span.lo;
let discriminant = self.parse_expr_res(RestrictionNoStructLiteral); let discriminant = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
self.commit_expr_expecting(&*discriminant, token::LBRACE); self.commit_expr_expecting(&*discriminant, token::LBRACE);
let mut arms: Vec<Arm> = Vec::new(); let mut arms: Vec<Arm> = Vec::new();
while self.token != token::RBRACE { while self.token != token::RBRACE {
@ -2971,7 +2971,7 @@ impl<'a> Parser<'a> {
guard = Some(self.parse_expr()); guard = Some(self.parse_expr());
} }
self.expect(&token::FAT_ARROW); self.expect(&token::FAT_ARROW);
let expr = self.parse_expr_res(RestrictionStmtExpr); let expr = self.parse_expr_res(RESTRICTION_STMT_EXPR);
let require_comma = let require_comma =
!classify::expr_is_simple_block(&*expr) !classify::expr_is_simple_block(&*expr)
@ -2993,7 +2993,7 @@ impl<'a> Parser<'a> {
/// Parse an expression /// Parse an expression
pub fn parse_expr(&mut self) -> P<Expr> { pub fn parse_expr(&mut self) -> P<Expr> {
return self.parse_expr_res(Unrestricted); return self.parse_expr_res(UNRESTRICTED);
} }
/// Parse an expression, subject to the given restrictions /// Parse an expression, subject to the given restrictions
@ -3290,9 +3290,9 @@ impl<'a> Parser<'a> {
self.look_ahead(2, |t| { self.look_ahead(2, |t| {
*t != token::COMMA && *t != token::RBRACKET *t != token::COMMA && *t != token::RBRACKET
}) { }) {
let start = self.parse_expr_res(RestrictionNoBarOp); let start = self.parse_expr_res(RESTRICTION_NO_BAR_OP);
self.eat(&token::DOTDOTDOT); self.eat(&token::DOTDOTDOT);
let end = self.parse_expr_res(RestrictionNoBarOp); let end = self.parse_expr_res(RESTRICTION_NO_BAR_OP);
pat = PatRange(start, end); pat = PatRange(start, end);
} else if is_plain_ident(&self.token) && !can_be_enum_or_struct { } else if is_plain_ident(&self.token) && !can_be_enum_or_struct {
let id = self.parse_ident(); let id = self.parse_ident();
@ -3593,7 +3593,7 @@ impl<'a> Parser<'a> {
} }
// Remainder are line-expr stmts. // Remainder are line-expr stmts.
let e = self.parse_expr_res(RestrictionStmtExpr); let e = self.parse_expr_res(RESTRICTION_STMT_EXPR);
P(spanned(lo, e.span.hi, StmtExpr(e, ast::DUMMY_NODE_ID))) P(spanned(lo, e.span.hi, StmtExpr(e, ast::DUMMY_NODE_ID)))
} }
} }
@ -3602,7 +3602,7 @@ impl<'a> Parser<'a> {
/// Is this expression a successfully-parsed statement? /// Is this expression a successfully-parsed statement?
fn expr_is_complete(&mut self, e: &Expr) -> bool { fn expr_is_complete(&mut self, e: &Expr) -> bool {
self.restrictions.contains(RestrictionStmtExpr) && self.restrictions.contains(RESTRICTION_STMT_EXPR) &&
!classify::expr_requires_semi_to_be_stmt(e) !classify::expr_requires_semi_to_be_stmt(e)
} }