From cfd768e2e69a3ca8f28d7bc49f2ae3ca744841c8 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Thu, 10 Mar 2016 04:12:36 +0200 Subject: hir_map: Provide expression and statement attributes. --- src/librustc_front/hir.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/librustc_front') diff --git a/src/librustc_front/hir.rs b/src/librustc_front/hir.rs index 43a9ac23a95..ee530677b60 100644 --- a/src/librustc_front/hir.rs +++ b/src/librustc_front/hir.rs @@ -39,7 +39,7 @@ use syntax::codemap::{self, Span, Spanned, DUMMY_SP, ExpnId}; 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 { -- cgit 1.4.1-3-g733a5