diff --git a/src/librustc/front/map/mod.rs b/src/librustc/front/map/mod.rs index 44f588c2e9ca0e9d379d3f47f7f561cf901bd188..dfc8560b58de0268dd3fb09ebf3327e117e6b0e7 100644 --- a/src/librustc/front/map/mod.rs +++ b/src/librustc/front/map/mod.rs @@ -22,6 +22,7 @@ use syntax::abi::Abi; use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID}; +use syntax::attr::ThinAttributesExt; use syntax::codemap::{Span, Spanned}; use syntax::parse::token; @@ -718,6 +719,8 @@ pub fn attrs(&self, id: NodeId) -> &'ast [ast::Attribute] { Some(NodeTraitItem(ref ti)) => Some(&ti.attrs[..]), Some(NodeImplItem(ref ii)) => Some(&ii.attrs[..]), Some(NodeVariant(ref v)) => Some(&v.node.attrs[..]), + Some(NodeExpr(ref e)) => Some(e.attrs.as_attr_slice()), + Some(NodeStmt(ref s)) => Some(s.node.attrs()), // unit/tuple structs take the attributes straight from // the struct definition. Some(NodeStructCtor(_)) => { diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index 43a9ac23a95ed2f0ebb8333150b92d0b2ab6692a..ee530677b60cd7ffb26dcb858c879156cacc4953 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -39,7 +39,7 @@ use syntax::abi::Abi; use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect}; use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem}; -use syntax::attr::ThinAttributes; +use syntax::attr::{ThinAttributes, ThinAttributesExt}; use syntax::parse::token::InternedString; use syntax::ptr::P; @@ -635,6 +635,16 @@ pub enum Stmt_ { StmtSemi(P, NodeId), } +impl Stmt_ { + pub fn attrs(&self) -> &[Attribute] { + match *self { + StmtDecl(ref d, _) => d.node.attrs(), + StmtExpr(ref e, _) | + StmtSemi(ref e, _) => e.attrs.as_attr_slice(), + } + } +} + // FIXME (pending discussion of #1697, #2178...): local should really be // a refinement on pat. /// Local represents a `let` statement, e.g., `let : = ;` @@ -659,6 +669,15 @@ pub enum Decl_ { DeclItem(ItemId), } +impl Decl_ { + pub fn attrs(&self) -> &[Attribute] { + match *self { + DeclLocal(ref l) => l.attrs.as_attr_slice(), + DeclItem(_) => &[] + } + } +} + /// represents one arm of a 'match' #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub struct Arm {