Skip to content

Commit 3ea2bc4

Browse files
committed
Refactor away ast::Attribute_.
1 parent bfa709a commit 3ea2bc4

File tree

19 files changed

+85
-93
lines changed

19 files changed

+85
-93
lines changed

src/librustc/lint/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ pub fn gather_attr(attr: &ast::Attribute)
405405

406406
attr::mark_used(attr);
407407

408-
let meta = &attr.node.value;
408+
let meta = &attr.value;
409409
let metas = if let Some(metas) = meta.meta_item_list() {
410410
metas
411411
} else {

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
914914
let indices = self.indices_sorted_by(attributes, |attr| attr.name());
915915

916916
for i in indices {
917-
let attr = &attributes[i].node;
917+
let attr = &attributes[i];
918918
if !attr.is_sugared_doc &&
919919
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name()) {
920920
SawAttribute(attr.style).hash(self.st);

src/librustc_lint/unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ impl LateLintPass for UnusedAttributes {
277277
.find(|&&(ref x, t)| &*attr.name() == x && AttributeType::CrateLevel == t)
278278
.is_some();
279279
if known_crate || plugin_crate {
280-
let msg = match attr.node.style {
280+
let msg = match attr.style {
281281
ast::AttrStyle::Outer => {
282282
"crate-level attribute should be an inner attribute: add an exclamation \
283283
mark: #![foo]"

src/librustc_metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ impl<'a, 'tcx> CrateMetadata {
934934
.decode(self)
935935
.map(|mut attr| {
936936
// Need new unique IDs: old thread-local IDs won't map to new threads.
937-
attr.node.id = attr::mk_attr_id();
937+
attr.id = attr::mk_attr_id();
938938
attr
939939
})
940940
.collect()

src/librustc_passes/hir_stats.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
240240
hir_visit::walk_assoc_type_binding(self, type_binding)
241241
}
242242
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
243-
self.record("Attribute", Id::Attr(attr.node.id), attr);
243+
self.record("Attribute", Id::Attr(attr.id), attr);
244244
}
245245
fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef) {
246246
self.record("MacroDef", Id::Node(macro_def.id), macro_def);

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ impl<'b> Resolver<'b> {
607607
if attr.check_name("macro_escape") {
608608
let msg = "macro_escape is a deprecated synonym for macro_use";
609609
let mut err = self.session.struct_span_warn(attr.span, msg);
610-
if let ast::AttrStyle::Inner = attr.node.style {
610+
if let ast::AttrStyle::Inner = attr.style {
611611
err.help("consider an outer attribute, #[macro_use] mod ...").emit();
612612
} else {
613613
err.emit();

src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ fn docs_for_attrs(attrs: &[Attribute]) -> String {
734734
for attr in attrs {
735735
if attr.name() == doc {
736736
if let Some(ref val) = attr.value_str() {
737-
if attr.node.is_sugared_doc {
737+
if attr.is_sugared_doc {
738738
result.push_str(&strip_doc_comment_decoration(val));
739739
} else {
740740
result.push_str(val);

src/libsyntax/ast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,8 +1755,6 @@ impl ViewPath_ {
17551755
}
17561756
}
17571757

1758-
/// Meta-data associated with an item
1759-
pub type Attribute = Spanned<Attribute_>;
17601758

17611759
/// Distinguishes between Attributes that decorate items and Attributes that
17621760
/// are contained as statements within items. These two cases need to be
@@ -1770,13 +1768,15 @@ pub enum AttrStyle {
17701768
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
17711769
pub struct AttrId(pub usize);
17721770

1771+
/// Meta-data associated with an item
17731772
/// Doc-comments are promoted to attributes that have is_sugared_doc = true
17741773
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1775-
pub struct Attribute_ {
1774+
pub struct Attribute {
17761775
pub id: AttrId,
17771776
pub style: AttrStyle,
17781777
pub value: P<MetaItem>,
17791778
pub is_sugared_doc: bool,
1779+
pub span: Span,
17801780
}
17811781

17821782
/// TraitRef's appear in impls.

src/libsyntax/attr.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ pub use self::ReprAttr::*;
1515
pub use self::IntType::*;
1616

1717
use ast;
18-
use ast::{AttrId, Attribute, Attribute_};
18+
use ast::{AttrId, Attribute};
1919
use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
2020
use ast::{Lit, Expr, Item, Local, Stmt, StmtKind};
21-
use codemap::{respan, spanned, dummy_spanned};
21+
use codemap::{respan, spanned, dummy_spanned, mk_sp};
2222
use syntax_pos::{Span, BytePos, DUMMY_SP};
2323
use errors::Handler;
2424
use feature_gate::{Features, GatedCfg};
@@ -61,7 +61,7 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError) {
6161

6262
pub fn mark_used(attr: &Attribute) {
6363
debug!("Marking {:?} as used.", attr);
64-
let AttrId(id) = attr.node.id;
64+
let AttrId(id) = attr.id;
6565
USED_ATTRS.with(|slot| {
6666
let idx = (id / 64) as usize;
6767
let shift = id % 64;
@@ -73,7 +73,7 @@ pub fn mark_used(attr: &Attribute) {
7373
}
7474

7575
pub fn is_used(attr: &Attribute) -> bool {
76-
let AttrId(id) = attr.node.id;
76+
let AttrId(id) = attr.id;
7777
USED_ATTRS.with(|slot| {
7878
let idx = (id / 64) as usize;
7979
let shift = id % 64;
@@ -84,7 +84,7 @@ pub fn is_used(attr: &Attribute) -> bool {
8484

8585
pub fn mark_known(attr: &Attribute) {
8686
debug!("Marking {:?} as known.", attr);
87-
let AttrId(id) = attr.node.id;
87+
let AttrId(id) = attr.id;
8888
KNOWN_ATTRS.with(|slot| {
8989
let idx = (id / 64) as usize;
9090
let shift = id % 64;
@@ -96,7 +96,7 @@ pub fn mark_known(attr: &Attribute) {
9696
}
9797

9898
pub fn is_known(attr: &Attribute) -> bool {
99-
let AttrId(id) = attr.node.id;
99+
let AttrId(id) = attr.id;
100100
KNOWN_ATTRS.with(|slot| {
101101
let idx = (id / 64) as usize;
102102
let shift = id % 64;
@@ -270,7 +270,7 @@ impl MetaItem {
270270
impl Attribute {
271271
/// Extract the MetaItem from inside this Attribute.
272272
pub fn meta(&self) -> &MetaItem {
273-
&self.node.value
273+
&self.value
274274
}
275275

276276
/// Convert self to a normal #[doc="foo"] comment, if it is a
@@ -279,16 +279,16 @@ impl Attribute {
279279
pub fn with_desugared_doc<T, F>(&self, f: F) -> T where
280280
F: FnOnce(&Attribute) -> T,
281281
{
282-
if self.node.is_sugared_doc {
282+
if self.is_sugared_doc {
283283
let comment = self.value_str().unwrap();
284284
let meta = mk_name_value_item_str(
285285
InternedString::new("doc"),
286286
token::intern_and_get_ident(&strip_doc_comment_decoration(
287287
&comment)));
288-
if self.node.style == ast::AttrStyle::Outer {
289-
f(&mk_attr_outer(self.node.id, meta))
288+
if self.style == ast::AttrStyle::Outer {
289+
f(&mk_attr_outer(self.id, meta))
290290
} else {
291-
f(&mk_attr_inner(self.node.id, meta))
291+
f(&mk_attr_inner(self.id, meta))
292292
}
293293
} else {
294294
f(self)
@@ -355,13 +355,13 @@ pub fn mk_attr_inner(id: AttrId, item: P<MetaItem>) -> Attribute {
355355

356356
/// Returns an innter attribute with the given value and span.
357357
pub fn mk_spanned_attr_inner(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribute {
358-
respan(sp,
359-
Attribute_ {
360-
id: id,
361-
style: ast::AttrStyle::Inner,
362-
value: item,
363-
is_sugared_doc: false,
364-
})
358+
Attribute {
359+
id: id,
360+
style: ast::AttrStyle::Inner,
361+
value: item,
362+
is_sugared_doc: false,
363+
span: sp,
364+
}
365365
}
366366

367367

@@ -372,36 +372,36 @@ pub fn mk_attr_outer(id: AttrId, item: P<MetaItem>) -> Attribute {
372372

373373
/// Returns an outer attribute with the given value and span.
374374
pub fn mk_spanned_attr_outer(sp: Span, id: AttrId, item: P<MetaItem>) -> Attribute {
375-
respan(sp,
376-
Attribute_ {
377-
id: id,
378-
style: ast::AttrStyle::Outer,
379-
value: item,
380-
is_sugared_doc: false,
381-
})
375+
Attribute {
376+
id: id,
377+
style: ast::AttrStyle::Outer,
378+
value: item,
379+
is_sugared_doc: false,
380+
span: sp,
381+
}
382382
}
383383

384384
pub fn mk_doc_attr_outer(id: AttrId, item: P<MetaItem>, is_sugared_doc: bool) -> Attribute {
385-
dummy_spanned(Attribute_ {
385+
Attribute {
386386
id: id,
387387
style: ast::AttrStyle::Outer,
388388
value: item,
389389
is_sugared_doc: is_sugared_doc,
390-
})
390+
span: DUMMY_SP,
391+
}
391392
}
392393

393-
pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos,
394-
hi: BytePos)
394+
pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, hi: BytePos)
395395
-> Attribute {
396396
let style = doc_comment_style(&text);
397397
let lit = spanned(lo, hi, ast::LitKind::Str(text, ast::StrStyle::Cooked));
398-
let attr = Attribute_ {
398+
Attribute {
399399
id: id,
400400
style: style,
401401
value: P(spanned(lo, hi, MetaItemKind::NameValue(InternedString::new("doc"), lit))),
402-
is_sugared_doc: true
403-
};
404-
spanned(lo, hi, attr)
402+
is_sugared_doc: true,
403+
span: mk_sp(lo, hi),
404+
}
405405
}
406406

407407
/* Searching */
@@ -489,7 +489,7 @@ pub enum InlineAttr {
489489
/// Determine what `#[inline]` attribute is present in `attrs`, if any.
490490
pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> InlineAttr {
491491
attrs.iter().fold(InlineAttr::None, |ia,attr| {
492-
match attr.node.value.node {
492+
match attr.value.node {
493493
MetaItemKind::Word(ref n) if n == "inline" => {
494494
mark_used(attr);
495495
InlineAttr::Hint
@@ -896,7 +896,7 @@ pub fn require_unique_names(diagnostic: &Handler, metas: &[P<MetaItem>]) {
896896
/// structure layout, and `packed` to remove padding.
897897
pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> {
898898
let mut acc = Vec::new();
899-
match attr.node.value.node {
899+
match attr.value.node {
900900
ast::MetaItemKind::List(ref s, ref items) if s == "repr" => {
901901
mark_used(attr);
902902
for item in items {

src/libsyntax/config.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use attr::HasAttrs;
1212
use feature_gate::{feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features, GateIssue};
1313
use {fold, attr};
1414
use ast;
15-
use codemap::{Spanned, respan};
15+
use codemap::Spanned;
1616
use parse::ParseSess;
1717
use ptr::P;
1818

@@ -106,12 +106,13 @@ impl<'a> StripUnconfigured<'a> {
106106
match (cfg.meta_item(), mi.meta_item()) {
107107
(Some(cfg), Some(mi)) =>
108108
if cfg_matches(&cfg, self.sess, self.features) {
109-
self.process_cfg_attr(respan(mi.span, ast::Attribute_ {
109+
self.process_cfg_attr(ast::Attribute {
110110
id: attr::mk_attr_id(),
111-
style: attr.node.style,
111+
style: attr.style,
112112
value: mi.clone(),
113113
is_sugared_doc: false,
114-
}))
114+
span: mi.span,
115+
})
115116
} else {
116117
None
117118
},
@@ -131,7 +132,7 @@ impl<'a> StripUnconfigured<'a> {
131132
return false;
132133
}
133134

134-
let mis = match attr.node.value.node {
135+
let mis = match attr.value.node {
135136
ast::MetaItemKind::List(_, ref mis) if is_cfg(&attr) => mis,
136137
_ => return true
137138
};
@@ -160,7 +161,7 @@ impl<'a> StripUnconfigured<'a> {
160161
attr.span,
161162
GateIssue::Language,
162163
EXPLAIN_STMT_ATTR_SYNTAX);
163-
if attr.node.is_sugared_doc {
164+
if attr.is_sugared_doc {
164165
err.help("`///` is for documentation comments. For a plain comment, use `//`.");
165166
}
166167
err.emit();

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
353353

354354
match *ext {
355355
MultiModifier(ref mac) => {
356-
let item = mac.expand(self.cx, attr.span, &attr.node.value, item);
356+
let item = mac.expand(self.cx, attr.span, &attr.value, item);
357357
kind.expect_from_annotatables(item)
358358
}
359359
MultiDecorator(ref mac) => {
360360
let mut items = Vec::new();
361-
mac.expand(self.cx, attr.span, &attr.node.value, &item,
361+
mac.expand(self.cx, attr.span, &attr.value, &item,
362362
&mut |item| items.push(item));
363363
items.push(item);
364364
kind.expect_from_annotatables(items)

src/libsyntax/ext/quote.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ pub mod rt {
223223
let mut r = vec![];
224224
// FIXME: The spans could be better
225225
r.push(TokenTree::Token(self.span, token::Pound));
226-
if self.node.style == ast::AttrStyle::Inner {
226+
if self.style == ast::AttrStyle::Inner {
227227
r.push(TokenTree::Token(self.span, token::Not));
228228
}
229229
r.push(TokenTree::Delimited(self.span, Rc::new(tokenstream::Delimited {
230230
delim: token::Bracket,
231231
open_span: self.span,
232-
tts: self.node.value.to_tokens(cx),
232+
tts: self.value.to_tokens(cx),
233233
close_span: self.span,
234234
})));
235235
r

src/libsyntax/feature_gate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
10131013
self.context.check_attribute(attr, false);
10141014
}
10151015

1016-
if contains_novel_literal(&*(attr.node.value)) {
1016+
if contains_novel_literal(&*(attr.value)) {
10171017
gate_feature_post!(&self, attr_literals, attr.span,
10181018
"non-string literals in attributes, or string \
10191019
literals in top-level positions, are experimental");

src/libsyntax/fold.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -486,16 +486,13 @@ pub fn noop_fold_local<T: Folder>(l: P<Local>, fld: &mut T) -> P<Local> {
486486
})
487487
}
488488

489-
pub fn noop_fold_attribute<T: Folder>(at: Attribute, fld: &mut T) -> Option<Attribute> {
490-
let Spanned {node: Attribute_ {id, style, value, is_sugared_doc}, span} = at;
491-
Some(Spanned {
492-
node: Attribute_ {
493-
id: id,
494-
style: style,
495-
value: fld.fold_meta_item(value),
496-
is_sugared_doc: is_sugared_doc
497-
},
498-
span: fld.new_span(span)
489+
pub fn noop_fold_attribute<T: Folder>(attr: Attribute, fld: &mut T) -> Option<Attribute> {
490+
Some(Attribute {
491+
id: attr.id,
492+
style: attr.style,
493+
value: fld.fold_meta_item(attr.value),
494+
is_sugared_doc: attr.is_sugared_doc,
495+
span: fld.new_span(attr.span),
499496
})
500497
}
501498

0 commit comments

Comments
 (0)