Skip to content

Commit 4b0f702

Browse files
committed
convert ast::attribute_ and ast::view_item to a struct
1 parent eafed93 commit 4b0f702

File tree

11 files changed

+79
-57
lines changed

11 files changed

+79
-57
lines changed

src/librustc/driver/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ mod test {
345345
use syntax::ast_util;
346346

347347
fn make_crate_type_attr(+t: ~str) -> ast::attribute {
348-
ast_util::respan(ast_util::dummy_sp(), {
348+
ast_util::respan(ast_util::dummy_sp(), ast::attribute_ {
349349
style: ast::attr_outer,
350350
value: ast_util::respan(ast_util::dummy_sp(),
351351
ast::meta_name_value(

src/librustc/front/core_inject.rs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,21 @@ fn inject_libcore_ref(sess: Session,
4545
let precursor = @fold::AstFoldFns {
4646
fold_crate: |crate, span, fld| {
4747
let n1 = sess.next_node_id();
48-
let vi1 = @{node: ast::view_item_use(sess.ident_of(~"core"),
49-
~[],
50-
n1),
51-
attrs: ~[
52-
spanned({
53-
style: ast::attr_inner,
54-
value: spanned(ast::meta_name_value(
55-
~"vers",
56-
spanned(ast::lit_str(
57-
@CORE_VERSION.to_str()))
58-
)),
59-
is_sugared_doc: false
60-
})
61-
],
62-
vis: ast::private,
63-
span: dummy_sp()};
48+
let vi1 = @ast::view_item {
49+
node: ast::view_item_use(sess.ident_of(~"core"), ~[], n1),
50+
attrs: ~[
51+
spanned(ast::attribute_ {
52+
style: ast::attr_inner,
53+
value: spanned(ast::meta_name_value(
54+
~"vers",
55+
spanned(ast::lit_str(@CORE_VERSION.to_str()))
56+
)),
57+
is_sugared_doc: false
58+
})
59+
],
60+
vis: ast::private,
61+
span: dummy_sp()
62+
};
6463

6564
let vis = vec::append(~[vi1], crate.module.view_items);
6665
let mut new_module = {
@@ -88,10 +87,10 @@ fn inject_libcore_ref(sess: Session,
8887
};
8988

9089
let vp = @spanned(ast::view_path_glob(prelude_path, n2));
91-
let vi2 = @{node: ast::view_item_import(~[vp]),
92-
attrs: ~[],
93-
vis: ast::private,
94-
span: dummy_sp()};
90+
let vi2 = @ast::view_item { node: ast::view_item_import(~[vp]),
91+
attrs: ~[],
92+
vis: ast::private,
93+
span: dummy_sp() };
9594

9695
let vis = vec::append(~[vi2], module.view_items);
9796

src/librustc/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn mk_std(cx: test_ctxt) -> @ast::view_item {
268268
let vi = ast::view_item_use(cx.sess.ident_of(~"std"),
269269
~[@mi],
270270
cx.sess.next_node_id());
271-
let vi = {
271+
let vi = ast::view_item {
272272
node: vi,
273273
attrs: ~[],
274274
vis: ast::private,

src/librustc/metadata/decoder.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,14 @@ fn get_attributes(md: ebml::Doc) -> ~[ast::attribute] {
10341034
assert (vec::len(meta_items) == 1u);
10351035
let meta_item = meta_items[0];
10361036
attrs.push(
1037-
ast::spanned { node: { style: ast::attr_outer,
1038-
value: /*bad*/copy *meta_item,
1039-
is_sugared_doc: false },
1040-
span: ast_util::dummy_sp()});
1037+
ast::spanned {
1038+
node: ast::attribute_ {
1039+
style: ast::attr_outer,
1040+
value: /*bad*/copy *meta_item,
1041+
is_sugared_doc: false,
1042+
},
1043+
span: ast_util::dummy_sp()
1044+
});
10411045
};
10421046
}
10431047
option::None => ()

src/libsyntax/ast.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,8 +1393,12 @@ enum view_path_ {
13931393
13941394
#[auto_encode]
13951395
#[auto_decode]
1396-
type view_item = {node: view_item_, attrs: ~[attribute],
1397-
vis: visibility, span: span};
1396+
struct view_item {
1397+
node: view_item_,
1398+
attrs: ~[attribute],
1399+
vis: visibility,
1400+
span: span,
1401+
}
13981402
13991403
#[auto_encode]
14001404
#[auto_decode]
@@ -1424,7 +1428,11 @@ impl attr_style : cmp::Eq {
14241428
// doc-comments are promoted to attributes that have is_sugared_doc = true
14251429
#[auto_encode]
14261430
#[auto_decode]
1427-
type attribute_ = {style: attr_style, value: meta_item, is_sugared_doc: bool};
1431+
struct attribute_ {
1432+
style: attr_style,
1433+
value: meta_item,
1434+
is_sugared_doc: bool,
1435+
}
14281436
14291437
/*
14301438
trait_refs appear in impls.

src/libsyntax/attr.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,20 @@ fn mk_word_item(name: ~str) -> @ast::meta_item {
9191
}
9292

9393
fn mk_attr(item: @ast::meta_item) -> ast::attribute {
94-
return dummy_spanned({style: ast::attr_inner, value: *item,
95-
is_sugared_doc: false});
94+
dummy_spanned(ast::attribute_ { style: ast::attr_inner,
95+
value: *item,
96+
is_sugared_doc: false })
9697
}
9798

9899
fn mk_sugared_doc_attr(text: ~str,
99100
+lo: BytePos, +hi: BytePos) -> ast::attribute {
100101
let lit = spanned(lo, hi, ast::lit_str(@text));
101-
let attr = {
102+
let attr = ast::attribute_ {
102103
style: doc_comment_style(text),
103104
value: spanned(lo, hi, ast::meta_name_value(~"doc", lit)),
104105
is_sugared_doc: true
105106
};
106-
return spanned(lo, hi, attr);
107+
spanned(lo, hi, attr)
107108
}
108109

109110
/* Conversion */

src/libsyntax/ext/build.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ fn mk_glob_use(cx: ext_ctxt, sp: span,
173173
node: ast::view_path_glob(mk_raw_path(sp, path), cx.next_id()),
174174
span: sp,
175175
};
176-
@{node: ast::view_item_import(~[glob]),
177-
attrs: ~[],
178-
vis: ast::private,
179-
span: sp}
176+
@ast::view_item { node: ast::view_item_import(~[glob]),
177+
attrs: ~[],
178+
vis: ast::private,
179+
span: sp }
180180
}
181181
fn mk_local(cx: ext_ctxt, sp: span, mutbl: bool,
182182
ident: ast::ident, ex: @ast::expr) -> @ast::stmt {

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
219219

220220
// XXX: Would be nice if our generated code didn't violate
221221
// Rust coding conventions
222-
let non_camel_case_attribute = respan(dummy_sp(), {
222+
let non_camel_case_attribute = respan(dummy_sp(), ast::attribute_ {
223223
style: ast::attr_outer,
224224
value: respan(dummy_sp(),
225225
ast::meta_list(~"allow", ~[
@@ -306,7 +306,7 @@ impl ext_ctxt: ext_ctxt_ast_builder {
306306
span: ast_util::dummy_sp()
307307
}
308308
]);
309-
let vi = @{
309+
let vi = @ast::view_item {
310310
node: vi,
311311
attrs: ~[],
312312
vis: ast::private,

src/libsyntax/fold.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,14 @@ fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
114114
}
115115
//used in noop_fold_item and noop_fold_crate
116116
fn fold_attribute_(at: attribute, fld: ast_fold) -> attribute {
117-
spanned { node: { style: at.node.style,
118-
value: *fold_meta_item_(@at.node.value, fld),
119-
is_sugared_doc: at.node.is_sugared_doc },
120-
span: fld.new_span(at.span) }
117+
spanned {
118+
node: ast::attribute_ {
119+
style: at.node.style,
120+
value: *fold_meta_item_(@at.node.value, fld),
121+
is_sugared_doc: at.node.is_sugared_doc,
122+
},
123+
span: fld.new_span(at.span),
124+
}
121125
}
122126
//used in noop_fold_foreign_item and noop_fold_fn_decl
123127
fn fold_arg_(a: arg, fld: ast_fold) -> arg {
@@ -679,11 +683,13 @@ impl ast_fold_fns: ast_fold {
679683
}
680684
fn fold_view_item(&&x: @view_item) ->
681685
@view_item {
682-
return @{node: (self.fold_view_item)(x.node, self as ast_fold),
683-
attrs: vec::map(x.attrs, |a|
686+
@ast::view_item {
687+
node: (self.fold_view_item)(x.node, self as ast_fold),
688+
attrs: vec::map(x.attrs, |a|
684689
fold_attribute_(*a, self as ast_fold)),
685-
vis: x.vis,
686-
span: (self.new_span)(x.span)};
690+
vis: x.vis,
691+
span: (self.new_span)(x.span),
692+
}
687693
}
688694
fn fold_foreign_item(&&x: @foreign_item)
689695
-> @foreign_item {

src/libsyntax/parse/attr.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ impl Parser: parser_attr {
7272
let meta_item = self.parse_meta_item();
7373
self.expect(token::RBRACKET);
7474
let mut hi = self.span.hi;
75-
return spanned(lo, hi, {style: style, value: *meta_item,
76-
is_sugared_doc: false});
75+
return spanned(lo, hi, ast::attribute_ { style: style,
76+
value: *meta_item,
77+
is_sugared_doc: false });
7778
}
7879

7980
// Parse attributes that appear after the opening of an item, each
@@ -101,8 +102,9 @@ impl Parser: parser_attr {
101102
// It's not really an inner attribute
102103
let outer_attr =
103104
spanned(attr.span.lo, attr.span.hi,
104-
{style: ast::attr_outer, value: attr.node.value,
105-
is_sugared_doc: false});
105+
ast::attribute_ { style: ast::attr_outer,
106+
value: attr.node.value,
107+
is_sugared_doc: false });
106108
next_outer_attrs += ~[outer_attr];
107109
break;
108110
}

src/libsyntax/parse/parser.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,12 +3276,12 @@ impl Parser {
32763276
// extern mod foo;
32773277
let metadata = self.parse_optional_meta();
32783278
self.expect(token::SEMI);
3279-
return iovi_view_item(@{
3279+
iovi_view_item(@ast::view_item {
32803280
node: view_item_use(ident, metadata, self.get_id()),
32813281
attrs: attrs,
32823282
vis: visibility,
32833283
span: mk_sp(lo, self.last_span.hi)
3284-
});
3284+
})
32853285
}
32863286
32873287
fn parse_type_decl() -> {lo: BytePos, ident: ident} {
@@ -3573,7 +3573,7 @@ impl Parser {
35733573
} else if self.eat_keyword(~"use") {
35743574
let view_item = self.parse_use();
35753575
self.expect(token::SEMI);
3576-
return iovi_view_item(@{
3576+
return iovi_view_item(@ast::view_item {
35773577
node: view_item,
35783578
attrs: attrs,
35793579
vis: visibility,
@@ -3582,7 +3582,7 @@ impl Parser {
35823582
} else if self.eat_keyword(~"export") {
35833583
let view_paths = self.parse_view_paths();
35843584
self.expect(token::SEMI);
3585-
return iovi_view_item(@{
3585+
return iovi_view_item(@ast::view_item {
35863586
node: view_item_export(view_paths),
35873587
attrs: attrs,
35883588
vis: visibility,
@@ -3780,8 +3780,10 @@ impl Parser {
37803780
fail;
37813781
};
37823782
self.expect(token::SEMI);
3783-
@{node: node, attrs: attrs,
3784-
vis: vis, span: mk_sp(lo, self.last_span.hi)}
3783+
@ast::view_item { node: node,
3784+
attrs: attrs,
3785+
vis: vis,
3786+
span: mk_sp(lo, self.last_span.hi) }
37853787
}
37863788
37873789
fn parse_items_and_view_items(+first_item_attrs: ~[attribute],

0 commit comments

Comments
 (0)