Skip to content

Commit 8e58771

Browse files
committed
Remove the #[allow(non_uppercase_statics)] attr from bitflags!
1 parent e3ca987 commit 8e58771

File tree

2 files changed

+37
-42
lines changed

2 files changed

+37
-42
lines changed

src/libstd/bitflags.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424
/// ```{.rust}
2525
/// bitflags! {
2626
/// flags Flags: u32 {
27-
/// static FlagA = 0x00000001,
28-
/// static FlagB = 0x00000010,
29-
/// static FlagC = 0x00000100,
30-
/// static FlagABC = FlagA.bits
31-
/// | FlagB.bits
32-
/// | FlagC.bits,
27+
/// static FLAG_A = 0x00000001,
28+
/// static FLAG_B = 0x00000010,
29+
/// static FLAG_C = 0x00000100,
30+
/// static FLAG_ABC = FLAG_A.bits
31+
/// | FLAG_B.bits
32+
/// | FLAG_C.bits,
3333
/// }
3434
/// }
3535
///
3636
/// fn main() {
37-
/// let e1 = FlagA | FlagC;
38-
/// let e2 = FlagB | FlagC;
39-
/// assert!((e1 | e2) == FlagABC); // union
40-
/// assert!((e1 & e2) == FlagC); // intersection
41-
/// assert!((e1 - e2) == FlagA); // set difference
42-
/// assert!(!e2 == FlagA); // set complement
37+
/// let e1 = FLAG_A | FLAG_C;
38+
/// let e2 = FLAG_B | FLAG_C;
39+
/// assert!((e1 | e2) == FLAG_ABC); // union
40+
/// assert!((e1 & e2) == FLAG_C); // intersection
41+
/// assert!((e1 - e2) == FLAG_A); // set difference
42+
/// assert!(!e2 == FLAG_A); // set complement
4343
/// }
4444
/// ```
4545
///
@@ -50,8 +50,8 @@
5050
///
5151
/// bitflags! {
5252
/// flags Flags: u32 {
53-
/// static FlagA = 0x00000001,
54-
/// static FlagB = 0x00000010,
53+
/// static FLAG_A = 0x00000001,
54+
/// static FLAG_B = 0x00000010,
5555
/// }
5656
/// }
5757
///
@@ -69,7 +69,7 @@
6969
/// }
7070
///
7171
/// fn main() {
72-
/// let mut flags = FlagA | FlagB;
72+
/// let mut flags = FLAG_A | FLAG_B;
7373
/// flags.clear();
7474
/// assert!(flags.is_empty());
7575
/// assert_eq!(format!("{}", flags).as_slice(), "hi!");
@@ -123,10 +123,7 @@ macro_rules! bitflags {
123123
bits: $T,
124124
}
125125

126-
$(
127-
#[allow(non_uppercase_statics)]
128-
$(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value };
129-
)+
126+
$($(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value };)+
130127

131128
impl $BitFlags {
132129
/// Returns an empty set of flags.
@@ -243,16 +240,14 @@ macro_rules! bitflags {
243240
bitflags! {
244241
$(#[$attr])*
245242
flags $BitFlags: $T {
246-
$(
247-
#[allow(non_uppercase_statics)]
248-
$(#[$Flag_attr])* static $Flag = $value
249-
),+
243+
$($(#[$Flag_attr])* static $Flag = $value),+
250244
}
251245
}
252246
};
253247
}
254248

255249
#[cfg(test)]
250+
#[allow(non_uppercase_statics)]
256251
mod tests {
257252
use hash;
258253
use option::{Some, None};

src/libsyntax/parse/parser.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ use std::iter;
9191

9292
bitflags! {
9393
flags Restrictions: u8 {
94-
static Unrestricted = 0b0000,
95-
static RestrictionStmtExpr = 0b0001,
96-
static RestrictionNoBarOp = 0b0010,
97-
static RestrictionNoStructLiteral = 0b0100
94+
static UNRESTRICTED = 0b0000,
95+
static RESTRICTION_STMT_EXPR = 0b0001,
96+
static RESTRICTION_NO_BAR_OP = 0b0010,
97+
static RESTRICTION_NO_STRUCT_LITERAL = 0b0100
9898
}
9999
}
100100

@@ -383,7 +383,7 @@ impl<'a> Parser<'a> {
383383
buffer_start: 0,
384384
buffer_end: 0,
385385
tokens_consumed: 0,
386-
restrictions: Unrestricted,
386+
restrictions: UNRESTRICTED,
387387
quote_depth: 0,
388388
obsolete_set: HashSet::new(),
389389
mod_path_stack: Vec::new(),
@@ -2242,7 +2242,7 @@ impl<'a> Parser<'a> {
22422242
if self.token == token::LBRACE {
22432243
// This is a struct literal, unless we're prohibited
22442244
// from parsing struct literals here.
2245-
if !self.restrictions.contains(RestrictionNoStructLiteral) {
2245+
if !self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL) {
22462246
// It's a struct literal.
22472247
self.bump();
22482248
let mut fields = Vec::new();
@@ -2771,7 +2771,7 @@ impl<'a> Parser<'a> {
27712771
// Prevent dynamic borrow errors later on by limiting the
27722772
// scope of the borrows.
27732773
if self.token == token::BINOP(token::OR) &&
2774-
self.restrictions.contains(RestrictionNoBarOp) {
2774+
self.restrictions.contains(RESTRICTION_NO_BAR_OP) {
27752775
return lhs;
27762776
}
27772777

@@ -2812,7 +2812,7 @@ impl<'a> Parser<'a> {
28122812
pub fn parse_assign_expr(&mut self) -> P<Expr> {
28132813
let lo = self.span.lo;
28142814
let lhs = self.parse_binops();
2815-
let restrictions = self.restrictions & RestrictionNoStructLiteral;
2815+
let restrictions = self.restrictions & RESTRICTION_NO_STRUCT_LITERAL;
28162816
match self.token {
28172817
token::EQ => {
28182818
self.bump();
@@ -2850,7 +2850,7 @@ impl<'a> Parser<'a> {
28502850
return self.parse_if_let_expr();
28512851
}
28522852
let lo = self.last_span.lo;
2853-
let cond = self.parse_expr_res(RestrictionNoStructLiteral);
2853+
let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
28542854
let thn = self.parse_block();
28552855
let mut els: Option<P<Expr>> = None;
28562856
let mut hi = thn.span.hi;
@@ -2868,7 +2868,7 @@ impl<'a> Parser<'a> {
28682868
self.expect_keyword(keywords::Let);
28692869
let pat = self.parse_pat();
28702870
self.expect(&token::EQ);
2871-
let expr = self.parse_expr_res(RestrictionNoStructLiteral);
2871+
let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
28722872
let thn = self.parse_block();
28732873
let (hi, els) = if self.eat_keyword(keywords::Else) {
28742874
let expr = self.parse_else_expr();
@@ -2928,7 +2928,7 @@ impl<'a> Parser<'a> {
29282928
let lo = self.last_span.lo;
29292929
let pat = self.parse_pat();
29302930
self.expect_keyword(keywords::In);
2931-
let expr = self.parse_expr_res(RestrictionNoStructLiteral);
2931+
let expr = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
29322932
let loop_block = self.parse_block();
29332933
let hi = self.span.hi;
29342934

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

29382938
pub fn parse_while_expr(&mut self, opt_ident: Option<ast::Ident>) -> P<Expr> {
29392939
let lo = self.last_span.lo;
2940-
let cond = self.parse_expr_res(RestrictionNoStructLiteral);
2940+
let cond = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
29412941
let body = self.parse_block();
29422942
let hi = body.span.hi;
29432943
return self.mk_expr(lo, hi, ExprWhile(cond, body, opt_ident));
@@ -2952,7 +2952,7 @@ impl<'a> Parser<'a> {
29522952

29532953
fn parse_match_expr(&mut self) -> P<Expr> {
29542954
let lo = self.last_span.lo;
2955-
let discriminant = self.parse_expr_res(RestrictionNoStructLiteral);
2955+
let discriminant = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL);
29562956
self.commit_expr_expecting(&*discriminant, token::LBRACE);
29572957
let mut arms: Vec<Arm> = Vec::new();
29582958
while self.token != token::RBRACE {
@@ -2971,7 +2971,7 @@ impl<'a> Parser<'a> {
29712971
guard = Some(self.parse_expr());
29722972
}
29732973
self.expect(&token::FAT_ARROW);
2974-
let expr = self.parse_expr_res(RestrictionStmtExpr);
2974+
let expr = self.parse_expr_res(RESTRICTION_STMT_EXPR);
29752975

29762976
let require_comma =
29772977
!classify::expr_is_simple_block(&*expr)
@@ -2993,7 +2993,7 @@ impl<'a> Parser<'a> {
29932993

29942994
/// Parse an expression
29952995
pub fn parse_expr(&mut self) -> P<Expr> {
2996-
return self.parse_expr_res(Unrestricted);
2996+
return self.parse_expr_res(UNRESTRICTED);
29972997
}
29982998

29992999
/// Parse an expression, subject to the given restrictions
@@ -3290,9 +3290,9 @@ impl<'a> Parser<'a> {
32903290
self.look_ahead(2, |t| {
32913291
*t != token::COMMA && *t != token::RBRACKET
32923292
}) {
3293-
let start = self.parse_expr_res(RestrictionNoBarOp);
3293+
let start = self.parse_expr_res(RESTRICTION_NO_BAR_OP);
32943294
self.eat(&token::DOTDOTDOT);
3295-
let end = self.parse_expr_res(RestrictionNoBarOp);
3295+
let end = self.parse_expr_res(RESTRICTION_NO_BAR_OP);
32963296
pat = PatRange(start, end);
32973297
} else if is_plain_ident(&self.token) && !can_be_enum_or_struct {
32983298
let id = self.parse_ident();
@@ -3593,7 +3593,7 @@ impl<'a> Parser<'a> {
35933593
}
35943594

35953595
// Remainder are line-expr stmts.
3596-
let e = self.parse_expr_res(RestrictionStmtExpr);
3596+
let e = self.parse_expr_res(RESTRICTION_STMT_EXPR);
35973597
P(spanned(lo, e.span.hi, StmtExpr(e, ast::DUMMY_NODE_ID)))
35983598
}
35993599
}
@@ -3602,7 +3602,7 @@ impl<'a> Parser<'a> {
36023602

36033603
/// Is this expression a successfully-parsed statement?
36043604
fn expr_is_complete(&mut self, e: &Expr) -> bool {
3605-
self.restrictions.contains(RestrictionStmtExpr) &&
3605+
self.restrictions.contains(RESTRICTION_STMT_EXPR) &&
36063606
!classify::expr_requires_semi_to_be_stmt(e)
36073607
}
36083608

0 commit comments

Comments
 (0)