diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index a490b58964a..e9d2aa7e775 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -405,7 +405,7 @@ pub fn gather_attr(attr: &ast::Attribute) attr::mark_used(attr); - let meta = &attr.node.value; + let meta = &attr.value; let metas = if let Some(metas) = meta.meta_item_list() { metas } else { diff --git a/src/librustc_incremental/calculate_svh/svh_visitor.rs b/src/librustc_incremental/calculate_svh/svh_visitor.rs index a1ece48462b..21c628d18ba 100644 --- a/src/librustc_incremental/calculate_svh/svh_visitor.rs +++ b/src/librustc_incremental/calculate_svh/svh_visitor.rs @@ -914,7 +914,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> { let indices = self.indices_sorted_by(attributes, |attr| attr.name()); for i in indices { - let attr = &attributes[i].node; + let attr = &attributes[i]; if !attr.is_sugared_doc && !IGNORED_ATTRIBUTES.contains(&&*attr.value.name()) { SawAttribute(attr.style).hash(self.st); diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 0668d362037..aaca823369b 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -277,7 +277,7 @@ impl LateLintPass for UnusedAttributes { .find(|&&(ref x, t)| &*attr.name() == x && AttributeType::CrateLevel == t) .is_some(); if known_crate || plugin_crate { - let msg = match attr.node.style { + let msg = match attr.style { ast::AttrStyle::Outer => { "crate-level attribute should be an inner attribute: add an exclamation \ mark: #![foo]" diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 3af9d291ae5..fb1314992c0 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -934,7 +934,7 @@ impl<'a, 'tcx> CrateMetadata { .decode(self) .map(|mut attr| { // Need new unique IDs: old thread-local IDs won't map to new threads. - attr.node.id = attr::mk_attr_id(); + attr.id = attr::mk_attr_id(); attr }) .collect() diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 3bdaf276b40..dafb7bc6e60 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -240,7 +240,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_assoc_type_binding(self, type_binding) } fn visit_attribute(&mut self, attr: &'v ast::Attribute) { - self.record("Attribute", Id::Attr(attr.node.id), attr); + self.record("Attribute", Id::Attr(attr.id), attr); } fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef) { self.record("MacroDef", Id::Node(macro_def.id), macro_def); diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 627c72ff8c9..5d743fc5d4e 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -607,7 +607,7 @@ impl<'b> Resolver<'b> { if attr.check_name("macro_escape") { let msg = "macro_escape is a deprecated synonym for macro_use"; let mut err = self.session.struct_span_warn(attr.span, msg); - if let ast::AttrStyle::Inner = attr.node.style { + if let ast::AttrStyle::Inner = attr.style { err.help("consider an outer attribute, #[macro_use] mod ...").emit(); } else { err.emit(); diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 778f0184141..c8e350e475a 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -734,7 +734,7 @@ fn docs_for_attrs(attrs: &[Attribute]) -> String { for attr in attrs { if attr.name() == doc { if let Some(ref val) = attr.value_str() { - if attr.node.is_sugared_doc { + if attr.is_sugared_doc { result.push_str(&strip_doc_comment_decoration(val)); } else { result.push_str(val); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f5cd089e923..bc6d21cab64 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1755,8 +1755,6 @@ impl ViewPath_ { } } -/// Meta-data associated with an item -pub type Attribute = Spanned; /// Distinguishes between Attributes that decorate items and Attributes that /// are contained as statements within items. These two cases need to be @@ -1770,13 +1768,15 @@ pub enum AttrStyle { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)] pub struct AttrId(pub usize); +/// Meta-data associated with an item /// Doc-comments are promoted to attributes that have is_sugared_doc = true #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] -pub struct Attribute_ { +pub struct Attribute { pub id: AttrId, pub style: AttrStyle, pub value: P, pub is_sugared_doc: bool, + pub span: Span, } /// TraitRef's appear in impls. diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 2977e340a3c..8f3ef0e16df 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -15,10 +15,10 @@ pub use self::ReprAttr::*; pub use self::IntType::*; use ast; -use ast::{AttrId, Attribute, Attribute_}; +use ast::{AttrId, Attribute}; use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind}; use ast::{Lit, Expr, Item, Local, Stmt, StmtKind}; -use codemap::{respan, spanned, dummy_spanned}; +use codemap::{respan, spanned, dummy_spanned, mk_sp}; use syntax_pos::{Span, BytePos, DUMMY_SP}; use errors::Handler; use feature_gate::{Features, GatedCfg}; @@ -61,7 +61,7 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError) { pub fn mark_used(attr: &Attribute) { debug!("Marking {:?} as used.", attr); - let AttrId(id) = attr.node.id; + let AttrId(id) = attr.id; USED_ATTRS.with(|slot| { let idx = (id / 64) as usize; let shift = id % 64; @@ -73,7 +73,7 @@ pub fn mark_used(attr: &Attribute) { } pub fn is_used(attr: &Attribute) -> bool { - let AttrId(id) = attr.node.id; + let AttrId(id) = attr.id; USED_ATTRS.with(|slot| { let idx = (id / 64) as usize; let shift = id % 64; @@ -84,7 +84,7 @@ pub fn is_used(attr: &Attribute) -> bool { pub fn mark_known(attr: &Attribute) { debug!("Marking {:?} as known.", attr); - let AttrId(id) = attr.node.id; + let AttrId(id) = attr.id; KNOWN_ATTRS.with(|slot| { let idx = (id / 64) as usize; let shift = id % 64; @@ -96,7 +96,7 @@ pub fn mark_known(attr: &Attribute) { } pub fn is_known(attr: &Attribute) -> bool { - let AttrId(id) = attr.node.id; + let AttrId(id) = attr.id; KNOWN_ATTRS.with(|slot| { let idx = (id / 64) as usize; let shift = id % 64; @@ -270,7 +270,7 @@ impl MetaItem { impl Attribute { /// Extract the MetaItem from inside this Attribute. pub fn meta(&self) -> &MetaItem { - &self.node.value + &self.value } /// Convert self to a normal #[doc="foo"] comment, if it is a @@ -279,16 +279,16 @@ impl Attribute { pub fn with_desugared_doc(&self, f: F) -> T where F: FnOnce(&Attribute) -> T, { - if self.node.is_sugared_doc { + if self.is_sugared_doc { let comment = self.value_str().unwrap(); let meta = mk_name_value_item_str( InternedString::new("doc"), token::intern_and_get_ident(&strip_doc_comment_decoration( &comment))); - if self.node.style == ast::AttrStyle::Outer { - f(&mk_attr_outer(self.node.id, meta)) + if self.style == ast::AttrStyle::Outer { + f(&mk_attr_outer(self.id, meta)) } else { - f(&mk_attr_inner(self.node.id, meta)) + f(&mk_attr_inner(self.id, meta)) } } else { f(self) @@ -355,13 +355,13 @@ pub fn mk_attr_inner(id: AttrId, item: P) -> Attribute { /// Returns an innter attribute with the given value and span. pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: P) -> Attribute { - respan(sp, - Attribute_ { - id: id, - style: ast::AttrStyle::Inner, - value: item, - is_sugared_doc: false, - }) + Attribute { + id: id, + style: ast::AttrStyle::Inner, + value: item, + is_sugared_doc: false, + span: sp, + } } @@ -372,36 +372,36 @@ pub fn mk_attr_outer(id: AttrId, item: P) -> Attribute { /// Returns an outer attribute with the given value and span. pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: P) -> Attribute { - respan(sp, - Attribute_ { - id: id, - style: ast::AttrStyle::Outer, - value: item, - is_sugared_doc: false, - }) + Attribute { + id: id, + style: ast::AttrStyle::Outer, + value: item, + is_sugared_doc: false, + span: sp, + } } pub fn mk_doc_attr_outer(id: AttrId, item: P, is_sugared_doc: bool) -> Attribute { - dummy_spanned(Attribute_ { + Attribute { id: id, style: ast::AttrStyle::Outer, value: item, is_sugared_doc: is_sugared_doc, - }) + span: DUMMY_SP, + } } -pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, - hi: BytePos) +pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: BytePos) -> Attribute { let style = doc_comment_style(&text); let lit = spanned(lo, hi, ast::LitKind::Str(text, ast::StrStyle::Cooked)); - let attr = Attribute_ { + Attribute { id: id, style: style, value: P(spanned(lo, hi, MetaItemKind::NameValue(InternedString::new("doc"), lit))), - is_sugared_doc: true - }; - spanned(lo, hi, attr) + is_sugared_doc: true, + span: mk_sp(lo, hi), + } } /* Searching */ @@ -489,7 +489,7 @@ pub enum InlineAttr { /// Determine what `#[inline]` attribute is present in `attrs`, if any. pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr { attrs.iter().fold(InlineAttr::None, |ia,attr| { - match attr.node.value.node { + match attr.value.node { MetaItemKind::Word(ref n) if n == "inline" => { mark_used(attr); InlineAttr::Hint @@ -896,7 +896,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P]) { /// structure layout, and `packed` to remove padding. pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec { let mut acc = Vec::new(); - match attr.node.value.node { + match attr.value.node { ast::MetaItemKind::List(ref s, ref items) if s == "repr" => { mark_used(attr); for item in items { diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 02429f02738..e83606200f8 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -12,7 +12,7 @@ use attr::HasAttrs; use feature_gate::{feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features, GateIssue}; use {fold, attr}; use ast; -use codemap::{Spanned, respan}; +use codemap::Spanned; use parse::ParseSess; use ptr::P; @@ -106,12 +106,13 @@ impl<'a> StripUnconfigured<'a> { match (cfg.meta_item(), mi.meta_item()) { (Some(cfg), Some(mi)) => if cfg_matches(&cfg, self.sess, self.features) { - self.process_cfg_attr(respan(mi.span, ast::Attribute_ { + self.process_cfg_attr(ast::Attribute { id: attr::mk_attr_id(), - style: attr.node.style, + style: attr.style, value: mi.clone(), is_sugared_doc: false, - })) + span: mi.span, + }) } else { None }, @@ -131,7 +132,7 @@ impl<'a> StripUnconfigured<'a> { return false; } - let mis = match attr.node.value.node { + let mis = match attr.value.node { ast::MetaItemKind::List(_, ref mis) if is_cfg(&attr) => mis, _ => return true }; @@ -160,7 +161,7 @@ impl<'a> StripUnconfigured<'a> { attr.span, GateIssue::Language, EXPLAIN_STMT_ATTR_SYNTAX); - if attr.node.is_sugared_doc { + if attr.is_sugared_doc { err.help("`///` is for documentation comments. For a plain comment, use `//`."); } err.emit(); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 8e0c3ce8448..841a6bb1b06 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -353,12 +353,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> { match *ext { MultiModifier(ref mac) => { - let item = mac.expand(self.cx, attr.span, &attr.node.value, item); + let item = mac.expand(self.cx, attr.span, &attr.value, item); kind.expect_from_annotatables(item) } MultiDecorator(ref mac) => { let mut items = Vec::new(); - mac.expand(self.cx, attr.span, &attr.node.value, &item, + mac.expand(self.cx, attr.span, &attr.value, &item, &mut |item| items.push(item)); items.push(item); kind.expect_from_annotatables(items) diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 969cfa292ce..4386dbeb834 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -223,13 +223,13 @@ pub mod rt { let mut r = vec![]; // FIXME: The spans could be better r.push(TokenTree::Token(self.span, token::Pound)); - if self.node.style == ast::AttrStyle::Inner { + if self.style == ast::AttrStyle::Inner { r.push(TokenTree::Token(self.span, token::Not)); } r.push(TokenTree::Delimited(self.span, Rc::new(tokenstream::Delimited { delim: token::Bracket, open_span: self.span, - tts: self.node.value.to_tokens(cx), + tts: self.value.to_tokens(cx), close_span: self.span, }))); r diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index ea66fdc31cf..2416ead1224 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1013,7 +1013,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> { self.context.check_attribute(attr, false); } - if contains_novel_literal(&*(attr.node.value)) { + if contains_novel_literal(&*(attr.value)) { gate_feature_post!(&self, attr_literals, attr.span, "non-string literals in attributes, or string \ literals in top-level positions, are experimental"); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 2e62f23578d..aac99e4e513 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -486,16 +486,13 @@ pub fn noop_fold_local(l: P, fld: &mut T) -> P { }) } -pub fn noop_fold_attribute(at: Attribute, fld: &mut T) -> Option { - let Spanned {node: Attribute_ {id, style, value, is_sugared_doc}, span} = at; - Some(Spanned { - node: Attribute_ { - id: id, - style: style, - value: fld.fold_meta_item(value), - is_sugared_doc: is_sugared_doc - }, - span: fld.new_span(span) +pub fn noop_fold_attribute(attr: Attribute, fld: &mut T) -> Option { + Some(Attribute { + id: attr.id, + style: attr.style, + value: fld.fold_meta_item(attr.value), + is_sugared_doc: attr.is_sugared_doc, + span: fld.new_span(attr.span), }) } diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 983c882eafc..8818b94209e 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -11,7 +11,7 @@ use attr; use ast; use syntax_pos::{mk_sp, Span}; -use codemap::{spanned, Spanned}; +use codemap::spanned; use parse::common::SeqSep; use parse::PResult; use parse::token; @@ -55,7 +55,7 @@ impl<'a> Parser<'a> { self.span.lo, self.span.hi ); - if attr.node.style != ast::AttrStyle::Outer { + if attr.style != ast::AttrStyle::Outer { let mut err = self.fatal("expected outer doc comment"); err.note("inner doc comments like this (starting with \ `//!` or `/*!`) can only appear before items"); @@ -145,14 +145,12 @@ impl<'a> Parser<'a> { style = ast::AttrStyle::Inner; } - Ok(Spanned { + Ok(ast::Attribute { + id: attr::mk_attr_id(), + style: style, + value: value, + is_sugared_doc: false, span: span, - node: ast::Attribute_ { - id: attr::mk_attr_id(), - style: style, - value: value, - is_sugared_doc: false, - }, }) } @@ -172,7 +170,7 @@ impl<'a> Parser<'a> { } let attr = self.parse_attribute(true)?; - assert!(attr.node.style == ast::AttrStyle::Inner); + assert!(attr.style == ast::AttrStyle::Inner); attrs.push(attr); } token::DocComment(s) => { @@ -180,7 +178,7 @@ impl<'a> Parser<'a> { let Span { lo, hi, .. } = self.span; let str = self.id_to_interned_str(ast::Ident::with_empty_ctxt(s)); let attr = attr::mk_sugared_doc_attr(attr::mk_attr_id(), str, lo, hi); - if attr.node.style == ast::AttrStyle::Inner { + if attr.style == ast::AttrStyle::Inner { attrs.push(attr); self.bump(); } else { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2e38ca82d5d..98ce00c7d38 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3751,9 +3751,7 @@ impl<'a> Parser<'a> { /// Emit an expected item after attributes error. fn expected_item_err(&self, attrs: &[Attribute]) { let message = match attrs.last() { - Some(&Attribute { node: ast::Attribute_ { is_sugared_doc: true, .. }, .. }) => { - "expected item after doc comment" - } + Some(&Attribute { is_sugared_doc: true, .. }) => "expected item after doc comment", _ => "expected item after attributes", }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 203c19285ac..ea4a9177d42 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -727,7 +727,7 @@ pub trait PrintState<'a> { trailing_hardbreak: bool) -> io::Result<()> { let mut count = 0; for attr in attrs { - if attr.node.style == kind { + if attr.style == kind { try!(self.print_attribute_inline(attr, is_inline)); if is_inline { try!(self.nbsp()); @@ -751,11 +751,11 @@ pub trait PrintState<'a> { try!(self.hardbreak_if_not_bol()); } try!(self.maybe_print_comment(attr.span.lo)); - if attr.node.is_sugared_doc { + if attr.is_sugared_doc { try!(word(self.writer(), &attr.value_str().unwrap())); hardbreak(self.writer()) } else { - match attr.node.style { + match attr.style { ast::AttrStyle::Inner => try!(word(self.writer(), "#![")), ast::AttrStyle::Outer => try!(word(self.writer(), "#[")), } diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 1b63a2b7076..f0cfd42c824 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -68,15 +68,13 @@ pub fn maybe_inject_crates_ref(sess: &ParseSess, let span = ignored_span(sess, DUMMY_SP); krate.module.items.insert(0, P(ast::Item { attrs: vec![ast::Attribute { - node: ast::Attribute_ { - style: ast::AttrStyle::Outer, - value: P(ast::MetaItem { - node: ast::MetaItemKind::Word(token::intern_and_get_ident("prelude_import")), - span: span, - }), - id: attr::mk_attr_id(), - is_sugared_doc: false, - }, + style: ast::AttrStyle::Outer, + value: P(ast::MetaItem { + node: ast::MetaItemKind::Word(token::intern_and_get_ident("prelude_import")), + span: span, + }), + id: attr::mk_attr_id(), + is_sugared_doc: false, span: span, }], vis: ast::Visibility::Inherited, diff --git a/src/libsyntax_ext/deriving/mod.rs b/src/libsyntax_ext/deriving/mod.rs index b1d473820f7..09d529f5313 100644 --- a/src/libsyntax_ext/deriving/mod.rs +++ b/src/libsyntax_ext/deriving/mod.rs @@ -135,7 +135,7 @@ pub fn expand_derive(cx: &mut ExtCtxt, let mut traits = get_traits(mitem, cx); for derive_attr in derive_attrs { - traits.extend(get_traits(&derive_attr.node.value, cx)); + traits.extend(get_traits(&derive_attr.value, cx)); } // First, weed out malformed #[derive]