diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 391d099de87..7966040ed7b 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -24,22 +24,22 @@ /// ```{.rust} /// bitflags! { /// flags Flags: u32 { -/// static FlagA = 0x00000001, -/// static FlagB = 0x00000010, -/// static FlagC = 0x00000100, -/// static FlagABC = FlagA.bits -/// | FlagB.bits -/// | FlagC.bits, +/// static FLAG_A = 0x00000001, +/// static FLAG_B = 0x00000010, +/// static FLAG_C = 0x00000100, +/// static FLAG_ABC = FLAG_A.bits +/// | FLAG_B.bits +/// | FLAG_C.bits, /// } /// } /// /// fn main() { -/// let e1 = FlagA | FlagC; -/// let e2 = FlagB | FlagC; -/// assert!((e1 | e2) == FlagABC); // union -/// assert!((e1 & e2) == FlagC); // intersection -/// assert!((e1 - e2) == FlagA); // set difference -/// assert!(!e2 == FlagA); // set complement +/// let e1 = FLAG_A | FLAG_C; +/// let e2 = FLAG_B | FLAG_C; +/// assert!((e1 | e2) == FLAG_ABC); // union +/// assert!((e1 & e2) == FLAG_C); // intersection +/// assert!((e1 - e2) == FLAG_A); // set difference +/// assert!(!e2 == FLAG_A); // set complement /// } /// ``` /// @@ -50,8 +50,8 @@ /// /// bitflags! { /// flags Flags: u32 { -/// static FlagA = 0x00000001, -/// static FlagB = 0x00000010, +/// static FLAG_A = 0x00000001, +/// static FLAG_B = 0x00000010, /// } /// } /// @@ -69,7 +69,7 @@ /// } /// /// fn main() { -/// let mut flags = FlagA | FlagB; +/// let mut flags = FLAG_A | FLAG_B; /// flags.clear(); /// assert!(flags.is_empty()); /// assert_eq!(format!("{}", flags).as_slice(), "hi!"); @@ -123,10 +123,7 @@ macro_rules! bitflags { bits: $T, } - $( - #[allow(non_uppercase_statics)] - $(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value }; - )+ + $($(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value };)+ impl $BitFlags { /// Returns an empty set of flags. @@ -243,16 +240,14 @@ macro_rules! bitflags { bitflags! { $(#[$attr])* flags $BitFlags: $T { - $( - #[allow(non_uppercase_statics)] - $(#[$Flag_attr])* static $Flag = $value - ),+ + $($(#[$Flag_attr])* static $Flag = $value),+ } } }; } #[cfg(test)] +#[allow(non_uppercase_statics)] mod tests { use hash; use option::{Some, None}; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4c877c0b101..6ab14417265 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -91,10 +91,10 @@ use std::iter; bitflags! { flags Restrictions: u8 { - static Unrestricted = 0b0000, - static RestrictionStmtExpr = 0b0001, - static RestrictionNoBarOp = 0b0010, - static RestrictionNoStructLiteral = 0b0100 + static UNRESTRICTED = 0b0000, + static RESTRICTION_STMT_EXPR = 0b0001, + static RESTRICTION_NO_BAR_OP = 0b0010, + static RESTRICTION_NO_STRUCT_LITERAL = 0b0100 } } @@ -383,7 +383,7 @@ impl<'a> Parser<'a> { buffer_start: 0, buffer_end: 0, tokens_consumed: 0, - restrictions: Unrestricted, + restrictions: UNRESTRICTED, quote_depth: 0, obsolete_set: HashSet::new(), mod_path_stack: Vec::new(), @@ -2242,7 +2242,7 @@ impl<'a> Parser<'a> { if self.token == token::LBRACE { // This is a struct literal, unless we're prohibited // from parsing struct literals here. - if !self.restrictions.contains(RestrictionNoStructLiteral) { + if !self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL) { // It's a struct literal. self.bump(); let mut fields = Vec::new(); @@ -2771,7 +2771,7 @@ impl<'a> Parser<'a> { // Prevent dynamic borrow errors later on by limiting the // scope of the borrows. if self.token == token::BINOP(token::OR) && - self.restrictions.contains(RestrictionNoBarOp) { + self.restrictions.contains(RESTRICTION_NO_BAR_OP) { return lhs; } @@ -2812,7 +2812,7 @@ impl<'a> Parser<'a> { pub fn parse_assign_expr(&mut self) -> P { let lo = self.span.lo; let lhs = self.parse_binops(); - let restrictions = self.restrictions & RestrictionNoStructLiteral; + let restrictions = self.restrictions & RESTRICTION_NO_STRUCT_LITERAL; match self.token { token::EQ => { self.bump(); @@ -2850,7 +2850,7 @@ impl<'a> Parser<'a> { return self.parse_if_let_expr(); } 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 mut els: Option> = None; let mut hi = thn.span.hi; @@ -2868,7 +2868,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(RestrictionNoStructLiteral); + let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL); let thn = self.parse_block(); let (hi, els) = if self.eat_keyword(keywords::Else) { let expr = self.parse_else_expr(); @@ -2928,7 +2928,7 @@ impl<'a> Parser<'a> { let lo = self.last_span.lo; let pat = self.parse_pat(); 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 hi = self.span.hi; @@ -2937,7 +2937,7 @@ impl<'a> Parser<'a> { pub fn parse_while_expr(&mut self, opt_ident: Option) -> P { 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 hi = body.span.hi; 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 { 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); let mut arms: Vec = Vec::new(); while self.token != token::RBRACE { @@ -2971,7 +2971,7 @@ impl<'a> Parser<'a> { guard = Some(self.parse_expr()); } self.expect(&token::FAT_ARROW); - let expr = self.parse_expr_res(RestrictionStmtExpr); + let expr = self.parse_expr_res(RESTRICTION_STMT_EXPR); let require_comma = !classify::expr_is_simple_block(&*expr) @@ -2993,7 +2993,7 @@ impl<'a> Parser<'a> { /// Parse an expression pub fn parse_expr(&mut self) -> P { - return self.parse_expr_res(Unrestricted); + return self.parse_expr_res(UNRESTRICTED); } /// Parse an expression, subject to the given restrictions @@ -3290,9 +3290,9 @@ impl<'a> Parser<'a> { self.look_ahead(2, |t| { *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); - let end = self.parse_expr_res(RestrictionNoBarOp); + let end = self.parse_expr_res(RESTRICTION_NO_BAR_OP); pat = PatRange(start, end); } else if is_plain_ident(&self.token) && !can_be_enum_or_struct { let id = self.parse_ident(); @@ -3593,7 +3593,7 @@ impl<'a> Parser<'a> { } // 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))) } } @@ -3602,7 +3602,7 @@ impl<'a> Parser<'a> { /// Is this expression a successfully-parsed statement? 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) }