Skip to content

Commit f47d7c7

Browse files
committed
hir_map: Provide expression and statement attributes.
1 parent ad5aff5 commit f47d7c7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/librustc/front/map/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use middle::def_id::DefId;
2222

2323
use syntax::abi::Abi;
2424
use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID};
25+
use syntax::attr::ThinAttributesExt;
2526
use syntax::codemap::{Span, Spanned};
2627
use syntax::parse::token;
2728

@@ -718,6 +719,8 @@ impl<'ast> Map<'ast> {
718719
Some(NodeTraitItem(ref ti)) => Some(&ti.attrs[..]),
719720
Some(NodeImplItem(ref ii)) => Some(&ii.attrs[..]),
720721
Some(NodeVariant(ref v)) => Some(&v.node.attrs[..]),
722+
Some(NodeExpr(ref e)) => Some(e.attrs.as_attr_slice()),
723+
Some(NodeStmt(ref s)) => Some(s.node.attrs()),
721724
// unit/tuple structs take the attributes straight from
722725
// the struct definition.
723726
Some(NodeStructCtor(_)) => {

src/librustc_front/hir.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId};
3939
use syntax::abi::Abi;
4040
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
4141
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};
42-
use syntax::attr::ThinAttributes;
42+
use syntax::attr::{ThinAttributes, ThinAttributesExt};
4343
use syntax::parse::token::InternedString;
4444
use syntax::ptr::P;
4545

@@ -635,6 +635,16 @@ pub enum Stmt_ {
635635
StmtSemi(P<Expr>, NodeId),
636636
}
637637

638+
impl Stmt_ {
639+
pub fn attrs(&self) -> &[Attribute] {
640+
match *self {
641+
StmtDecl(ref d, _) => d.node.attrs(),
642+
StmtExpr(ref e, _) |
643+
StmtSemi(ref e, _) => e.attrs.as_attr_slice(),
644+
}
645+
}
646+
}
647+
638648
// FIXME (pending discussion of #1697, #2178...): local should really be
639649
// a refinement on pat.
640650
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`
@@ -659,6 +669,15 @@ pub enum Decl_ {
659669
DeclItem(ItemId),
660670
}
661671

672+
impl Decl_ {
673+
pub fn attrs(&self) -> &[Attribute] {
674+
match *self {
675+
DeclLocal(ref l) => l.attrs.as_attr_slice(),
676+
DeclItem(_) => &[]
677+
}
678+
}
679+
}
680+
662681
/// represents one arm of a 'match'
663682
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
664683
pub struct Arm {

0 commit comments

Comments
 (0)