Skip to content

Commit d1d8497

Browse files
committed
auto merge of #13588 : alexcrichton/rust/no-more-growing, r=thestinger
This is all in preparation for DST. This removes all the growable/shrinkable methods from `~[T]`.
2 parents ce2bab6 + 675b826 commit d1d8497

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+483
-1166
lines changed

src/compiletest/runtest.rs

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

3938
pub fn run(config: config, testfile: ~str) {
@@ -509,7 +508,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
509508
proc_res: &ProcRes) {
510509
511510
// true if we found the error in question
512-
let mut found_flags = slice::from_elem(
511+
let mut found_flags = Vec::from_elem(
513512
expected_errors.len(), false);
514513
515514
if proc_res.status.success() {
@@ -554,13 +553,13 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
554553
for line in proc_res.stderr.lines() {
555554
let mut was_expected = false;
556555
for (i, ee) in expected_errors.iter().enumerate() {
557-
if !found_flags[i] {
556+
if !*found_flags.get(i) {
558557
debug!("prefix={} ee.kind={} ee.msg={} line={}",
559558
*prefixes.get(i), ee.kind, ee.msg, line);
560559
if prefix_matches(line, *prefixes.get(i)) &&
561560
line.contains(ee.kind) &&
562561
line.contains(ee.msg) {
563-
found_flags[i] = true;
562+
*found_flags.get_mut(i) = true;
564563
was_expected = true;
565564
break;
566565
}

src/doc/guide-tasks.md

+10-16
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,9 @@ might look like the example below.
255255

256256
~~~
257257
# use std::task::spawn;
258-
# use std::slice;
259258
260259
// Create a vector of ports, one for each child task
261-
let rxs = slice::from_fn(3, |init_val| {
260+
let rxs = Vec::from_fn(3, |init_val| {
262261
let (tx, rx) = channel();
263262
spawn(proc() {
264263
tx.send(some_expensive_computation(init_val));
@@ -304,7 +303,6 @@ be distributed on the available cores.
304303

305304
~~~
306305
# extern crate sync;
307-
# use std::slice;
308306
fn partial_sum(start: uint) -> f64 {
309307
let mut local_sum = 0f64;
310308
for num in range(start*100000, (start+1)*100000) {
@@ -314,7 +312,7 @@ fn partial_sum(start: uint) -> f64 {
314312
}
315313
316314
fn main() {
317-
let mut futures = slice::from_fn(1000, |ind| sync::Future::spawn( proc() { partial_sum(ind) }));
315+
let mut futures = Vec::from_fn(1000, |ind| sync::Future::spawn( proc() { partial_sum(ind) }));
318316
319317
let mut final_res = 0f64;
320318
for ft in futures.mut_iter() {
@@ -342,25 +340,24 @@ a single large vector of floats. Each task needs the full vector to perform its
342340
extern crate rand;
343341
extern crate sync;
344342
345-
use std::slice;
346343
use sync::Arc;
347344
348-
fn pnorm(nums: &~[f64], p: uint) -> f64 {
345+
fn pnorm(nums: &[f64], p: uint) -> f64 {
349346
nums.iter().fold(0.0, |a,b| a+(*b).powf(&(p as f64)) ).powf(&(1.0 / (p as f64)))
350347
}
351348
352349
fn main() {
353-
let numbers = slice::from_fn(1000000, |_| rand::random::<f64>());
350+
let numbers = Vec::from_fn(1000000, |_| rand::random::<f64>());
354351
let numbers_arc = Arc::new(numbers);
355352
356353
for num in range(1u, 10) {
357354
let (tx, rx) = channel();
358355
tx.send(numbers_arc.clone());
359356
360357
spawn(proc() {
361-
let local_arc : Arc<~[f64]> = rx.recv();
358+
let local_arc : Arc<Vec<f64>> = rx.recv();
362359
let task_numbers = &*local_arc;
363-
println!("{}-norm = {}", num, pnorm(task_numbers, num));
360+
println!("{}-norm = {}", num, pnorm(task_numbers.as_slice(), num));
364361
});
365362
}
366363
}
@@ -374,9 +371,8 @@ created by the line
374371
# extern crate sync;
375372
# extern crate rand;
376373
# use sync::Arc;
377-
# use std::slice;
378374
# fn main() {
379-
# let numbers = slice::from_fn(1000000, |_| rand::random::<f64>());
375+
# let numbers = Vec::from_fn(1000000, |_| rand::random::<f64>());
380376
let numbers_arc=Arc::new(numbers);
381377
# }
382378
~~~
@@ -387,9 +383,8 @@ and a clone of it is sent to each task
387383
# extern crate sync;
388384
# extern crate rand;
389385
# use sync::Arc;
390-
# use std::slice;
391386
# fn main() {
392-
# let numbers=slice::from_fn(1000000, |_| rand::random::<f64>());
387+
# let numbers=Vec::from_fn(1000000, |_| rand::random::<f64>());
393388
# let numbers_arc = Arc::new(numbers);
394389
# let (tx, rx) = channel();
395390
tx.send(numbers_arc.clone());
@@ -404,13 +399,12 @@ Each task recovers the underlying data by
404399
# extern crate sync;
405400
# extern crate rand;
406401
# use sync::Arc;
407-
# use std::slice;
408402
# fn main() {
409-
# let numbers=slice::from_fn(1000000, |_| rand::random::<f64>());
403+
# let numbers=Vec::from_fn(1000000, |_| rand::random::<f64>());
410404
# let numbers_arc=Arc::new(numbers);
411405
# let (tx, rx) = channel();
412406
# tx.send(numbers_arc.clone());
413-
# let local_arc : Arc<~[f64]> = rx.recv();
407+
# let local_arc : Arc<Vec<f64>> = rx.recv();
414408
let task_numbers = &*local_arc;
415409
# }
416410
~~~

src/doc/tutorial.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -1582,12 +1582,12 @@ the elements are mutable if the vector is mutable.
15821582
use std::strbuf::StrBuf;
15831583

15841584
// A dynamically sized vector (unique vector)
1585-
let mut numbers = ~[1, 2, 3];
1585+
let mut numbers = vec![1, 2, 3];
15861586
numbers.push(4);
15871587
numbers.push(5);
15881588

15891589
// The type of a unique vector is written as `~[int]`
1590-
let more_numbers: ~[int] = numbers;
1590+
let more_numbers: ~[int] = numbers.move_iter().collect();
15911591

15921592
// The original `numbers` value can no longer be used, due to move semantics.
15931593

@@ -1955,8 +1955,8 @@ vector consisting of the result of applying `function` to each element
19551955
of `vector`:
19561956
19571957
~~~~
1958-
fn map<T, U>(vector: &[T], function: |v: &T| -> U) -> ~[U] {
1959-
let mut accumulator = ~[];
1958+
fn map<T, U>(vector: &[T], function: |v: &T| -> U) -> Vec<U> {
1959+
let mut accumulator = Vec::new();
19601960
for element in vector.iter() {
19611961
accumulator.push(function(element));
19621962
}

src/libnative/io/addrinfo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl GetAddrInfoRequest {
5757
}
5858

5959
// Collect all the results we found
60-
let mut addrs = ~[];
60+
let mut addrs = Vec::new();
6161
let mut rp = res;
6262
while rp.is_not_null() {
6363
unsafe {
@@ -80,7 +80,7 @@ impl GetAddrInfoRequest {
8080

8181
unsafe { freeaddrinfo(res); }
8282

83-
Ok(addrs)
83+
Ok(addrs.move_iter().collect())
8484
}
8585
}
8686

src/libnative/io/file_unix.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use libc::{c_int, c_void};
1818
use libc;
1919
use std::mem;
2020
use std::rt::rtio;
21-
use std::slice;
2221

2322
use io::{IoResult, retry, keep_going};
2423

@@ -416,7 +415,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
416415
if len == -1 {
417416
len = 1024; // FIXME: read PATH_MAX from C ffi?
418417
}
419-
let mut buf = slice::with_capacity::<u8>(len as uint);
418+
let mut buf: Vec<u8> = Vec::with_capacity(len as uint);
420419
match retry(|| unsafe {
421420
libc::readlink(p, buf.as_ptr() as *mut libc::c_char,
422421
len as libc::size_t) as libc::c_int

src/libnative/io/process.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Process {
7474
return Err(super::unimpl());
7575
}
7676

77-
fn get_io(io: p::StdioContainer, ret: &mut ~[Option<file::FileDesc>])
77+
fn get_io(io: p::StdioContainer, ret: &mut Vec<Option<file::FileDesc>>)
7878
-> (Option<os::Pipe>, c_int)
7979
{
8080
match io {
@@ -93,7 +93,7 @@ impl Process {
9393
}
9494
}
9595

96-
let mut ret_io = ~[];
96+
let mut ret_io = Vec::new();
9797
let (in_pipe, in_fd) = get_io(config.stdin, &mut ret_io);
9898
let (out_pipe, out_fd) = get_io(config.stdout, &mut ret_io);
9999
let (err_pipe, err_fd) = get_io(config.stderr, &mut ret_io);
@@ -117,7 +117,7 @@ impl Process {
117117
exit_code: None,
118118
exit_signal: None,
119119
},
120-
ret_io))
120+
ret_io.move_iter().collect()))
121121
}
122122
Err(e) => Err(e)
123123
}
@@ -641,12 +641,10 @@ fn spawn_process_os(config: p::ProcessConfig,
641641

642642
#[cfg(unix)]
643643
fn with_argv<T>(prog: &str, args: &[~str], cb: proc(**libc::c_char) -> T) -> T {
644-
use std::slice;
645-
646644
// We can't directly convert `str`s into `*char`s, as someone needs to hold
647645
// a reference to the intermediary byte buffers. So first build an array to
648646
// hold all the ~[u8] byte strings.
649-
let mut tmps = slice::with_capacity(args.len() + 1);
647+
let mut tmps = Vec::with_capacity(args.len() + 1);
650648

651649
tmps.push(prog.to_c_str());
652650

@@ -667,14 +665,12 @@ fn with_argv<T>(prog: &str, args: &[~str], cb: proc(**libc::c_char) -> T) -> T {
667665

668666
#[cfg(unix)]
669667
fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: proc(*c_void) -> T) -> T {
670-
use std::slice;
671-
672668
// On posixy systems we can pass a char** for envp, which is a
673669
// null-terminated array of "k=v\n" strings. Like `with_argv`, we have to
674670
// have a temporary buffer to hold the intermediary `~[u8]` byte strings.
675671
match env {
676672
Some(env) => {
677-
let mut tmps = slice::with_capacity(env.len());
673+
let mut tmps = Vec::with_capacity(env.len());
678674

679675
for pair in env.iter() {
680676
let kv = format!("{}={}", *pair.ref0(), *pair.ref1());
@@ -700,7 +696,7 @@ fn with_envp<T>(env: Option<~[(~str, ~str)]>, cb: |*mut c_void| -> T) -> T {
700696
// \0 to terminate.
701697
match env {
702698
Some(env) => {
703-
let mut blk = ~[];
699+
let mut blk = Vec::new();
704700

705701
for pair in env.iter() {
706702
let kv = format!("{}={}", *pair.ref0(), *pair.ref1());

src/librustc/back/rpath.rs

-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@ pub fn minimize_rpaths(rpaths: &[~str]) -> Vec<~str> {
156156

157157
#[cfg(unix, test)]
158158
mod test {
159-
use std::os;
160-
161159
use back::rpath::get_install_prefix_rpath;
162160
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
163161
use syntax::abi;

src/librustc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ pub fn describe_codegen_flags() {
223223
}
224224

225225
pub fn run_compiler(args: &[~str]) {
226-
let mut args = args.to_owned();
226+
let mut args = Vec::from_slice(args);
227227
let binary = args.shift().unwrap();
228228

229229
if args.is_empty() { usage(binary); return; }
230230

231231
let matches =
232-
&match getopts::getopts(args, d::optgroups().as_slice()) {
232+
&match getopts::getopts(args.as_slice(), d::optgroups().as_slice()) {
233233
Ok(m) => m,
234234
Err(f) => {
235235
d::early_error(f.to_err_msg());

src/librustc/middle/dataflow.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919

2020
use std::io;
21-
use std::slice;
2221
use std::strbuf::StrBuf;
2322
use std::uint;
2423
use syntax::ast;
@@ -308,13 +307,13 @@ impl<'a, O:DataFlowOperator+Clone+'static> DataFlowContext<'a, O> {
308307
changed: true
309308
};
310309

311-
let mut temp = slice::from_elem(self.words_per_id, 0u);
310+
let mut temp = Vec::from_elem(self.words_per_id, 0u);
312311
let mut loop_scopes = Vec::new();
313312

314313
while propcx.changed {
315314
propcx.changed = false;
316-
propcx.reset(temp);
317-
propcx.walk_block(blk, temp, &mut loop_scopes);
315+
propcx.reset(temp.as_mut_slice());
316+
propcx.walk_block(blk, temp.as_mut_slice(), &mut loop_scopes);
318317
}
319318
}
320319

src/librustc/middle/trans/callee.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
* closure.
1717
*/
1818

19-
use std::slice;
20-
2119
use back::abi;
2220
use driver::session;
2321
use lib::llvm::{ValueRef, NoAliasAttribute, StructRetAttribute, NoCaptureAttribute};
@@ -221,11 +219,12 @@ fn resolve_default_method_vtables(bcx: &Block,
221219
Some(vtables) => {
222220
let num_impl_type_parameters =
223221
vtables.len() - num_method_vtables;
224-
vtables.tailn(num_impl_type_parameters).to_owned()
222+
Vec::from_slice(vtables.tailn(num_impl_type_parameters))
225223
},
226-
None => slice::from_elem(num_method_vtables, @Vec::new())
224+
None => Vec::from_elem(num_method_vtables, @Vec::new())
227225
};
228226

227+
let method_vtables = method_vtables.as_slice();
229228
let param_vtables = @((*trait_vtables_fixed).clone().append(method_vtables));
230229

231230
let self_vtables = resolve_param_vtables_under_param_substs(

src/librustc/middle/trans/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,11 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
593593
const_eval::const_uint(i) => i as uint,
594594
_ => cx.sess().span_bug(count.span, "count must be integral const expression.")
595595
};
596-
let vs = slice::from_elem(n, const_expr(cx, elem, is_local).val0());
596+
let vs = Vec::from_elem(n, const_expr(cx, elem, is_local).val0());
597597
let v = if vs.iter().any(|vi| val_ty(*vi) != llunitty) {
598-
C_struct(cx, vs, false)
598+
C_struct(cx, vs.as_slice(), false)
599599
} else {
600-
C_array(llunitty, vs)
600+
C_array(llunitty, vs.as_slice())
601601
};
602602
(v, true)
603603
}

src/librustc/middle/trans/debuginfo.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ use collections::HashMap;
148148
use collections::HashSet;
149149
use libc::{c_uint, c_ulonglong, c_longlong};
150150
use std::ptr;
151-
use std::slice;
152151
use std::strbuf::StrBuf;
153152
use std::sync::atomics;
154153
use syntax::codemap::{Span, Pos};
@@ -776,7 +775,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
776775
return create_DIArray(DIB(cx), []);
777776
}
778777

779-
let mut signature = slice::with_capacity(fn_decl.inputs.len() + 1);
778+
let mut signature = Vec::with_capacity(fn_decl.inputs.len() + 1);
780779

781780
// Return type -- llvm::DIBuilder wants this at index 0
782781
match fn_decl.output.node {
@@ -818,7 +817,7 @@ pub fn create_function_debug_context(cx: &CrateContext,
818817
signature.push(type_metadata(cx, arg_type, codemap::DUMMY_SP));
819818
}
820819

821-
return create_DIArray(DIB(cx), signature);
820+
return create_DIArray(DIB(cx), signature.as_slice());
822821
}
823822

824823
fn get_template_parameters(cx: &CrateContext,
@@ -961,15 +960,15 @@ fn compile_unit_metadata(cx: &CrateContext) {
961960
// prepend "./" if necessary
962961
let dotdot = bytes!("..");
963962
let prefix = &[dotdot[0], ::std::path::SEP_BYTE];
964-
let mut path_bytes = p.as_vec().to_owned();
963+
let mut path_bytes = Vec::from_slice(p.as_vec());
965964

966965
if path_bytes.slice_to(2) != prefix &&
967966
path_bytes.slice_to(2) != dotdot {
968967
path_bytes.insert(0, prefix[0]);
969968
path_bytes.insert(1, prefix[1]);
970969
}
971970

972-
path_bytes.to_c_str()
971+
path_bytes.as_slice().to_c_str()
973972
}
974973
_ => fallback_path(cx)
975974
}

0 commit comments

Comments
 (0)