Skip to content

Commit ae06546

Browse files
committed
Replace more vector + (issue #2719)
1 parent 0b84437 commit ae06546

File tree

10 files changed

+82
-65
lines changed

10 files changed

+82
-65
lines changed

src/libcore/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ mod tests {
18881888
let mut results: [[int]/~]/~;
18891889

18901890
results = []/~;
1891-
permute([]/~) {|v| results += [v]/~; }
1891+
permute([]/~) {|v| vec::push(results, v); }
18921892
assert results == [[]/~]/~;
18931893

18941894
results = []/~;

src/libsyntax/attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value }
7777
// Get the meta_items from inside a vector of attributes
7878
fn attr_metas(attrs: [ast::attribute]/~) -> [@ast::meta_item]/~ {
7979
let mut mitems = []/~;
80-
for attrs.each {|a| mitems += [attr_meta(a)]/~; }
80+
for attrs.each {|a| vec::push(mitems, attr_meta(a)); }
8181
ret mitems;
8282
}
8383

@@ -303,7 +303,7 @@ fn find_linkage_attrs(attrs: [ast::attribute]/~) -> [ast::attribute]/~ {
303303
let mut found = []/~;
304304
for find_attrs_by_name(attrs, "link").each {|attr|
305305
alt attr.node.value.node {
306-
ast::meta_list(_, _) { found += [attr]/~ }
306+
ast::meta_list(_, _) { vec::push(found, attr) }
307307
_ { #debug("ignoring link attribute that has incorrect type"); }
308308
}
309309
}

src/libsyntax/ext/auto_serialize.rs

+31-25
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ fn expand(cx: ext_ctxt,
103103
vec::flat_map(in_items) {|in_item|
104104
alt in_item.node {
105105
ast::item_ty(ty, tps, _) {
106-
[filter_attrs(in_item)]/~ + ty_fns(cx, in_item.ident, ty, tps)
106+
vec::append([filter_attrs(in_item)]/~,
107+
ty_fns(cx, in_item.ident, ty, tps))
107108
}
108109

109110
ast::item_enum(variants, tps, _) {
110-
[filter_attrs(in_item)]/~ + enum_fns(cx, in_item.ident,
111-
in_item.span, variants, tps)
111+
vec::append([filter_attrs(in_item)]/~,
112+
enum_fns(cx, in_item.ident,
113+
in_item.span, variants, tps))
112114
}
113115

114116
_ {
@@ -126,7 +128,8 @@ impl helpers for ext_ctxt {
126128
helper_name: str) -> @ast::path {
127129
let head = vec::init(base_path.idents);
128130
let tail = vec::last(base_path.idents);
129-
self.path(base_path.span, head + [@(helper_name + "_" + *tail)]/~)
131+
self.path(base_path.span,
132+
vec::append(head, [@(helper_name + "_" + *tail)]/~))
130133
}
131134

132135
fn path(span: span, strs: [ast::ident]/~) -> @ast::path {
@@ -301,7 +304,7 @@ fn ser_path(cx: ext_ctxt, tps: ser_tps_map, path: @ast::path,
301304
[cx.stmt(
302305
cx.expr(
303306
path.span,
304-
ast::expr_call(callee, [s, v]/~ + ty_args, false)))]/~
307+
ast::expr_call(callee, vec::append([s, v]/~, ty_args), false)))]/~
305308
}
306309

307310
fn ser_variant(cx: ext_ctxt,
@@ -502,15 +505,15 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
502505

503506

504507
let ser_inputs: [ast::arg]/~ =
505-
[{mode: ast::expl(ast::by_ref),
506-
ty: cx.ty_path(span, [@"__S"]/~, []/~),
507-
ident: @"__s",
508-
id: cx.next_id()},
509-
{mode: ast::expl(ast::by_ref),
510-
ty: v_ty,
511-
ident: @"__v",
512-
id: cx.next_id()}]/~
513-
+ tp_inputs;
508+
vec::append([{mode: ast::expl(ast::by_ref),
509+
ty: cx.ty_path(span, [@"__S"]/~, []/~),
510+
ident: @"__s",
511+
id: cx.next_id()},
512+
{mode: ast::expl(ast::by_ref),
513+
ty: v_ty,
514+
ident: @"__v",
515+
id: cx.next_id()}]/~,
516+
tp_inputs);
514517

515518
let tps_map = map::str_hash();
516519
vec::iter2(tps, tp_inputs) {|tp, arg|
@@ -531,10 +534,10 @@ fn mk_ser_fn(cx: ext_ctxt, span: span, name: ast::ident,
531534
[]/~))]/~;
532535

533536
let ser_tps: [ast::ty_param]/~ =
534-
[{ident: @"__S",
535-
id: cx.next_id(),
536-
bounds: ser_bnds}]/~ +
537-
vec::map(tps) {|tp| cx.clone_ty_param(tp) };
537+
vec::append([{ident: @"__S",
538+
id: cx.next_id(),
539+
bounds: ser_bnds}]/~,
540+
vec::map(tps) {|tp| cx.clone_ty_param(tp) });
538541

539542
let ser_output: @ast::ty = @{id: cx.next_id(),
540543
node: ast::ty_nil,
@@ -575,7 +578,8 @@ fn deser_path(cx: ext_ctxt, tps: deser_tps_map, path: @ast::path,
575578
cx.lambda(cx.expr_blk(dv_expr))
576579
};
577580

578-
cx.expr(path.span, ast::expr_call(callee, [d]/~ + ty_args, false))
581+
cx.expr(path.span, ast::expr_call(callee, vec::append([d]/~, ty_args),
582+
false))
579583
}
580584

581585
fn deser_lambda(cx: ext_ctxt, tps: deser_tps_map, ty: @ast::ty,
@@ -712,11 +716,11 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
712716
#debug["tp_inputs = %?", tp_inputs];
713717

714718
let deser_inputs: [ast::arg]/~ =
715-
[{mode: ast::expl(ast::by_ref),
716-
ty: cx.ty_path(span, [@"__D"]/~, []/~),
717-
ident: @"__d",
718-
id: cx.next_id()}]/~
719-
+ tp_inputs;
719+
vec::append([{mode: ast::expl(ast::by_ref),
720+
ty: cx.ty_path(span, [@"__D"]/~, []/~),
721+
ident: @"__d",
722+
id: cx.next_id()}]/~,
723+
tp_inputs);
720724

721725
let tps_map = map::str_hash();
722726
vec::iter2(tps, tp_inputs) {|tp, arg|
@@ -740,7 +744,9 @@ fn mk_deser_fn(cx: ext_ctxt, span: span,
740744
id: cx.next_id(),
741745
bounds: deser_bnds}]/~ + vec::map(tps) {|tp|
742746
let cloned = cx.clone_ty_param(tp);
743-
{bounds: @(*cloned.bounds + [ast::bound_copy]/~) with cloned}
747+
{bounds: @(vec::append(*cloned.bounds,
748+
[ast::bound_copy]/~))
749+
with cloned}
744750
};
745751

746752
let deser_blk = cx.expr_blk(f(cx, tps_map, #ast(expr){__d}));

src/libsyntax/ext/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn mk_rec_e(cx: ext_ctxt, sp: span,
8282
let val = field.ex;
8383
let astfield =
8484
{node: {mutbl: ast::m_imm, ident: ident, expr: val}, span: sp};
85-
astfields += [astfield]/~;
85+
vec::push(astfields, astfield);
8686
}
8787
let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>);
8888
ret @{id: cx.next_id(), node: recexpr, span: sp};

src/libsyntax/ext/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
6060
flag_sign_always { fstr = "flag_sign_always"; }
6161
flag_alternate { fstr = "flag_alternate"; }
6262
}
63-
flagexprs += [make_rt_path_expr(cx, sp, @fstr)]/~;
63+
vec::push(flagexprs, make_rt_path_expr(cx, sp, @fstr));
6464
}
6565
ret mk_uniq_vec_e(cx, sp, flagexprs);
6666
}

src/libsyntax/ext/simplext.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn option_flatten_map<T: copy, U: copy>(f: fn@(T) -> option<U>, v: [T]/~) ->
104104
option<[U]/~> {
105105
let mut res = []/~;
106106
for v.each {|elem|
107-
alt f(elem) { none { ret none; } some(fv) { res += [fv]/~; } }
107+
alt f(elem) { none { ret none; } some(fv) { vec::push(res, fv); } }
108108
}
109109
ret some(res);
110110
}
@@ -309,16 +309,16 @@ fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut [uint]/~,
309309
/* Whew, we now know how how many times to repeat */
310310
let mut idx: uint = 0u;
311311
while idx < rc {
312-
*idx_path += [idx]/~;
313-
res += [recur(repeat_me)]/~; // whew!
312+
vec::push(*idx_path, idx);
313+
vec::push(res, recur(repeat_me)); // whew!
314314
vec::pop(*idx_path);
315315
idx += 1u;
316316
}
317317
}
318318
}
319319
}
320320
}
321-
res += vec::map(post, recur);
321+
res = vec::append(res, vec::map(post, recur));
322322
ret res;
323323
}
324324
}
@@ -718,9 +718,9 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
718718
none { cx.span_fatal(mac.span,
719719
"macro must have arguments")}
720720
};
721-
clauses +=
722-
[@{params: pattern_to_selectors(cx, arg),
723-
body: elts[1u]}]/~;
721+
vec::push(clauses,
722+
@{params: pattern_to_selectors(cx, arg),
723+
body: elts[1u]});
724724

725725
// FIXME (#2251): check duplicates (or just simplify
726726
// the macro arg situation)

src/libsyntax/parse.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn parse_crate_from_crate_file(input: str, cfg: ast::crate_cfg,
8484
ret @ast_util::respan(ast_util::mk_sp(lo, hi),
8585
{directives: cdirs,
8686
module: m,
87-
attrs: crate_attrs + attrs,
87+
attrs: vec::append(crate_attrs, attrs),
8888
config: /* FIXME (#2543) */ copy p.cfg});
8989
}
9090

src/libsyntax/parse/attr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ impl parser_attr for parser {
2121
self.bump();
2222
let first_attr =
2323
self.parse_attribute_naked(ast::attr_outer, lo);
24-
ret some(left([first_attr]/~ +
25-
self.parse_outer_attributes()));
24+
ret some(left(vec::append([first_attr]/~,
25+
self.parse_outer_attributes())));
2626
} else if !(self.look_ahead(1u) == token::LT
2727
|| self.look_ahead(1u) == token::LBRACKET
2828
|| self.look_ahead(1u) == token::POUND
@@ -38,7 +38,7 @@ impl parser_attr for parser {
3838
let mut attrs: [ast::attribute]/~ = []/~;
3939
while self.token == token::POUND
4040
&& self.look_ahead(1u) == token::LBRACKET {
41-
attrs += [self.parse_attribute(ast::attr_outer)]/~;
41+
vec::push(attrs, self.parse_attribute(ast::attr_outer));
4242
}
4343
ret attrs;
4444
}
@@ -76,13 +76,13 @@ impl parser_attr for parser {
7676
let attr = self.parse_attribute(ast::attr_inner);
7777
if self.token == token::SEMI {
7878
self.bump();
79-
inner_attrs += [attr]/~;
79+
vec::push(inner_attrs, attr);
8080
} else {
8181
// It's not really an inner attribute
8282
let outer_attr =
8383
spanned(attr.span.lo, attr.span.hi,
8484
{style: ast::attr_outer, value: attr.node.value});
85-
next_outer_attrs += [outer_attr]/~;
85+
vec::push(next_outer_attrs, outer_attr);
8686
break;
8787
}
8888
}

src/libsyntax/parse/eval.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ fn eval_crate_directives_to_mod(cx: ctx, cdirs: [@ast::crate_directive]/~,
2828
let mut view_items: [@ast::view_item]/~ = []/~;
2929
let mut items: [@ast::item]/~ = []/~;
3030
eval_crate_directives(cx, cdirs, prefix, view_items, items);
31-
ret ({view_items: view_items + cview_items,
32-
items: items + citems},
31+
ret ({view_items: vec::append(view_items, cview_items),
32+
items: vec::append(items, citems)},
3333
cattrs);
3434
}
3535

@@ -100,7 +100,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
100100
let (p0, r0) =
101101
new_parser_etc_from_file(cx.sess, cx.cfg, full_path, SOURCE_FILE);
102102
let inner_attrs = p0.parse_inner_attrs_and_next();
103-
let mod_attrs = attrs + inner_attrs.inner;
103+
let mod_attrs = vec::append(attrs, inner_attrs.inner);
104104
let first_item_outer_attrs = inner_attrs.next;
105105
let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs);
106106

@@ -110,7 +110,7 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
110110
// Thread defids, chpos and byte_pos through the parsers
111111
cx.sess.chpos = r0.chpos;
112112
cx.sess.byte_pos = cx.sess.byte_pos + r0.pos;
113-
items += [i]/~;
113+
vec::push(items, i);
114114
}
115115
ast::cdir_dir_mod(id, cdirs, attrs) {
116116
let path = cdir_path_opt(id, attrs);
@@ -122,15 +122,15 @@ fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: str,
122122
cx, cdirs, full_path, none);
123123
let i =
124124
@{ident: /* FIXME (#2543) */ copy id,
125-
attrs: attrs + a0,
125+
attrs: vec::append(attrs, a0),
126126
id: cx.sess.next_id,
127127
node: ast::item_mod(m0),
128128
vis: ast::public,
129129
span: cdir.span};
130130
cx.sess.next_id += 1;
131-
items += [i]/~;
131+
vec::push(items, i);
132132
}
133-
ast::cdir_view_item(vi) { view_items += [vi]/~; }
133+
ast::cdir_view_item(vi) { vec::push(view_items, vi); }
134134
ast::cdir_syntax(pth) { }
135135
}
136136
}

0 commit comments

Comments
 (0)