diff options
| author | bors <bors@rust-lang.org> | 2014-04-23 23:51:30 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-04-23 23:51:30 -0700 |
| commit | 867898977d30a79ef19d5588c1632f48e75cb98f (patch) | |
| tree | fadd42a856cb56ccc07a66920331eb19a5a4d331 /src/libsyntax | |
| parent | 4e1a09844e49a91d0f9dea19561f15d34992d0e8 (diff) | |
| parent | 1452c9c04a11dd6ad6890b811b411ef80b0c5b6f (diff) | |
| download | rust-867898977d30a79ef19d5588c1632f48e75cb98f.tar.gz rust-867898977d30a79ef19d5588c1632f48e75cb98f.zip | |
auto merge of #12812 : sfackler/rust/attr-arm, r=alexcrichton
This is really only useful for #[cfg()]. For example:
```rust
enum Foo {
Bar,
Baz,
#[cfg(blob)]
Blob
}
fn match_foos(f: &Foo) {
match *f {
Bar => {}
Baz => {}
#[cfg(blob)]
Blob => {}
}
}
```
This is a kind of weird place to allow attributes, so it should probably
be discussed before merging.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/build.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/primitive.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 7 |
6 files changed, 18 insertions, 2 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 116411c9e05..4a93fed8d03 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -440,6 +440,7 @@ pub enum Decl_ { #[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)] pub struct Arm { + pub attrs: Vec<Attribute>, pub pats: Vec<@Pat>, pub guard: Option<@Expr>, pub body: @Expr, diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index e1174ea6cc4..b0dbd8b635a 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -726,6 +726,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { fn arm(&self, _span: Span, pats: Vec<@ast::Pat> , expr: @ast::Expr) -> ast::Arm { ast::Arm { + attrs: vec!(), pats: pats, guard: None, body: expr diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index 0a7aa591657..9978a2edce9 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -112,6 +112,7 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure // arm for `_ if $guard => $body` let arm = ast::Arm { + attrs: vec!(), pats: vec!(cx.pat_wild(span)), guard: Some(guard), body: body, @@ -131,6 +132,7 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure // arm for `_ => None` let arm = ast::Arm { + attrs: vec!(), pats: vec!(cx.pat_wild(trait_span)), guard: None, body: cx.expr_none(trait_span), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 04b289b9fca..9f05db5f807 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -119,6 +119,7 @@ pub trait Folder { fn fold_arm(&mut self, a: &Arm) -> Arm { Arm { + attrs: a.attrs.iter().map(|x| fold_attribute_(*x, self)).collect(), pats: a.pats.iter().map(|x| self.fold_pat(*x)).collect(), guard: a.guard.map(|x| self.fold_expr(x)), body: self.fold_expr(a.body), diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8808312bed7..f30d756d854 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2539,6 +2539,7 @@ impl<'a> Parser<'a> { self.commit_expr_expecting(discriminant, token::LBRACE); let mut arms: Vec<Arm> = Vec::new(); while self.token != token::RBRACE { + let attrs = self.parse_outer_attributes(); let pats = self.parse_pats(); let mut guard = None; if self.eat_keyword(keywords::If) { @@ -2557,7 +2558,12 @@ impl<'a> Parser<'a> { self.eat(&token::COMMA); } - arms.push(ast::Arm { pats: pats, guard: guard, body: expr }); + arms.push(ast::Arm { + attrs: attrs, + pats: pats, + guard: guard, + body: expr + }); } let hi = self.span.hi; self.bump(); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f768bf22ce0..b0130f127a3 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1286,9 +1286,14 @@ impl<'a> State<'a> { try!(self.bopen()); let len = arms.len(); for (i, arm) in arms.iter().enumerate() { - try!(space(&mut self.s)); + // I have no idea why this check is necessary, but here it + // is :( + if arm.attrs.is_empty() { + try!(space(&mut self.s)); + } try!(self.cbox(indent_unit)); try!(self.ibox(0u)); + try!(self.print_outer_attributes(arm.attrs.as_slice())); let mut first = true; for p in arm.pats.iter() { if first { |
