Skip to content

Commit cbbc1fc

Browse files
committed
vec: convert append and append_one to methods
These were only free functions on `~[T]` because taking self by-value used to be broken.
1 parent 612e22e commit cbbc1fc

File tree

30 files changed

+126
-222
lines changed

30 files changed

+126
-222
lines changed

src/compiletest/procsrv.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use std::os;
1212
use std::str;
1313
use std::io::process::{ProcessExit, Process, ProcessConfig, ProcessOutput};
14-
use std::vec;
1514

1615
#[cfg(target_os = "win32")]
1716
fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> {
@@ -66,8 +65,7 @@ pub fn run(lib_path: &str,
6665
env: Vec<(~str, ~str)> ,
6766
input: Option<~str>) -> Option<Result> {
6867

69-
let env = vec::append(env.clone(),
70-
target_env(lib_path, prog).as_slice());
68+
let env = env.clone().append(target_env(lib_path, prog).as_slice());
7169
let mut opt_process = Process::configure(ProcessConfig {
7270
program: prog,
7371
args: args,
@@ -98,8 +96,7 @@ pub fn run_background(lib_path: &str,
9896
env: Vec<(~str, ~str)> ,
9997
input: Option<~str>) -> Option<Process> {
10098

101-
let env = vec::append(env.clone(),
102-
target_env(lib_path, prog).as_slice());
99+
let env = env.clone().append(target_env(lib_path, prog).as_slice());
103100
let opt_process = Process::configure(ProcessConfig {
104101
program: prog,
105102
args: args,

src/compiletest/runtest.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use std::os;
3333
use std::str;
3434
use std::task;
3535
use std::slice;
36-
use std::vec;
3736
use test::MetricMap;
3837

3938
pub fn run(config: config, testfile: ~str) {
@@ -683,7 +682,7 @@ fn compile_test_(config: &config, props: &TestProps,
683682
let link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned());
684683
let args = make_compile_args(config,
685684
props,
686-
vec::append(link_args, extra_args),
685+
link_args.append(extra_args),
687686
|a, b| ThisFile(make_exe_name(a, b)), testfile);
688687
compose_and_run_compiler(config, props, testfile, args, None)
689688
}
@@ -734,8 +733,7 @@ fn compose_and_run_compiler(
734733
let aux_args =
735734
make_compile_args(config,
736735
&aux_props,
737-
vec::append(crate_type,
738-
extra_link_args.as_slice()),
736+
crate_type.append(extra_link_args.as_slice()),
739737
|a,b| {
740738
let f = make_lib_name(a, b, testfile);
741739
ThisDirectory(f.dir_path())
@@ -1108,8 +1106,7 @@ fn compile_test_and_save_bitcode(config: &config, props: &TestProps,
11081106
let llvm_args = vec!(~"--emit=obj", ~"--crate-type=lib", ~"-C", ~"save-temps");
11091107
let args = make_compile_args(config,
11101108
props,
1111-
vec::append(link_args,
1112-
llvm_args.as_slice()),
1109+
link_args.append(llvm_args.as_slice()),
11131110
|a, b| ThisFile(make_o_name(a, b)), testfile);
11141111
compose_and_run_compiler(config, props, testfile, args, None)
11151112
}

src/libnum/bigint.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use rand::Rng;
2828
use std::str;
2929
use std::uint;
3030
use std::{i64, u64};
31-
use std::vec;
3231

3332
/**
3433
A `BigDigit` is a `BigUint`'s composing element.
@@ -747,8 +746,7 @@ impl BigUint {
747746
fn shl_unit(&self, n_unit: uint) -> BigUint {
748747
if n_unit == 0 || self.is_zero() { return (*self).clone(); }
749748

750-
return BigUint::new(vec::append(Vec::from_elem(n_unit, ZERO_BIG_DIGIT),
751-
self.data.as_slice()));
749+
BigUint::new(Vec::from_elem(n_unit, ZERO_BIG_DIGIT).append(self.data.as_slice()))
752750
}
753751

754752
#[inline]

src/librustc/driver/driver.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use std::io::fs;
3737
use std::io::MemReader;
3838
use std::mem::drop;
3939
use std::os;
40-
use std::vec;
4140
use getopts::{optopt, optmulti, optflag, optflagopt};
4241
use getopts;
4342
use syntax::ast;
@@ -137,8 +136,7 @@ pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
137136
} else {
138137
InternedString::new("nogc")
139138
});
140-
return vec::append(user_cfg.move_iter().collect(),
141-
default_cfg.as_slice());
139+
user_cfg.move_iter().collect::<Vec<_>>().append(default_cfg.as_slice())
142140
}
143141

144142
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
@@ -836,9 +834,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
836834

837835
let level_short = level_name.slice_chars(0, 1);
838836
let level_short = level_short.to_ascii().to_upper().into_str();
839-
let flags = vec::append(matches.opt_strs(level_short)
840-
.move_iter()
841-
.collect(),
837+
let flags = matches.opt_strs(level_short).move_iter().collect::<Vec<_>>().append(
842838
matches.opt_strs(level_name).as_slice());
843839
for lint_name in flags.iter() {
844840
let lint_name = lint_name.replace("-", "_");

src/librustc/front/std_inject.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use driver::session::Session;
1313

14-
use std::vec;
1514
use syntax::ast;
1615
use syntax::attr;
1716
use syntax::codemap::DUMMY_SP;
@@ -173,7 +172,7 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
173172
span: DUMMY_SP,
174173
};
175174

176-
let vis = vec::append(vec!(vi2), module.view_items.as_slice());
175+
let vis = (vec!(vi2)).append(module.view_items.as_slice());
177176

178177
// FIXME #2543: Bad copy.
179178
let new_module = ast::Mod {

src/librustc/front/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ fn should_fail(i: @ast::Item) -> bool {
272272
fn add_test_module(cx: &TestCtxt, m: &ast::Mod) -> ast::Mod {
273273
let testmod = mk_test_module(cx);
274274
ast::Mod {
275-
items: vec::append_one(m.items.clone(), testmod),
275+
items: m.items.clone().append_one(testmod),
276276
..(*m).clone()
277277
}
278278
}

src/librustc/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ use std::io;
5454
use std::os;
5555
use std::str;
5656
use std::task;
57-
use std::vec;
5857
use syntax::ast;
5958
use syntax::diagnostic::Emitter;
6059
use syntax::diagnostic;
@@ -239,9 +238,7 @@ pub fn run_compiler(args: &[~str]) {
239238
return;
240239
}
241240

242-
let lint_flags = vec::append(matches.opt_strs("W")
243-
.move_iter()
244-
.collect(),
241+
let lint_flags = matches.opt_strs("W").move_iter().collect::<Vec<_>>().append(
245242
matches.opt_strs("warn").as_slice());
246243
if lint_flags.iter().any(|x| x == &~"help") {
247244
describe_warnings();

src/librustc/metadata/csearch.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use middle::typeck;
2020

2121
use reader = serialize::ebml::reader;
2222
use std::rc::Rc;
23-
use std::vec;
2423
use syntax::ast;
2524
use syntax::ast_map;
2625
use syntax::diagnostic::expect;
@@ -93,8 +92,7 @@ pub fn get_item_path(tcx: &ty::ctxt, def: ast::DefId) -> Vec<ast_map::PathElem>
9392

9493
// FIXME #1920: This path is not always correct if the crate is not linked
9594
// into the root namespace.
96-
vec::append(vec!(ast_map::PathMod(token::intern(cdata.name))),
97-
path.as_slice())
95+
(vec!(ast_map::PathMod(token::intern(cdata.name)))).append(path.as_slice())
9896
}
9997

10098
pub enum found_ast {

src/librustc/middle/borrowck/gather_loans/restrictions.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* Computes the restrictions that result from a borrow.
1313
*/
1414

15-
use std::vec;
1615
use middle::borrowck::*;
1716
use mc = middle::mem_categorization;
1817
use middle::ty;
@@ -173,11 +172,7 @@ impl<'a> RestrictionsContext<'a> {
173172
Safe => Safe,
174173
SafeIf(base_lp, base_vec) => {
175174
let lp = @LpExtend(base_lp, mc, elem);
176-
SafeIf(lp, vec::append_one(base_vec,
177-
Restriction {
178-
loan_path: lp,
179-
set: restrictions
180-
}))
175+
SafeIf(lp, base_vec.append_one(Restriction { loan_path: lp, set: restrictions }))
181176
}
182177
}
183178
}

src/librustc/middle/check_match.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use util::ppaux::ty_to_str;
2121

2222
use std::cmp;
2323
use std::iter;
24-
use std::vec;
2524
use syntax::ast::*;
2625
use syntax::ast_util::{unguarded_pat, walk_pat};
2726
use syntax::codemap::{DUMMY_SP, Span};
@@ -560,11 +559,10 @@ fn specialize(cx: &MatchCheckCtxt,
560559
Pat{id: pat_id, node: n, span: pat_span} =>
561560
match n {
562561
PatWild => {
563-
Some(vec::append(Vec::from_elem(arity, wild()), r.tail()))
562+
Some(Vec::from_elem(arity, wild()).append(r.tail()))
564563
}
565564
PatWildMulti => {
566-
Some(vec::append(Vec::from_elem(arity, wild_multi()),
567-
r.tail()))
565+
Some(Vec::from_elem(arity, wild_multi()).append(r.tail()))
568566
}
569567
PatIdent(_, _, _) => {
570568
let opt_def = cx.tcx.def_map.borrow().find_copy(&pat_id);
@@ -615,12 +613,7 @@ fn specialize(cx: &MatchCheckCtxt,
615613
}
616614
}
617615
_ => {
618-
Some(
619-
vec::append(
620-
Vec::from_elem(arity, wild()),
621-
r.tail()
622-
)
623-
)
616+
Some(Vec::from_elem(arity, wild()).append(r.tail()))
624617
}
625618
}
626619
}
@@ -667,7 +660,7 @@ fn specialize(cx: &MatchCheckCtxt,
667660
Some(args) => args.iter().map(|x| *x).collect(),
668661
None => Vec::from_elem(arity, wild())
669662
};
670-
Some(vec::append(args, r.tail()))
663+
Some(args.append(r.tail()))
671664
}
672665
DefVariant(_, _, _) => None,
673666

@@ -680,7 +673,7 @@ fn specialize(cx: &MatchCheckCtxt,
680673
}
681674
None => new_args = Vec::from_elem(arity, wild())
682675
}
683-
Some(vec::append(new_args, r.tail()))
676+
Some(new_args.append(r.tail()))
684677
}
685678
_ => None
686679
}
@@ -697,8 +690,8 @@ fn specialize(cx: &MatchCheckCtxt,
697690
Some(f) => f.pat,
698691
_ => wild()
699692
}
700-
}).collect();
701-
Some(vec::append(args, r.tail()))
693+
}).collect::<Vec<_>>();
694+
Some(args.append(r.tail()))
702695
} else {
703696
None
704697
}
@@ -728,16 +721,16 @@ fn specialize(cx: &MatchCheckCtxt,
728721
Some(f) => f.pat,
729722
_ => wild()
730723
}
731-
}).collect();
732-
Some(vec::append(args, r.tail()))
724+
}).collect::<Vec<_>>();
725+
Some(args.append(r.tail()))
733726
}
734727
}
735728
}
736729
PatTup(args) => {
737-
Some(vec::append(args.iter().map(|x| *x).collect(), r.tail()))
730+
Some(args.iter().map(|x| *x).collect::<Vec<_>>().append(r.tail()))
738731
}
739732
PatUniq(a) | PatRegion(a) => {
740-
Some(vec::append(vec!(a), r.tail()))
733+
Some((vec!(a)).append(r.tail()))
741734
}
742735
PatLit(expr) => {
743736
let e_v = eval_const_expr(cx.tcx, expr);

src/librustc/middle/trans/_match.rs

+13-24
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ use util::ppaux::{Repr, vec_map_to_str};
225225

226226
use collections::HashMap;
227227
use std::cell::Cell;
228-
use std::vec;
229228
use syntax::ast;
230229
use syntax::ast::Ident;
231230
use syntax::ast_util::path_to_ident;
@@ -478,11 +477,9 @@ fn expand_nested_bindings<'r,'b>(
478477
m.iter().map(|br| {
479478
match br.pats.get(col).node {
480479
ast::PatIdent(_, ref path, Some(inner)) => {
481-
let pats = vec::append(
482-
Vec::from_slice(br.pats.slice(0u, col)),
483-
vec::append(vec!(inner),
484-
br.pats.slice(col + 1u,
485-
br.pats.len())).as_slice());
480+
let pats = Vec::from_slice(br.pats.slice(0u, col))
481+
.append((vec!(inner))
482+
.append(br.pats.slice(col + 1u, br.pats.len())).as_slice());
486483

487484
let mut res = Match {
488485
pats: pats,
@@ -527,10 +524,8 @@ fn enter_match<'r,'b>(
527524
for br in m.iter() {
528525
match e(*br.pats.get(col)) {
529526
Some(sub) => {
530-
let pats =
531-
vec::append(
532-
vec::append(sub, br.pats.slice(0u, col)),
533-
br.pats.slice(col + 1u, br.pats.len()));
527+
let pats = sub.append(br.pats.slice(0u, col))
528+
.append(br.pats.slice(col + 1u, br.pats.len()));
534529

535530
let this = *br.pats.get(col);
536531
let mut bound_ptrs = br.bound_ptrs.clone();
@@ -1557,8 +1552,7 @@ fn compile_submatch_continue<'r,
15571552
let tcx = bcx.tcx();
15581553
let dm = tcx.def_map;
15591554

1560-
let vals_left = vec::append(Vec::from_slice(vals.slice(0u, col)),
1561-
vals.slice(col + 1u, vals.len()));
1555+
let vals_left = Vec::from_slice(vals.slice(0u, col)).append(vals.slice(col + 1u, vals.len()));
15621556
let ccx = bcx.fcx.ccx;
15631557
let mut pat_id = 0;
15641558
for br in m.iter() {
@@ -1581,7 +1575,7 @@ fn compile_submatch_continue<'r,
15811575
let rec_vals = rec_fields.iter().map(|field_name| {
15821576
let ix = ty::field_idx_strict(tcx, field_name.name, field_tys);
15831577
adt::trans_field_ptr(bcx, pat_repr, val, discr, ix)
1584-
}).collect();
1578+
}).collect::<Vec<_>>();
15851579
compile_submatch(
15861580
bcx,
15871581
enter_rec_or_struct(bcx,
@@ -1590,8 +1584,7 @@ fn compile_submatch_continue<'r,
15901584
col,
15911585
rec_fields.as_slice(),
15921586
val).as_slice(),
1593-
vec::append(rec_vals,
1594-
vals_left.as_slice()).as_slice(),
1587+
rec_vals.append(vals_left.as_slice()).as_slice(),
15951588
chk);
15961589
});
15971590
return;
@@ -1616,8 +1609,7 @@ fn compile_submatch_continue<'r,
16161609
col,
16171610
val,
16181611
n_tup_elts).as_slice(),
1619-
vec::append(tup_vals,
1620-
vals_left.as_slice()).as_slice(),
1612+
tup_vals.append(vals_left.as_slice()).as_slice(),
16211613
chk);
16221614
return;
16231615
}
@@ -1642,8 +1634,7 @@ fn compile_submatch_continue<'r,
16421634
compile_submatch(bcx,
16431635
enter_tuple_struct(bcx, dm, m, col, val,
16441636
struct_element_count).as_slice(),
1645-
vec::append(llstructvals,
1646-
vals_left.as_slice()).as_slice(),
1637+
llstructvals.append(vals_left.as_slice()).as_slice(),
16471638
chk);
16481639
return;
16491640
}
@@ -1652,8 +1643,7 @@ fn compile_submatch_continue<'r,
16521643
let llbox = Load(bcx, val);
16531644
compile_submatch(bcx,
16541645
enter_uniq(bcx, dm, m, col, val).as_slice(),
1655-
vec::append(vec!(llbox),
1656-
vals_left.as_slice()).as_slice(),
1646+
(vec!(llbox)).append(vals_left.as_slice()).as_slice(),
16571647
chk);
16581648
return;
16591649
}
@@ -1662,8 +1652,7 @@ fn compile_submatch_continue<'r,
16621652
let loaded_val = Load(bcx, val);
16631653
compile_submatch(bcx,
16641654
enter_region(bcx, dm, m, col, val).as_slice(),
1665-
vec::append(vec!(loaded_val),
1666-
vals_left.as_slice()).as_slice(),
1655+
(vec!(loaded_val)).append(vals_left.as_slice()).as_slice(),
16671656
chk);
16681657
return;
16691658
}
@@ -1844,7 +1833,7 @@ fn compile_submatch_continue<'r,
18441833
lit(_) | range(_, _) => ()
18451834
}
18461835
let opt_ms = enter_opt(opt_cx, m, opt, col, size, val);
1847-
let opt_vals = vec::append(unpacked, vals_left.as_slice());
1836+
let opt_vals = unpacked.append(vals_left.as_slice());
18481837

18491838
match branch_chk {
18501839
None => {

0 commit comments

Comments
 (0)