Skip to content

Commit

Permalink
Remove the #[allow(non_uppercase_statics)] attr from bitflags!
Browse files Browse the repository at this point in the history
  • Loading branch information
ftxqxd committed Oct 6, 2014
1 parent e3ca987 commit 8e58771
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 42 deletions.
41 changes: 18 additions & 23 deletions src/libstd/bitflags.rs
Expand Up @@ -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
/// }
/// ```
///
Expand All @@ -50,8 +50,8 @@
///
/// bitflags! {
/// flags Flags: u32 {
/// static FlagA = 0x00000001,
/// static FlagB = 0x00000010,
/// static FLAG_A = 0x00000001,
/// static FLAG_B = 0x00000010,
/// }
/// }
///
Expand All @@ -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!");
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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};
Expand Down
38 changes: 19 additions & 19 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -2812,7 +2812,7 @@ impl<'a> Parser<'a> {
pub fn parse_assign_expr(&mut self) -> P<Expr> {
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();
Expand Down Expand Up @@ -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<P<Expr>> = None;
let mut hi = thn.span.hi;
Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand All @@ -2937,7 +2937,7 @@ impl<'a> Parser<'a> {

pub fn parse_while_expr(&mut self, opt_ident: Option<ast::Ident>) -> P<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 body = self.parse_block();
let hi = body.span.hi;
return self.mk_expr(lo, hi, ExprWhile(cond, body, opt_ident));
Expand All @@ -2952,7 +2952,7 @@ impl<'a> Parser<'a> {

fn parse_match_expr(&mut self) -> P<Expr> {
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<Arm> = Vec::new();
while self.token != token::RBRACE {
Expand All @@ -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)
Expand All @@ -2993,7 +2993,7 @@ impl<'a> Parser<'a> {

/// Parse an expression
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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)))
}
}
Expand All @@ -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)
}

Expand Down

5 comments on commit 8e58771

@bors
Copy link
Contributor

@bors bors commented on 8e58771 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at ftxqxd@8e58771

@bors
Copy link
Contributor

@bors bors commented on 8e58771 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging P1start/rust/bitflags-lints = 8e58771 into auto

@bors
Copy link
Contributor

@bors bors commented on 8e58771 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1start/rust/bitflags-lints = 8e58771 merged ok, testing candidate = 0e2f0ac

@bors
Copy link
Contributor

@bors bors commented on 8e58771 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 8e58771 Oct 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 0e2f0ac

Please sign in to comment.