diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index c5ec19813065c..be3ed62e42265 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -17,6 +17,7 @@ extern crate test; extern crate getopts; use std::os; +use std::vec_ng::Vec; use std::io; use std::io::fs; use getopts::{optopt, optflag, reqopt}; @@ -39,15 +40,15 @@ pub mod errors; pub fn main() { let args = os::args(); - let config = parse_config(args); + let config = parse_config(args.move_iter().collect()); log_config(&config); run_tests(&config); } -pub fn parse_config(args: ~[~str]) -> config { +pub fn parse_config(args: Vec<~str> ) -> config { - let groups : ~[getopts::OptGroup] = - ~[reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"), + let groups : Vec = + vec!(reqopt("", "compile-lib-path", "path to host shared libraries", "PATH"), reqopt("", "run-lib-path", "path to target shared libraries", "PATH"), reqopt("", "rustc-path", "path to rustc to use for compiling", "PATH"), optopt("", "clang-path", "path to executable for codegen tests", "PATH"), @@ -75,28 +76,27 @@ pub fn parse_config(args: ~[~str]) -> config { optopt("", "adb-path", "path to the android debugger", "PATH"), optopt("", "adb-test-dir", "path to tests for the android debugger", "PATH"), optopt("", "test-shard", "run shard A, of B shards, worth of the testsuite", "A.B"), - optflag("h", "help", "show this message"), - ]; + optflag("h", "help", "show this message")); assert!(!args.is_empty()); - let argv0 = args[0].clone(); + let argv0 = (*args.get(0)).clone(); let args_ = args.tail(); - if args[1] == ~"-h" || args[1] == ~"--help" { + if *args.get(1) == ~"-h" || *args.get(1) == ~"--help" { let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0); - println!("{}", getopts::usage(message, groups)); + println!("{}", getopts::usage(message, groups.as_slice())); println!(""); fail!() } let matches = - &match getopts::getopts(args_, groups) { + &match getopts::getopts(args_, groups.as_slice()) { Ok(m) => m, Err(f) => fail!("{}", f.to_err_msg()) }; if matches.opt_present("h") || matches.opt_present("help") { let message = format!("Usage: {} [OPTIONS] [TESTNAME...]", argv0); - println!("{}", getopts::usage(message, groups)); + println!("{}", getopts::usage(message, groups.as_slice())); println!(""); fail!() } @@ -119,7 +119,7 @@ pub fn parse_config(args: ~[~str]) -> config { run_ignored: matches.opt_present("ignored"), filter: if !matches.free.is_empty() { - Some(matches.free[0].clone()) + Some((*matches.free.get(0)).clone()) } else { None }, @@ -235,7 +235,7 @@ pub fn run_tests(config: &config) { // parallel (especially when we have lots and lots of child processes). // For context, see #8904 io::test::raise_fd_limit(); - let res = test::run_tests_console(&opts, tests); + let res = test::run_tests_console(&opts, tests.move_iter().collect()); match res { Ok(true) => {} Ok(false) => fail!("Some tests failed"), @@ -259,10 +259,10 @@ pub fn test_opts(config: &config) -> test::TestOpts { } } -pub fn make_tests(config: &config) -> ~[test::TestDescAndFn] { +pub fn make_tests(config: &config) -> Vec { debug!("making tests from {}", config.src_base.display()); - let mut tests = ~[]; + let mut tests = Vec::new(); let dirs = fs::readdir(&config.src_base).unwrap(); for file in dirs.iter() { let file = file.clone(); @@ -284,10 +284,10 @@ pub fn is_test(config: &config, testfile: &Path) -> bool { // Pretty-printer does not work with .rc files yet let valid_extensions = match config.mode { - mode_pretty => ~[~".rs"], - _ => ~[~".rc", ~".rs"] + mode_pretty => vec!(~".rs"), + _ => vec!(~".rc", ~".rs") }; - let invalid_prefixes = ~[~".", ~"#", ~"~"]; + let invalid_prefixes = vec!(~".", ~"#", ~"~"); let name = testfile.filename_str().unwrap(); let mut valid = false; diff --git a/src/compiletest/errors.rs b/src/compiletest/errors.rs index 3a6b1666c1e79..c578b3ce6d47f 100644 --- a/src/compiletest/errors.rs +++ b/src/compiletest/errors.rs @@ -9,13 +9,14 @@ // except according to those terms. use std::io::{BufferedReader, File}; +use std::vec_ng::Vec; pub struct ExpectedError { line: uint, kind: ~str, msg: ~str } // Load any test directives embedded in the file -pub fn load_errors(testfile: &Path) -> ~[ExpectedError] { +pub fn load_errors(testfile: &Path) -> Vec { - let mut error_patterns = ~[]; + let mut error_patterns = Vec::new(); let mut rdr = BufferedReader::new(File::open(testfile).unwrap()); let mut line_num = 1u; for ln in rdr.lines() { @@ -25,12 +26,12 @@ pub fn load_errors(testfile: &Path) -> ~[ExpectedError] { return error_patterns; } -fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] { +fn parse_expected(line_num: uint, line: ~str) -> Vec { let line = line.trim(); let error_tag = ~"//~"; let mut idx; match line.find_str(error_tag) { - None => return ~[], + None => return Vec::new(), Some(nn) => { idx = (nn as uint) + error_tag.len(); } } @@ -57,6 +58,6 @@ fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] { debug!("line={} kind={} msg={}", line_num - adjust_line, kind, msg); - return ~[ExpectedError{line: line_num - adjust_line, kind: kind, - msg: msg}]; + return vec!(ExpectedError{line: line_num - adjust_line, kind: kind, + msg: msg}); } diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index 7f8be5ff090e6..4793d0f8ba4da 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -12,22 +12,24 @@ use common::config; use common; use util; +use std::vec_ng::Vec; + pub struct TestProps { // Lines that should be expected, in order, on standard out - error_patterns: ~[~str], + error_patterns: Vec<~str> , // Extra flags to pass to the compiler compile_flags: Option<~str>, // If present, the name of a file that this test should match when // pretty-printed pp_exact: Option, // Modules from aux directory that should be compiled - aux_builds: ~[~str], + aux_builds: Vec<~str> , // Environment settings to use during execution - exec_env: ~[(~str,~str)], + exec_env: Vec<(~str,~str)> , // Commands to be given to the debugger, when testing debug info - debugger_cmds: ~[~str], + debugger_cmds: Vec<~str> , // Lines to check if they appear in the expected debugger output - check_lines: ~[~str], + check_lines: Vec<~str> , // Flag to force a crate to be built with the host architecture force_host: bool, // Check stdout for error-pattern output as well as stderr @@ -38,13 +40,13 @@ pub struct TestProps { // Load any test directives embedded in the file pub fn load_props(testfile: &Path) -> TestProps { - let mut error_patterns = ~[]; - let mut aux_builds = ~[]; - let mut exec_env = ~[]; + let mut error_patterns = Vec::new(); + let mut aux_builds = Vec::new(); + let mut exec_env = Vec::new(); let mut compile_flags = None; let mut pp_exact = None; - let mut debugger_cmds = ~[]; - let mut check_lines = ~[]; + let mut debugger_cmds = Vec::new(); + let mut check_lines = Vec::new(); let mut force_host = false; let mut check_stdout = false; let mut no_prefer_dynamic = false; @@ -182,7 +184,7 @@ fn parse_no_prefer_dynamic(line: &str) -> bool { fn parse_exec_env(line: &str) -> Option<(~str, ~str)> { parse_name_value_directive(line, ~"exec-env").map(|nv| { // nv is either FOO or FOO=BAR - let mut strs: ~[~str] = nv.splitn('=', 1).map(|s| s.to_owned()).collect(); + let mut strs: Vec<~str> = nv.splitn('=', 1).map(|s| s.to_owned()).collect(); match strs.len() { 1u => (strs.pop().unwrap(), ~""), diff --git a/src/compiletest/procsrv.rs b/src/compiletest/procsrv.rs index 5db01399992e8..91d221034cd98 100644 --- a/src/compiletest/procsrv.rs +++ b/src/compiletest/procsrv.rs @@ -11,9 +11,11 @@ use std::os; use std::str; use std::io::process::{ProcessExit, Process, ProcessConfig, ProcessOutput}; +use std::vec_ng::Vec; +use std::vec_ng; #[cfg(target_os = "win32")] -fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] { +fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> { let mut env = os::env(); @@ -35,11 +37,11 @@ fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] { #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] #[cfg(target_os = "freebsd")] -fn target_env(lib_path: &str, prog: &str) -> ~[(~str,~str)] { +fn target_env(lib_path: &str, prog: &str) -> Vec<(~str,~str)> { // Make sure we include the aux directory in the path let aux_path = prog + ".libaux"; - let mut env = os::env(); + let mut env: Vec<(~str,~str)> = os::env().move_iter().collect(); let var = if cfg!(target_os = "macos") { "DYLD_LIBRARY_PATH" } else { @@ -62,10 +64,11 @@ pub struct Result {status: ProcessExit, out: ~str, err: ~str} pub fn run(lib_path: &str, prog: &str, args: &[~str], - env: ~[(~str, ~str)], + env: Vec<(~str, ~str)> , input: Option<~str>) -> Option { - let env = env + target_env(lib_path, prog); + let env = vec_ng::append(env.clone(), + target_env(lib_path, prog).as_slice()); let mut opt_process = Process::configure(ProcessConfig { program: prog, args: args, @@ -93,10 +96,11 @@ pub fn run(lib_path: &str, pub fn run_background(lib_path: &str, prog: &str, args: &[~str], - env: ~[(~str, ~str)], + env: Vec<(~str, ~str)> , input: Option<~str>) -> Option { - let env = env + target_env(lib_path, prog); + let env = vec_ng::append(env.clone(), + target_env(lib_path, prog).as_slice()); let opt_process = Process::configure(ProcessConfig { program: prog, args: args, diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 47e1118459d67..efd97893998df 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -33,6 +33,8 @@ use std::os; use std::str; use std::task; use std::vec; +use std::vec_ng::Vec; +use std::vec_ng; use test::MetricMap; @@ -155,12 +157,14 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) { let src = File::open(testfile).read_to_end().unwrap(); let src = str::from_utf8_owned(src).unwrap(); - let mut srcs = ~[src]; + let mut srcs = vec!(src); let mut round = 0; while round < rounds { logv(config, format!("pretty-printing round {}", round)); - let proc_res = print_source(config, testfile, srcs[round].clone()); + let proc_res = print_source(config, + testfile, + (*srcs.get(round)).clone()); if !proc_res.status.success() { fatal_ProcRes(format!("pretty-printing failed in round {}", round), @@ -178,9 +182,9 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) { let s = File::open(&filepath).read_to_end().unwrap(); str::from_utf8_owned(s).unwrap() } - None => { srcs[srcs.len() - 2u].clone() } + None => { (*srcs.get(srcs.len() - 2u)).clone() } }; - let mut actual = srcs[srcs.len() - 1u].clone(); + let mut actual = (*srcs.get(srcs.len() - 1u)).clone(); if props.pp_exact.is_some() { // Now we have to care about line endings @@ -202,12 +206,12 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) { fn print_source(config: &config, testfile: &Path, src: ~str) -> ProcRes { compose_and_run(config, testfile, make_pp_args(config, testfile), - ~[], config.compile_lib_path, Some(src)) + Vec::new(), config.compile_lib_path, Some(src)) } fn make_pp_args(config: &config, _testfile: &Path) -> ProcArgs { - let args = ~[~"-", ~"--pretty", ~"normal", - ~"--target=" + config.target]; + let args = vec!(~"-", ~"--pretty", ~"normal", + ~"--target=" + config.target); // FIXME (#9639): This needs to handle non-utf8 paths return ProcArgs {prog: config.rustc_path.as_str().unwrap().to_owned(), args: args}; } @@ -244,12 +248,12 @@ actual:\n\ config.target.as_slice() }; // FIXME (#9639): This needs to handle non-utf8 paths - let mut args = ~[~"-", + let mut args = vec!(~"-", ~"--no-trans", ~"--crate-type=lib", ~"--target=" + target, ~"-L", config.build_base.as_str().unwrap().to_owned(), ~"-L", - aux_dir.as_str().unwrap().to_owned()]; + aux_dir.as_str().unwrap().to_owned()); args.push_all_move(split_maybe_args(&config.target_rustcflags)); args.push_all_move(split_maybe_args(&props.compile_flags)); // FIXME (#9639): This needs to handle non-utf8 paths @@ -295,12 +299,12 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { procsrv::run("", config.adb_path, [~"push", exe_file.as_str().unwrap().to_owned(), config.adb_test_dir.clone()], - ~[(~"",~"")], Some(~"")) + vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); procsrv::run("", config.adb_path, [~"forward", ~"tcp:5039", ~"tcp:5039"], - ~[(~"",~"")], Some(~"")) + vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); let adb_arg = format!("export LD_LIBRARY_PATH={}; gdbserver :5039 {}/{}", @@ -309,7 +313,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { let mut process = procsrv::run_background("", config.adb_path, [~"shell",adb_arg.clone()], - ~[(~"",~"")], Some(~"")) + vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); loop { //waiting 1 second for gdbserver start @@ -341,17 +345,21 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { let debugger_script = make_out_name(config, testfile, "debugger.script"); // FIXME (#9639): This needs to handle non-utf8 paths - let debugger_opts = ~[~"-quiet", ~"-batch", ~"-nx", - "-command=" + debugger_script.as_str().unwrap().to_owned()]; + let debugger_opts = vec!(~"-quiet", ~"-batch", ~"-nx", + "-command=" + debugger_script.as_str().unwrap().to_owned()); let gdb_path = tool_path.append("/bin/arm-linux-androideabi-gdb"); let procsrv::Result{ out, err, status }= procsrv::run("", gdb_path, - debugger_opts, ~[(~"",~"")], None) + debugger_opts.as_slice(), + vec!((~"",~"")), + None) .expect(format!("failed to exec `{}`", gdb_path)); let cmdline = { - let cmdline = make_cmdline("", "arm-linux-androideabi-gdb", debugger_opts); + let cmdline = make_cmdline("", + "arm-linux-androideabi-gdb", + debugger_opts.as_slice()); logv(config, format!("executing {}", cmdline)); cmdline }; @@ -380,11 +388,11 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { let debugger_script = make_out_name(config, testfile, "debugger.script"); // FIXME (#9639): This needs to handle non-utf8 paths - let debugger_opts = ~[~"-quiet", ~"-batch", ~"-nx", + let debugger_opts = vec!(~"-quiet", ~"-batch", ~"-nx", "-command=" + debugger_script.as_str().unwrap().to_owned(), - exe_file.as_str().unwrap().to_owned()]; + exe_file.as_str().unwrap().to_owned()); proc_args = ProcArgs {prog: debugger(), args: debugger_opts}; - proc_res = compose_and_run(config, testfile, proc_args, ~[], "", None); + proc_res = compose_and_run(config, testfile, proc_args, Vec::new(), "", None); } } @@ -395,7 +403,10 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { if num_check_lines > 0 { // Allow check lines to leave parts unspecified (e.g., uninitialized // bits in the wrong case of an enum) with the notation "[...]". - let check_fragments: ~[~[&str]] = check_lines.map(|s| s.split_str("[...]").collect()); + let check_fragments: Vec> = + check_lines.iter().map(|s| { + s.split_str("[...]").map(|x| x.to_str()).collect() + }).collect(); // check if each line in props.check_lines appears in the // output (in order) let mut i = 0u; @@ -403,11 +414,11 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { let mut rest = line.trim(); let mut first = true; let mut failed = false; - for &frag in check_fragments[i].iter() { + for frag in check_fragments.get(i).iter() { let found = if first { - if rest.starts_with(frag) { Some(0) } else { None } + if rest.starts_with(*frag) { Some(0) } else { None } } else { - rest.find_str(frag) + rest.find_str(*frag) }; match found { None => { @@ -430,7 +441,7 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) { } if i != num_check_lines { fatal_ProcRes(format!("line not found in debugger output: {}", - check_lines[i]), &proc_res); + *check_lines.get(i)), &proc_res); } } @@ -461,7 +472,7 @@ fn check_error_patterns(props: &TestProps, } let mut next_err_idx = 0u; - let mut next_err_pat = &props.error_patterns[next_err_idx]; + let mut next_err_pat = props.error_patterns.get(next_err_idx); let mut done = false; let output_to_check = if props.check_stdout { proc_res.stdout + proc_res.stderr @@ -477,7 +488,7 @@ fn check_error_patterns(props: &TestProps, done = true; break; } - next_err_pat = &props.error_patterns[next_err_idx]; + next_err_pat = props.error_patterns.get(next_err_idx); } } if done { return; } @@ -495,7 +506,7 @@ fn check_error_patterns(props: &TestProps, } } -fn check_expected_errors(expected_errors: ~[errors::ExpectedError], +fn check_expected_errors(expected_errors: Vec , testfile: &Path, proc_res: &ProcRes) { @@ -509,12 +520,12 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError], let prefixes = expected_errors.iter().map(|ee| { format!("{}:{}:", testfile.display(), ee.line) - }).collect::<~[~str]>(); + }).collect:: >(); #[cfg(target_os = "win32")] fn to_lower( s : &str ) -> ~str { let i = s.chars(); - let c : ~[char] = i.map( |c| { + let c : Vec = i.map( |c| { if c.is_ascii() { c.to_ascii().to_lower().to_char() } else { @@ -547,8 +558,8 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError], for (i, ee) in expected_errors.iter().enumerate() { if !found_flags[i] { debug!("prefix={} ee.kind={} ee.msg={} line={}", - prefixes[i], ee.kind, ee.msg, line); - if prefix_matches(line, prefixes[i]) && + *prefixes.get(i), ee.kind, ee.msg, line); + if prefix_matches(line, *prefixes.get(i)) && line.contains(ee.kind) && line.contains(ee.msg) { found_flags[i] = true; @@ -572,7 +583,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError], for (i, &flag) in found_flags.iter().enumerate() { if !flag { - let ee = &expected_errors[i]; + let ee = expected_errors.get(i); fatal_ProcRes(format!("expected {} on line {} not found: {}", ee.kind, ee.line, ee.msg), proc_res); } @@ -654,7 +665,7 @@ fn scan_string(haystack: &str, needle: &str, idx: &mut uint) -> bool { return true; } -struct ProcArgs {prog: ~str, args: ~[~str]} +struct ProcArgs {prog: ~str, args: Vec<~str> } struct ProcRes {status: ProcessExit, stdout: ~str, stderr: ~str, cmdline: ~str} @@ -671,8 +682,10 @@ fn compile_test_(config: &config, props: &TestProps, testfile: &Path, extra_args: &[~str]) -> ProcRes { let aux_dir = aux_output_dir_name(config, testfile); // FIXME (#9639): This needs to handle non-utf8 paths - let link_args = ~[~"-L", aux_dir.as_str().unwrap().to_owned()]; - let args = make_compile_args(config, props, link_args + extra_args, + let link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned()); + let args = make_compile_args(config, + props, + vec_ng::append(link_args, extra_args), |a, b| ThisFile(make_exe_name(a, b)), testfile); compose_and_run_compiler(config, props, testfile, args, None) } @@ -710,23 +723,26 @@ fn compose_and_run_compiler( let aux_dir = aux_output_dir_name(config, testfile); // FIXME (#9639): This needs to handle non-utf8 paths - let extra_link_args = ~[~"-L", aux_dir.as_str().unwrap().to_owned()]; + let extra_link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned()); for rel_ab in props.aux_builds.iter() { let abs_ab = config.aux_base.join(rel_ab.as_slice()); let aux_props = load_props(&abs_ab); let crate_type = if aux_props.no_prefer_dynamic { - ~[] + Vec::new() } else { - ~[~"--crate-type=dylib"] + vec!(~"--crate-type=dylib") }; let aux_args = - make_compile_args(config, &aux_props, crate_type + extra_link_args, + make_compile_args(config, + &aux_props, + vec_ng::append(crate_type, + extra_link_args.as_slice()), |a,b| { let f = make_lib_name(a, b, testfile); ThisDirectory(f.dir_path()) }, &abs_ab); - let auxres = compose_and_run(config, &abs_ab, aux_args, ~[], + let auxres = compose_and_run(config, &abs_ab, aux_args, Vec::new(), config.compile_lib_path, None); if !auxres.status.success() { fatal_ProcRes( @@ -745,7 +761,7 @@ fn compose_and_run_compiler( } } - compose_and_run(config, testfile, args, ~[], + compose_and_run(config, testfile, args, Vec::new(), config.compile_lib_path, input) } @@ -756,7 +772,7 @@ fn ensure_dir(path: &Path) { fn compose_and_run(config: &config, testfile: &Path, ProcArgs{ args, prog }: ProcArgs, - procenv: ~[(~str, ~str)], + procenv: Vec<(~str, ~str)> , lib_path: &str, input: Option<~str>) -> ProcRes { return program_output(config, testfile, lib_path, @@ -770,7 +786,7 @@ enum TargetLocation { fn make_compile_args(config: &config, props: &TestProps, - extras: ~[~str], + extras: Vec<~str> , xform: |&config, &Path| -> TargetLocation, testfile: &Path) -> ProcArgs { @@ -781,10 +797,10 @@ fn make_compile_args(config: &config, config.target.as_slice() }; // FIXME (#9639): This needs to handle non-utf8 paths - let mut args = ~[testfile.as_str().unwrap().to_owned(), + let mut args = vec!(testfile.as_str().unwrap().to_owned(), ~"-L", config.build_base.as_str().unwrap().to_owned(), - ~"--target=" + target] - + extras; + ~"--target=" + target); + args.push_all(extras.as_slice()); if !props.no_prefer_dynamic { args.push(~"-C"); args.push(~"prefer-dynamic"); @@ -833,28 +849,28 @@ fn make_run_args(config: &config, _props: &TestProps, testfile: &Path) -> return ProcArgs {prog: prog, args: args}; } -fn split_maybe_args(argstr: &Option<~str>) -> ~[~str] { +fn split_maybe_args(argstr: &Option<~str>) -> Vec<~str> { match *argstr { Some(ref s) => { s.split(' ') .filter_map(|s| if s.is_whitespace() {None} else {Some(s.to_owned())}) .collect() } - None => ~[] + None => Vec::new() } } fn program_output(config: &config, testfile: &Path, lib_path: &str, prog: ~str, - args: ~[~str], env: ~[(~str, ~str)], + args: Vec<~str> , env: Vec<(~str, ~str)> , input: Option<~str>) -> ProcRes { let cmdline = { - let cmdline = make_cmdline(lib_path, prog, args); + let cmdline = make_cmdline(lib_path, prog, args.as_slice()); logv(config, format!("executing {}", cmdline)); cmdline }; let procsrv::Result{ out, err, status } = - procsrv::run(lib_path, prog, args, env, input) + procsrv::run(lib_path, prog, args.as_slice(), env, input) .expect(format!("failed to exec `{}`", prog)); dump_output(config, testfile, out, err); return ProcRes {status: status, @@ -951,19 +967,19 @@ stderr:\n\ } fn _arm_exec_compiled_test(config: &config, props: &TestProps, - testfile: &Path, env: ~[(~str, ~str)]) -> ProcRes { + testfile: &Path, env: Vec<(~str, ~str)> ) -> ProcRes { let args = make_run_args(config, props, testfile); - let cmdline = make_cmdline("", args.prog, args.args); + let cmdline = make_cmdline("", args.prog, args.args.as_slice()); // get bare program string - let mut tvec: ~[~str] = args.prog.split('/').map(|ts| ts.to_owned()).collect(); + let mut tvec: Vec<~str> = args.prog.split('/').map(|ts| ts.to_owned()).collect(); let prog_short = tvec.pop().unwrap(); // copy to target let copy_result = procsrv::run("", config.adb_path, [~"push", args.prog.clone(), config.adb_test_dir.clone()], - ~[(~"",~"")], Some(~"")) + vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); if config.verbose { @@ -974,7 +990,7 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps, logv(config, format!("executing ({}) {}", config.target, cmdline)); - let mut runargs = ~[]; + let mut runargs = Vec::new(); // run test via adb_run_wrapper runargs.push(~"shell"); @@ -988,17 +1004,20 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps, for tv in args.args.iter() { runargs.push(tv.to_owned()); } - procsrv::run("", config.adb_path, runargs, ~[(~"",~"")], Some(~"")) + procsrv::run("", + config.adb_path, + runargs.as_slice(), + vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); // get exitcode of result - runargs = ~[]; + runargs = Vec::new(); runargs.push(~"shell"); runargs.push(~"cat"); runargs.push(format!("{}/{}.exitcode", config.adb_test_dir, prog_short)); let procsrv::Result{ out: exitcode_out, err: _, status: _ } = - procsrv::run("", config.adb_path, runargs, ~[(~"",~"")], + procsrv::run("", config.adb_path, runargs.as_slice(), vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); @@ -1012,23 +1031,29 @@ fn _arm_exec_compiled_test(config: &config, props: &TestProps, } // get stdout of result - runargs = ~[]; + runargs = Vec::new(); runargs.push(~"shell"); runargs.push(~"cat"); runargs.push(format!("{}/{}.stdout", config.adb_test_dir, prog_short)); let procsrv::Result{ out: stdout_out, err: _, status: _ } = - procsrv::run("", config.adb_path, runargs, ~[(~"",~"")], Some(~"")) + procsrv::run("", + config.adb_path, + runargs.as_slice(), + vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); // get stderr of result - runargs = ~[]; + runargs = Vec::new(); runargs.push(~"shell"); runargs.push(~"cat"); runargs.push(format!("{}/{}.stderr", config.adb_test_dir, prog_short)); let procsrv::Result{ out: stderr_out, err: _, status: _ } = - procsrv::run("", config.adb_path, runargs, ~[(~"",~"")], Some(~"")) + procsrv::run("", + config.adb_path, + runargs.as_slice(), + vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); dump_output(config, testfile, stdout_out, stderr_out); @@ -1050,7 +1075,7 @@ fn _arm_push_aux_shared_library(config: &config, testfile: &Path) { // FIXME (#9639): This needs to handle non-utf8 paths let copy_result = procsrv::run("", config.adb_path, [~"push", file.as_str().unwrap().to_owned(), config.adb_test_dir.clone()], - ~[(~"",~"")], Some(~"")) + vec!((~"",~"")), Some(~"")) .expect(format!("failed to exec `{}`", config.adb_path)); if config.verbose { @@ -1081,10 +1106,12 @@ fn compile_test_and_save_bitcode(config: &config, props: &TestProps, testfile: &Path) -> ProcRes { let aux_dir = aux_output_dir_name(config, testfile); // FIXME (#9639): This needs to handle non-utf8 paths - let link_args = ~[~"-L", aux_dir.as_str().unwrap().to_owned()]; - let llvm_args = ~[~"--emit=obj", ~"--crate-type=lib", ~"-C", ~"save-temps"]; - let args = make_compile_args(config, props, - link_args + llvm_args, + let link_args = vec!(~"-L", aux_dir.as_str().unwrap().to_owned()); + let llvm_args = vec!(~"--emit=obj", ~"--crate-type=lib", ~"-C", ~"save-temps"); + let args = make_compile_args(config, + props, + vec_ng::append(link_args, + llvm_args.as_slice()), |a, b| ThisFile(make_o_name(a, b)), testfile); compose_and_run_compiler(config, props, testfile, args, None) } @@ -1097,12 +1124,12 @@ fn compile_cc_with_clang_and_save_bitcode(config: &config, _props: &TestProps, let proc_args = ProcArgs { // FIXME (#9639): This needs to handle non-utf8 paths prog: config.clang_path.get_ref().as_str().unwrap().to_owned(), - args: ~[~"-c", + args: vec!(~"-c", ~"-emit-llvm", ~"-o", bitcodefile.as_str().unwrap().to_owned(), - testcc.as_str().unwrap().to_owned() ] + testcc.as_str().unwrap().to_owned() ) }; - compose_and_run(config, testfile, proc_args, ~[], "", None) + compose_and_run(config, testfile, proc_args, Vec::new(), "", None) } fn extract_function_from_bitcode(config: &config, _props: &TestProps, @@ -1115,11 +1142,11 @@ fn extract_function_from_bitcode(config: &config, _props: &TestProps, let proc_args = ProcArgs { // FIXME (#9639): This needs to handle non-utf8 paths prog: prog.as_str().unwrap().to_owned(), - args: ~["-func=" + fname, + args: vec!("-func=" + fname, "-o=" + extracted_bc.as_str().unwrap(), - bitcodefile.as_str().unwrap().to_owned() ] + bitcodefile.as_str().unwrap().to_owned() ) }; - compose_and_run(config, testfile, proc_args, ~[], "", None) + compose_and_run(config, testfile, proc_args, Vec::new(), "", None) } fn disassemble_extract(config: &config, _props: &TestProps, @@ -1132,10 +1159,10 @@ fn disassemble_extract(config: &config, _props: &TestProps, let proc_args = ProcArgs { // FIXME (#9639): This needs to handle non-utf8 paths prog: prog.as_str().unwrap().to_owned(), - args: ~["-o=" + extracted_ll.as_str().unwrap(), - extracted_bc.as_str().unwrap().to_owned() ] + args: vec!("-o=" + extracted_ll.as_str().unwrap(), + extracted_bc.as_str().unwrap().to_owned() ) }; - compose_and_run(config, testfile, proc_args, ~[], "", None) + compose_and_run(config, testfile, proc_args, Vec::new(), "", None) } diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 1fc88eda37b5f..d0e2e079ef82c 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -27,6 +27,7 @@ extern crate collections; use collections::list::{List, Cons, Nil}; use std::cast::{transmute, transmute_mut, transmute_mut_region}; +use std::vec_ng::Vec; use std::cast; use std::cell::{Cell, RefCell}; use std::mem; @@ -38,14 +39,13 @@ use std::rc::Rc; use std::rt::global_heap; use std::intrinsics::{TyDesc, get_tydesc}; use std::intrinsics; -use std::vec; // The way arena uses arrays is really deeply awful. The arrays are // allocated, and have capacities reserved, but the fill for the array // will always stay at 0. #[deriving(Clone, Eq)] struct Chunk { - data: Rc>, + data: Rc >>, fill: Cell, is_pod: Cell, } @@ -107,7 +107,7 @@ impl Arena { fn chunk(size: uint, is_pod: bool) -> Chunk { Chunk { - data: Rc::new(RefCell::new(vec::with_capacity(size))), + data: Rc::new(RefCell::new(Vec::with_capacity(size))), fill: Cell::new(0u), is_pod: Cell::new(is_pod), } @@ -485,6 +485,9 @@ impl Drop for TypedArena { #[cfg(test)] mod tests { extern crate test; + + use std::vec_ng::Vec; + use self::test::BenchHarness; use super::{Arena, TypedArena}; @@ -545,7 +548,7 @@ mod tests { struct Nonpod { string: ~str, - array: ~[int], + array: Vec , } #[test] @@ -554,7 +557,7 @@ mod tests { for _ in range(0, 100000) { arena.alloc(Nonpod { string: ~"hello world", - array: ~[ 1, 2, 3, 4, 5 ], + array: vec!( 1, 2, 3, 4, 5 ), }); } } @@ -565,7 +568,7 @@ mod tests { bh.iter(|| { arena.alloc(Nonpod { string: ~"hello world", - array: ~[ 1, 2, 3, 4, 5 ], + array: vec!( 1, 2, 3, 4, 5 ), }) }) } @@ -575,7 +578,7 @@ mod tests { bh.iter(|| { ~Nonpod { string: ~"hello world", - array: ~[ 1, 2, 3, 4, 5 ], + array: vec!( 1, 2, 3, 4, 5 ), } }) } @@ -586,7 +589,7 @@ mod tests { bh.iter(|| { arena.alloc(|| Nonpod { string: ~"hello world", - array: ~[ 1, 2, 3, 4, 5 ], + array: vec!( 1, 2, 3, 4, 5 ), }) }) } diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index b1b8351b040ad..90f641aca7e2a 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -67,7 +67,7 @@ //! } //! let output = matches.opt_str("o"); //! let input: &str = if !matches.free.is_empty() { -//! matches.free[0].clone() +//! (*matches.free.get(0)).clone() //! } else { //! print_usage(program, opts); //! return; @@ -87,8 +87,7 @@ use std::cmp::Eq; use std::result::{Err, Ok}; use std::result; -use std::option::{Some, None}; -use std::vec; +use std::vec_ng::Vec; /// Name of an option. Either a string or a single char. #[deriving(Clone, Eq)] @@ -126,7 +125,7 @@ pub struct Opt { /// How often it can occur occur: Occur, /// Which options it aliases - priv aliases: ~[Opt], + priv aliases: Vec , } /// One group of options, e.g., both -h and --help, along with @@ -159,12 +158,11 @@ enum Optval { #[deriving(Clone, Eq)] pub struct Matches { /// Options that matched - priv opts: ~[Opt], + priv opts: Vec , /// Values of the Options that matched - priv vals: ~[~[Optval]], + priv vals: Vec > , /// Free string fragments - free: ~[~str] -} + free: Vec<~str> } /// The type returned when the command line does not conform to the /// expected format. Call the `to_err_msg` method to retrieve the @@ -228,26 +226,26 @@ impl OptGroup { name: Long((long_name)), hasarg: hasarg, occur: occur, - aliases: ~[] + aliases: Vec::new() }, (1,0) => Opt { name: Short(short_name.char_at(0)), hasarg: hasarg, occur: occur, - aliases: ~[] + aliases: Vec::new() }, (1,_) => Opt { name: Long((long_name)), hasarg: hasarg, occur: occur, - aliases: ~[ + aliases: vec!( Opt { name: Short(short_name.char_at(0)), hasarg: hasarg, occur: occur, - aliases: ~[] + aliases: Vec::new() } - ] + ) }, (_,_) => fail!("something is wrong with the long-form opt") } @@ -255,9 +253,9 @@ impl OptGroup { } impl Matches { - fn opt_vals(&self, nm: &str) -> ~[Optval] { - match find_opt(self.opts, Name::from_str(nm)) { - Some(id) => self.vals[id].clone(), + fn opt_vals(&self, nm: &str) -> Vec { + match find_opt(self.opts.as_slice(), Name::from_str(nm)) { + Some(id) => (*self.vals.get(id)).clone(), None => fail!("No option '{}' defined", nm) } } @@ -267,7 +265,7 @@ impl Matches { if vals.is_empty() { None } else { - Some(vals[0].clone()) + Some((*vals.get(0)).clone()) } } @@ -284,8 +282,8 @@ impl Matches { /// Returns true if any of several options were matched. pub fn opts_present(&self, names: &[~str]) -> bool { for nm in names.iter() { - match find_opt(self.opts, Name::from_str(*nm)) { - Some(id) if !self.vals[id].is_empty() => return true, + match find_opt(self.opts.as_slice(), Name::from_str(*nm)) { + Some(id) if !self.vals.get(id).is_empty() => return true, _ => (), }; } @@ -307,8 +305,8 @@ impl Matches { /// option. /// /// Used when an option accepts multiple values. - pub fn opt_strs(&self, nm: &str) -> ~[~str] { - let mut acc: ~[~str] = ~[]; + pub fn opt_strs(&self, nm: &str) -> Vec<~str> { + let mut acc: Vec<~str> = Vec::new(); let r = self.opt_vals(nm); for v in r.iter() { match *v { @@ -325,8 +323,8 @@ impl Matches { if vals.is_empty() { return None::<~str>; } - match vals[0] { - Val(ref s) => Some((*s).clone()), + match vals.get(0) { + &Val(ref s) => Some((*s).clone()), _ => None } } @@ -340,8 +338,8 @@ impl Matches { pub fn opt_default(&self, nm: &str, def: &str) -> Option<~str> { let vals = self.opt_vals(nm); if vals.is_empty() { return None; } - match vals[0] { - Val(ref s) => Some((*s).clone()), + match vals.get(0) { + &Val(ref s) => Some((*s).clone()), _ => Some(def.to_owned()) } } @@ -506,10 +504,10 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result { let opts = optgrps.map(|x| x.long_to_short()); let n_opts = opts.len(); - fn f(_x: uint) -> ~[Optval] { return ~[]; } + fn f(_x: uint) -> Vec { return Vec::new(); } - let mut vals = vec::from_fn(n_opts, f); - let mut free: ~[~str] = ~[]; + let mut vals = Vec::from_fn(n_opts, f); + let mut free: Vec<~str> = Vec::new(); let l = args.len(); let mut i = 0; while i < l { @@ -526,18 +524,18 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result { let mut i_arg = None; if cur[1] == '-' as u8 { let tail = cur.slice(2, curlen); - let tail_eq: ~[&str] = tail.split('=').collect(); + let tail_eq: Vec<&str> = tail.split('=').collect(); if tail_eq.len() <= 1 { - names = ~[Long(tail.to_owned())]; + names = vec!(Long(tail.to_owned())); } else { names = - ~[Long(tail_eq[0].to_owned())]; - i_arg = Some(tail_eq[1].to_owned()); + vec!(Long((*tail_eq.get(0)).to_owned())); + i_arg = Some((*tail_eq.get(1)).to_owned()); } } else { let mut j = 1; let mut last_valid_opt_id = None; - names = ~[]; + names = Vec::new(); while j < curlen { let range = cur.char_range_at(j); let opt = Short(range.ch); @@ -584,22 +582,30 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result { if !i_arg.is_none() { return Err(UnexpectedArgument(nm.to_str())); } - vals[optid].push(Given); + vals.get_mut(optid).push(Given); } Maybe => { if !i_arg.is_none() { - vals[optid].push(Val((i_arg.clone()).unwrap())); + vals.get_mut(optid) + .push(Val((i_arg.clone()) + .unwrap())); } else if name_pos < names.len() || i + 1 == l || is_arg(args[i + 1]) { - vals[optid].push(Given); - } else { i += 1; vals[optid].push(Val(args[i].clone())); } + vals.get_mut(optid).push(Given); + } else { + i += 1; + vals.get_mut(optid).push(Val(args[i].clone())); + } } Yes => { if !i_arg.is_none() { - vals[optid].push(Val(i_arg.clone().unwrap())); + vals.get_mut(optid).push(Val(i_arg.clone().unwrap())); } else if i + 1 == l { return Err(ArgumentMissing(nm.to_str())); - } else { i += 1; vals[optid].push(Val(args[i].clone())); } + } else { + i += 1; + vals.get_mut(optid).push(Val(args[i].clone())); + } } } } @@ -608,7 +614,7 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result { } i = 0u; while i < n_opts { - let n = vals[i].len(); + let n = vals.get(i).len(); let occ = opts[i].occur; if occ == Req { if n == 0 { @@ -623,7 +629,7 @@ pub fn getopts(args: &[~str], optgrps: &[OptGroup]) -> Result { i += 1; } Ok(Matches { - opts: opts.to_owned(), + opts: Vec::from_slice(opts), vals: vals, free: free }) @@ -695,7 +701,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str { } // FIXME: #5516 should be graphemes not codepoints - let mut desc_rows = ~[]; + let mut desc_rows = Vec::new(); each_split_within(desc_normalized_whitespace, 54, |substr| { desc_rows.push(substr.to_owned()); true @@ -708,7 +714,7 @@ pub fn usage(brief: &str, opts: &[OptGroup]) -> ~str { row }); - format!("{}\n\nOptions:\n{}\n", brief, rows.collect::<~[~str]>().connect("\n")) + format!("{}\n\nOptions:\n{}\n", brief, rows.collect:: >().connect("\n")) } fn format_option(opt: &OptGroup) -> ~str { @@ -863,7 +869,7 @@ fn each_split_within<'a>(ss: &'a str, lim: uint, it: |&'a str| -> bool) #[test] fn test_split_within() { fn t(s: &str, i: uint, u: &[~str]) { - let mut v = ~[]; + let mut v = Vec::new(); each_split_within(s, i, |s| { v.push(s.to_owned()); true }); assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b)); } @@ -882,6 +888,7 @@ mod tests { use std::result::{Err, Ok}; use std::result; + use std::vec_ng::Vec; fn check_fail_type(f: Fail_, ft: FailType) { match f { @@ -896,9 +903,9 @@ mod tests { // Tests for reqopt #[test] fn test_reqopt() { - let long_args = ~[~"--test=20"]; - let opts = ~[reqopt("t", "test", "testing", "TEST")]; - let rs = getopts(long_args, opts); + let long_args = vec!(~"--test=20"); + let opts = vec!(reqopt("t", "test", "testing", "TEST")); + let rs = getopts(long_args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert!(m.opt_present("test")); @@ -908,8 +915,8 @@ mod tests { } _ => { fail!("test_reqopt failed (long arg)"); } } - let short_args = ~[~"-t", ~"20"]; - match getopts(short_args, opts) { + let short_args = vec!(~"-t", ~"20"); + match getopts(short_args.as_slice(), opts.as_slice()) { Ok(ref m) => { assert!((m.opt_present("test"))); assert_eq!(m.opt_str("test").unwrap(), ~"20"); @@ -922,9 +929,9 @@ mod tests { #[test] fn test_reqopt_missing() { - let args = ~[~"blah"]; - let opts = ~[reqopt("t", "test", "testing", "TEST")]; - let rs = getopts(args, opts); + let args = vec!(~"blah"); + let opts = vec!(reqopt("t", "test", "testing", "TEST")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Err(f) => check_fail_type(f, OptionMissing_), _ => fail!() @@ -933,15 +940,15 @@ mod tests { #[test] fn test_reqopt_no_arg() { - let long_args = ~[~"--test"]; - let opts = ~[reqopt("t", "test", "testing", "TEST")]; - let rs = getopts(long_args, opts); + let long_args = vec!(~"--test"); + let opts = vec!(reqopt("t", "test", "testing", "TEST")); + let rs = getopts(long_args.as_slice(), opts.as_slice()); match rs { Err(f) => check_fail_type(f, ArgumentMissing_), _ => fail!() } - let short_args = ~[~"-t"]; - match getopts(short_args, opts) { + let short_args = vec!(~"-t"); + match getopts(short_args.as_slice(), opts.as_slice()) { Err(f) => check_fail_type(f, ArgumentMissing_), _ => fail!() } @@ -949,9 +956,9 @@ mod tests { #[test] fn test_reqopt_multi() { - let args = ~[~"--test=20", ~"-t", ~"30"]; - let opts = ~[reqopt("t", "test", "testing", "TEST")]; - let rs = getopts(args, opts); + let args = vec!(~"--test=20", ~"-t", ~"30"); + let opts = vec!(reqopt("t", "test", "testing", "TEST")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Err(f) => check_fail_type(f, OptionDuplicated_), _ => fail!() @@ -961,9 +968,9 @@ mod tests { // Tests for optopt #[test] fn test_optopt() { - let long_args = ~[~"--test=20"]; - let opts = ~[optopt("t", "test", "testing", "TEST")]; - let rs = getopts(long_args, opts); + let long_args = vec!(~"--test=20"); + let opts = vec!(optopt("t", "test", "testing", "TEST")); + let rs = getopts(long_args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert!(m.opt_present("test")); @@ -973,8 +980,8 @@ mod tests { } _ => fail!() } - let short_args = ~[~"-t", ~"20"]; - match getopts(short_args, opts) { + let short_args = vec!(~"-t", ~"20"); + match getopts(short_args.as_slice(), opts.as_slice()) { Ok(ref m) => { assert!((m.opt_present("test"))); assert_eq!(m.opt_str("test").unwrap(), ~"20"); @@ -987,9 +994,9 @@ mod tests { #[test] fn test_optopt_missing() { - let args = ~[~"blah"]; - let opts = ~[optopt("t", "test", "testing", "TEST")]; - let rs = getopts(args, opts); + let args = vec!(~"blah"); + let opts = vec!(optopt("t", "test", "testing", "TEST")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert!(!m.opt_present("test")); @@ -1001,15 +1008,15 @@ mod tests { #[test] fn test_optopt_no_arg() { - let long_args = ~[~"--test"]; - let opts = ~[optopt("t", "test", "testing", "TEST")]; - let rs = getopts(long_args, opts); + let long_args = vec!(~"--test"); + let opts = vec!(optopt("t", "test", "testing", "TEST")); + let rs = getopts(long_args.as_slice(), opts.as_slice()); match rs { Err(f) => check_fail_type(f, ArgumentMissing_), _ => fail!() } - let short_args = ~[~"-t"]; - match getopts(short_args, opts) { + let short_args = vec!(~"-t"); + match getopts(short_args.as_slice(), opts.as_slice()) { Err(f) => check_fail_type(f, ArgumentMissing_), _ => fail!() } @@ -1017,9 +1024,9 @@ mod tests { #[test] fn test_optopt_multi() { - let args = ~[~"--test=20", ~"-t", ~"30"]; - let opts = ~[optopt("t", "test", "testing", "TEST")]; - let rs = getopts(args, opts); + let args = vec!(~"--test=20", ~"-t", ~"30"); + let opts = vec!(optopt("t", "test", "testing", "TEST")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Err(f) => check_fail_type(f, OptionDuplicated_), _ => fail!() @@ -1029,9 +1036,9 @@ mod tests { // Tests for optflag #[test] fn test_optflag() { - let long_args = ~[~"--test"]; - let opts = ~[optflag("t", "test", "testing")]; - let rs = getopts(long_args, opts); + let long_args = vec!(~"--test"); + let opts = vec!(optflag("t", "test", "testing")); + let rs = getopts(long_args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert!(m.opt_present("test")); @@ -1039,8 +1046,8 @@ mod tests { } _ => fail!() } - let short_args = ~[~"-t"]; - match getopts(short_args, opts) { + let short_args = vec!(~"-t"); + match getopts(short_args.as_slice(), opts.as_slice()) { Ok(ref m) => { assert!(m.opt_present("test")); assert!(m.opt_present("t")); @@ -1051,9 +1058,9 @@ mod tests { #[test] fn test_optflag_missing() { - let args = ~[~"blah"]; - let opts = ~[optflag("t", "test", "testing")]; - let rs = getopts(args, opts); + let args = vec!(~"blah"); + let opts = vec!(optflag("t", "test", "testing")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert!(!m.opt_present("test")); @@ -1065,9 +1072,9 @@ mod tests { #[test] fn test_optflag_long_arg() { - let args = ~[~"--test=20"]; - let opts = ~[optflag("t", "test", "testing")]; - let rs = getopts(args, opts); + let args = vec!(~"--test=20"); + let opts = vec!(optflag("t", "test", "testing")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Err(f) => { error!("{:?}", f.clone().to_err_msg()); @@ -1079,9 +1086,9 @@ mod tests { #[test] fn test_optflag_multi() { - let args = ~[~"--test", ~"-t"]; - let opts = ~[optflag("t", "test", "testing")]; - let rs = getopts(args, opts); + let args = vec!(~"--test", ~"-t"); + let opts = vec!(optflag("t", "test", "testing")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Err(f) => check_fail_type(f, OptionDuplicated_), _ => fail!() @@ -1090,14 +1097,14 @@ mod tests { #[test] fn test_optflag_short_arg() { - let args = ~[~"-t", ~"20"]; - let opts = ~[optflag("t", "test", "testing")]; - let rs = getopts(args, opts); + let args = vec!(~"-t", ~"20"); + let opts = vec!(optflag("t", "test", "testing")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { // The next variable after the flag is just a free argument - assert!(m.free[0] == ~"20"); + assert!(*m.free.get(0) == ~"20"); } _ => fail!() } @@ -1106,9 +1113,9 @@ mod tests { // Tests for optflagmulti #[test] fn test_optflagmulti_short1() { - let args = ~[~"-v"]; - let opts = ~[optflagmulti("v", "verbose", "verbosity")]; - let rs = getopts(args, opts); + let args = vec!(~"-v"); + let opts = vec!(optflagmulti("v", "verbose", "verbosity")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert_eq!(m.opt_count("v"), 1); @@ -1119,9 +1126,9 @@ mod tests { #[test] fn test_optflagmulti_short2a() { - let args = ~[~"-v", ~"-v"]; - let opts = ~[optflagmulti("v", "verbose", "verbosity")]; - let rs = getopts(args, opts); + let args = vec!(~"-v", ~"-v"); + let opts = vec!(optflagmulti("v", "verbose", "verbosity")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert_eq!(m.opt_count("v"), 2); @@ -1132,9 +1139,9 @@ mod tests { #[test] fn test_optflagmulti_short2b() { - let args = ~[~"-vv"]; - let opts = ~[optflagmulti("v", "verbose", "verbosity")]; - let rs = getopts(args, opts); + let args = vec!(~"-vv"); + let opts = vec!(optflagmulti("v", "verbose", "verbosity")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert_eq!(m.opt_count("v"), 2); @@ -1145,9 +1152,9 @@ mod tests { #[test] fn test_optflagmulti_long1() { - let args = ~[~"--verbose"]; - let opts = ~[optflagmulti("v", "verbose", "verbosity")]; - let rs = getopts(args, opts); + let args = vec!(~"--verbose"); + let opts = vec!(optflagmulti("v", "verbose", "verbosity")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert_eq!(m.opt_count("verbose"), 1); @@ -1158,9 +1165,9 @@ mod tests { #[test] fn test_optflagmulti_long2() { - let args = ~[~"--verbose", ~"--verbose"]; - let opts = ~[optflagmulti("v", "verbose", "verbosity")]; - let rs = getopts(args, opts); + let args = vec!(~"--verbose", ~"--verbose"); + let opts = vec!(optflagmulti("v", "verbose", "verbosity")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert_eq!(m.opt_count("verbose"), 2); @@ -1171,9 +1178,9 @@ mod tests { #[test] fn test_optflagmulti_mix() { - let args = ~[~"--verbose", ~"-v", ~"-vv", ~"verbose"]; - let opts = ~[optflagmulti("v", "verbose", "verbosity")]; - let rs = getopts(args, opts); + let args = vec!(~"--verbose", ~"-v", ~"-vv", ~"verbose"); + let opts = vec!(optflagmulti("v", "verbose", "verbosity")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert_eq!(m.opt_count("verbose"), 4); @@ -1186,9 +1193,9 @@ mod tests { // Tests for optmulti #[test] fn test_optmulti() { - let long_args = ~[~"--test=20"]; - let opts = ~[optmulti("t", "test", "testing", "TEST")]; - let rs = getopts(long_args, opts); + let long_args = vec!(~"--test=20"); + let opts = vec!(optmulti("t", "test", "testing", "TEST")); + let rs = getopts(long_args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert!((m.opt_present("test"))); @@ -1198,8 +1205,8 @@ mod tests { } _ => fail!() } - let short_args = ~[~"-t", ~"20"]; - match getopts(short_args, opts) { + let short_args = vec!(~"-t", ~"20"); + match getopts(short_args.as_slice(), opts.as_slice()) { Ok(ref m) => { assert!((m.opt_present("test"))); assert_eq!(m.opt_str("test").unwrap(), ~"20"); @@ -1212,9 +1219,9 @@ mod tests { #[test] fn test_optmulti_missing() { - let args = ~[~"blah"]; - let opts = ~[optmulti("t", "test", "testing", "TEST")]; - let rs = getopts(args, opts); + let args = vec!(~"blah"); + let opts = vec!(optmulti("t", "test", "testing", "TEST")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert!(!m.opt_present("test")); @@ -1226,15 +1233,15 @@ mod tests { #[test] fn test_optmulti_no_arg() { - let long_args = ~[~"--test"]; - let opts = ~[optmulti("t", "test", "testing", "TEST")]; - let rs = getopts(long_args, opts); + let long_args = vec!(~"--test"); + let opts = vec!(optmulti("t", "test", "testing", "TEST")); + let rs = getopts(long_args.as_slice(), opts.as_slice()); match rs { Err(f) => check_fail_type(f, ArgumentMissing_), _ => fail!() } - let short_args = ~[~"-t"]; - match getopts(short_args, opts) { + let short_args = vec!(~"-t"); + match getopts(short_args.as_slice(), opts.as_slice()) { Err(f) => check_fail_type(f, ArgumentMissing_), _ => fail!() } @@ -1242,9 +1249,9 @@ mod tests { #[test] fn test_optmulti_multi() { - let args = ~[~"--test=20", ~"-t", ~"30"]; - let opts = ~[optmulti("t", "test", "testing", "TEST")]; - let rs = getopts(args, opts); + let args = vec!(~"--test=20", ~"-t", ~"30"); + let opts = vec!(optmulti("t", "test", "testing", "TEST")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { assert!(m.opt_present("test")); @@ -1252,8 +1259,8 @@ mod tests { assert!(m.opt_present("t")); assert_eq!(m.opt_str("t").unwrap(), ~"20"); let pair = m.opt_strs("test"); - assert!(pair[0] == ~"20"); - assert!(pair[1] == ~"30"); + assert!(*pair.get(0) == ~"20"); + assert!(*pair.get(1) == ~"30"); } _ => fail!() } @@ -1261,15 +1268,15 @@ mod tests { #[test] fn test_unrecognized_option() { - let long_args = ~[~"--untest"]; - let opts = ~[optmulti("t", "test", "testing", "TEST")]; - let rs = getopts(long_args, opts); + let long_args = vec!(~"--untest"); + let opts = vec!(optmulti("t", "test", "testing", "TEST")); + let rs = getopts(long_args.as_slice(), opts.as_slice()); match rs { Err(f) => check_fail_type(f, UnrecognizedOption_), _ => fail!() } - let short_args = ~[~"-u"]; - match getopts(short_args, opts) { + let short_args = vec!(~"-u"); + match getopts(short_args.as_slice(), opts.as_slice()) { Err(f) => check_fail_type(f, UnrecognizedOption_), _ => fail!() } @@ -1278,33 +1285,33 @@ mod tests { #[test] fn test_combined() { let args = - ~[~"prog", ~"free1", ~"-s", ~"20", ~"free2", + vec!(~"prog", ~"free1", ~"-s", ~"20", ~"free2", ~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40", - ~"-m", ~"50", ~"-n", ~"-A B", ~"-n", ~"-60 70"]; + ~"-m", ~"50", ~"-n", ~"-A B", ~"-n", ~"-60 70"); let opts = - ~[optopt("s", "something", "something", "SOMETHING"), + vec!(optopt("s", "something", "something", "SOMETHING"), optflag("", "flag", "a flag"), reqopt("", "long", "hi", "LONG"), optflag("f", "", "another flag"), optmulti("m", "", "mmmmmm", "YUM"), optmulti("n", "", "nothing", "NOTHING"), - optopt("", "notpresent", "nothing to see here", "NOPE")]; - let rs = getopts(args, opts); + optopt("", "notpresent", "nothing to see here", "NOPE")); + let rs = getopts(args.as_slice(), opts.as_slice()); match rs { Ok(ref m) => { - assert!(m.free[0] == ~"prog"); - assert!(m.free[1] == ~"free1"); + assert!(*m.free.get(0) == ~"prog"); + assert!(*m.free.get(1) == ~"free1"); assert_eq!(m.opt_str("s").unwrap(), ~"20"); - assert!(m.free[2] == ~"free2"); + assert!(*m.free.get(2) == ~"free2"); assert!((m.opt_present("flag"))); assert_eq!(m.opt_str("long").unwrap(), ~"30"); assert!((m.opt_present("f"))); let pair = m.opt_strs("m"); - assert!(pair[0] == ~"40"); - assert!(pair[1] == ~"50"); + assert!(*pair.get(0) == ~"40"); + assert!(*pair.get(1) == ~"50"); let pair = m.opt_strs("n"); - assert!(pair[0] == ~"-A B"); - assert!(pair[1] == ~"-60 70"); + assert!(*pair.get(0) == ~"-A B"); + assert!(*pair.get(1) == ~"-60 70"); assert!((!m.opt_present("notpresent"))); } _ => fail!() @@ -1313,12 +1320,13 @@ mod tests { #[test] fn test_multi() { - let opts = ~[optopt("e", "", "encrypt", "ENCRYPT"), + let opts = vec!(optopt("e", "", "encrypt", "ENCRYPT"), optopt("", "encrypt", "encrypt", "ENCRYPT"), - optopt("f", "", "flag", "FLAG")]; + optopt("f", "", "flag", "FLAG")); - let args_single = ~[~"-e", ~"foo"]; - let matches_single = &match getopts(args_single, opts) { + let args_single = vec!(~"-e", ~"foo"); + let matches_single = &match getopts(args_single.as_slice(), + opts.as_slice()) { result::Ok(m) => m, result::Err(_) => fail!() }; @@ -1333,8 +1341,9 @@ mod tests { assert_eq!(matches_single.opts_str([~"e", ~"encrypt"]).unwrap(), ~"foo"); assert_eq!(matches_single.opts_str([~"encrypt", ~"e"]).unwrap(), ~"foo"); - let args_both = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; - let matches_both = &match getopts(args_both, opts) { + let args_both = vec!(~"-e", ~"foo", ~"--encrypt", ~"foo"); + let matches_both = &match getopts(args_both.as_slice(), + opts.as_slice()) { result::Ok(m) => m, result::Err(_) => fail!() }; @@ -1354,10 +1363,10 @@ mod tests { #[test] fn test_nospace() { - let args = ~[~"-Lfoo", ~"-M."]; - let opts = ~[optmulti("L", "", "library directory", "LIB"), - optmulti("M", "", "something", "MMMM")]; - let matches = &match getopts(args, opts) { + let args = vec!(~"-Lfoo", ~"-M."); + let opts = vec!(optmulti("L", "", "library directory", "LIB"), + optmulti("M", "", "something", "MMMM")); + let matches = &match getopts(args.as_slice(), opts.as_slice()) { result::Ok(m) => m, result::Err(_) => fail!() }; @@ -1370,14 +1379,16 @@ mod tests { #[test] fn test_long_to_short() { - let mut short = Opt { name: Long(~"banana"), - hasarg: Yes, - occur: Req, - aliases: ~[] }; - short.aliases = ~[Opt { name: Short('b'), + let mut short = Opt { + name: Long(~"banana"), + hasarg: Yes, + occur: Req, + aliases: Vec::new(), + }; + short.aliases = vec!(Opt { name: Short('b'), hasarg: Yes, occur: Req, - aliases: ~[] }]; + aliases: Vec::new() }); let verbose = reqopt("b", "banana", "some bananas", "VAL"); assert!(verbose.long_to_short() == short); @@ -1385,27 +1396,25 @@ mod tests { #[test] fn test_aliases_long_and_short() { - let opts = ~[ - optflagmulti("a", "apple", "Desc"), - ]; + let opts = vec!( + optflagmulti("a", "apple", "Desc")); - let args = ~[~"-a", ~"--apple", ~"-a"]; + let args = vec!(~"-a", ~"--apple", ~"-a"); - let matches = getopts(args, opts).unwrap(); + let matches = getopts(args.as_slice(), opts.as_slice()).unwrap(); assert_eq!(3, matches.opt_count("a")); assert_eq!(3, matches.opt_count("apple")); } #[test] fn test_usage() { - let optgroups = ~[ + let optgroups = vec!( reqopt("b", "banana", "Desc", "VAL"), optopt("a", "012345678901234567890123456789", "Desc", "VAL"), optflag("k", "kiwi", "Desc"), optflagopt("p", "", "Desc", "VAL"), - optmulti("l", "", "Desc", "VAL"), - ]; + optmulti("l", "", "Desc", "VAL")); let expected = ~"Usage: fruits @@ -1419,7 +1428,7 @@ Options: -l VAL Desc "; - let generated_usage = usage("Usage: fruits", optgroups); + let generated_usage = usage("Usage: fruits", optgroups.as_slice()); debug!("expected: <<{}>>", expected); debug!("generated: <<{}>>", generated_usage); @@ -1431,12 +1440,11 @@ Options: // indentation should be 24 spaces // lines wrap after 78: or rather descriptions wrap after 54 - let optgroups = ~[ + let optgroups = vec!( optflag("k", "kiwi", "This is a long description which won't be wrapped..+.."), // 54 optflag("a", "apple", - "This is a long description which _will_ be wrapped..+.."), // 55 - ]; + "This is a long description which _will_ be wrapped..+..")); let expected = ~"Usage: fruits @@ -1447,7 +1455,7 @@ Options: wrapped..+.. "; - let usage = usage("Usage: fruits", optgroups); + let usage = usage("Usage: fruits", optgroups.as_slice()); debug!("expected: <<{}>>", expected); debug!("generated: <<{}>>", usage); @@ -1456,13 +1464,12 @@ Options: #[test] fn test_usage_description_multibyte_handling() { - let optgroups = ~[ + let optgroups = vec!( optflag("k", "k\u2013w\u2013", "The word kiwi is normally spelled with two i's"), optflag("a", "apple", "This \u201Cdescription\u201D has some characters that could \ -confuse the line wrapping; an apple costs 0.51€ in some parts of Europe."), - ]; +confuse the line wrapping; an apple costs 0.51€ in some parts of Europe.")); let expected = ~"Usage: fruits @@ -1474,7 +1481,7 @@ Options: some parts of Europe. "; - let usage = usage("Usage: fruits", optgroups); + let usage = usage("Usage: fruits", optgroups.as_slice()); debug!("expected: <<{}>>", expected); debug!("generated: <<{}>>", usage); @@ -1483,17 +1490,16 @@ Options: #[test] fn test_short_usage() { - let optgroups = ~[ + let optgroups = vec!( reqopt("b", "banana", "Desc", "VAL"), optopt("a", "012345678901234567890123456789", "Desc", "VAL"), optflag("k", "kiwi", "Desc"), optflagopt("p", "", "Desc", "VAL"), - optmulti("l", "", "Desc", "VAL"), - ]; + optmulti("l", "", "Desc", "VAL")); let expected = ~"Usage: fruits -b VAL [-a VAL] [-k] [-p [VAL]] [-l VAL].."; - let generated_usage = short_usage("fruits", optgroups); + let generated_usage = short_usage("fruits", optgroups.as_slice()); debug!("expected: <<{}>>", expected); debug!("generated: <<{}>>", generated_usage); diff --git a/src/libglob/lib.rs b/src/libglob/lib.rs index 819e0949e3be4..4ccfdc8b40c87 100644 --- a/src/libglob/lib.rs +++ b/src/libglob/lib.rs @@ -29,6 +29,7 @@ #[license = "MIT/ASL2"]; use std::cell::Cell; +use std::vec_ng::Vec; use std::{cmp, os, path}; use std::io::fs; use std::path::is_sep; @@ -39,10 +40,9 @@ use std::path::is_sep; */ pub struct Paths { priv root: Path, - priv dir_patterns: ~[Pattern], + priv dir_patterns: Vec , priv options: MatchOptions, - priv todo: ~[(Path,uint)] -} + priv todo: Vec<(Path,uint)> } /// /// Return an iterator that produces all the Paths that match the given pattern, @@ -100,16 +100,23 @@ pub fn glob_with(pattern: &str, options: MatchOptions) -> Paths { if check_windows_verbatim(pat_root.get_ref()) { // FIXME: How do we want to handle verbatim paths? I'm inclined to return nothing, // since we can't very well find all UNC shares with a 1-letter server name. - return Paths { root: root, dir_patterns: ~[], options: options, todo: ~[] }; + return Paths { + root: root, + dir_patterns: Vec::new(), + options: options, + todo: Vec::new(), + }; } root.push(pat_root.get_ref()); } let root_len = pat_root.map_or(0u, |p| p.as_vec().len()); let dir_patterns = pattern.slice_from(cmp::min(root_len, pattern.len())) - .split_terminator(is_sep).map(|s| Pattern::new(s)).to_owned_vec(); + .split_terminator(is_sep) + .map(|s| Pattern::new(s)) + .collect(); - let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).to_owned_vec(); + let todo = list_dir_sorted(&root).move_iter().map(|x|(x,0u)).collect(); Paths { root: root, @@ -128,7 +135,7 @@ impl Iterator for Paths { } let (path,idx) = self.todo.pop().unwrap(); - let ref pattern = self.dir_patterns[idx]; + let ref pattern = *self.dir_patterns.get(idx); if pattern.matches_with(match path.filename_str() { // this ugly match needs to go here to avoid a borrowck error @@ -152,13 +159,13 @@ impl Iterator for Paths { } -fn list_dir_sorted(path: &Path) -> ~[Path] { +fn list_dir_sorted(path: &Path) -> Vec { match fs::readdir(path) { Ok(mut children) => { children.sort_by(|p1, p2| p2.filename().cmp(&p1.filename())); - children + children.move_iter().collect() } - Err(..) => ~[] + Err(..) => Vec::new() } } @@ -167,16 +174,15 @@ fn list_dir_sorted(path: &Path) -> ~[Path] { */ #[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash, Default)] pub struct Pattern { - priv tokens: ~[PatternToken] -} + priv tokens: Vec } #[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash)] enum PatternToken { Char(char), AnyChar, AnySequence, - AnyWithin(~[CharSpecifier]), - AnyExcept(~[CharSpecifier]) + AnyWithin(Vec ), + AnyExcept(Vec ) } #[deriving(Clone, Eq, TotalEq, Ord, TotalOrd, Hash)] @@ -216,7 +222,7 @@ impl Pattern { pub fn new(pattern: &str) -> Pattern { let chars = pattern.chars().to_owned_vec(); - let mut tokens = ~[]; + let mut tokens = Vec::new(); let mut i = 0; while i < chars.len() { @@ -388,10 +394,16 @@ impl Pattern { !require_literal(c) } AnyWithin(ref specifiers) => { - !require_literal(c) && in_char_specifiers(*specifiers, c, options) + !require_literal(c) && + in_char_specifiers(specifiers.as_slice(), + c, + options) } AnyExcept(ref specifiers) => { - !require_literal(c) && !in_char_specifiers(*specifiers, c, options) + !require_literal(c) && + !in_char_specifiers(specifiers.as_slice(), + c, + options) } Char(c2) => { chars_eq(c, c2, options.case_sensitive) @@ -418,8 +430,8 @@ impl Pattern { } -fn parse_char_specifiers(s: &[char]) -> ~[CharSpecifier] { - let mut cs = ~[]; +fn parse_char_specifiers(s: &[char]) -> Vec { + let mut cs = Vec::new(); let mut i = 0; while i < s.len() { if i + 3 <= s.len() && s[i + 1] == '-' { diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index ea8720751d8b0..b976ef3164b23 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -27,7 +27,8 @@ use std::num::{Zero, One, ToStrRadix, FromStrRadix}; use std::rand::Rng; use std::str; use std::uint; -use std::vec; +use std::vec_ng::Vec; +use std::vec_ng; use std::{i64, u64}; /** @@ -86,8 +87,7 @@ A `BigUint`-typed value `BigUint { data: ~[a, b, c] }` represents a number */ #[deriving(Clone)] pub struct BigUint { - priv data: ~[BigDigit] -} + priv data: Vec } impl Eq for BigUint { #[inline] @@ -141,10 +141,10 @@ impl Num for BigUint {} impl BitAnd for BigUint { fn bitand(&self, other: &BigUint) -> BigUint { let new_len = cmp::min(self.data.len(), other.data.len()); - let anded = vec::from_fn(new_len, |i| { + let anded = Vec::from_fn(new_len, |i| { // i will never be less than the size of either data vector - let ai = self.data[i]; - let bi = other.data[i]; + let ai = *self.data.get(i); + let bi = *other.data.get(i); ai & bi }); return BigUint::new(anded); @@ -154,9 +154,9 @@ impl BitAnd for BigUint { impl BitOr for BigUint { fn bitor(&self, other: &BigUint) -> BigUint { let new_len = cmp::max(self.data.len(), other.data.len()); - let ored = vec::from_fn(new_len, |i| { - let ai = if i < self.data.len() { self.data[i] } else { 0 }; - let bi = if i < other.data.len() { other.data[i] } else { 0 }; + let ored = Vec::from_fn(new_len, |i| { + let ai = if i < self.data.len() { *self.data.get(i) } else { 0 }; + let bi = if i < other.data.len() { *other.data.get(i)} else { 0 }; ai | bi }); return BigUint::new(ored); @@ -166,9 +166,17 @@ impl BitOr for BigUint { impl BitXor for BigUint { fn bitxor(&self, other: &BigUint) -> BigUint { let new_len = cmp::max(self.data.len(), other.data.len()); - let xored = vec::from_fn(new_len, |i| { - let ai = if i < self.data.len() { self.data[i] } else { 0 }; - let bi = if i < other.data.len() { other.data[i] } else { 0 }; + let xored = Vec::from_fn(new_len, |i| { + let ai = if i < self.data.len() { + *self.data.get(i) + } else { + 0 + }; + let bi = if i < other.data.len() { + *other.data.get(i) + } else { + 0 + }; ai ^ bi }); return BigUint::new(xored); @@ -195,7 +203,7 @@ impl Shr for BigUint { impl Zero for BigUint { #[inline] - fn zero() -> BigUint { BigUint::new(~[]) } + fn zero() -> BigUint { BigUint::new(Vec::new()) } #[inline] fn is_zero(&self) -> bool { self.data.is_empty() } @@ -203,7 +211,7 @@ impl Zero for BigUint { impl One for BigUint { #[inline] - fn one() -> BigUint { BigUint::new(~[1]) } + fn one() -> BigUint { BigUint::new(vec!(1)) } } impl Unsigned for BigUint {} @@ -213,9 +221,17 @@ impl Add for BigUint { let new_len = cmp::max(self.data.len(), other.data.len()); let mut carry = 0; - let mut sum = vec::from_fn(new_len, |i| { - let ai = if i < self.data.len() { self.data[i] } else { 0 }; - let bi = if i < other.data.len() { other.data[i] } else { 0 }; + let mut sum = Vec::from_fn(new_len, |i| { + let ai = if i < self.data.len() { + *self.data.get(i) + } else { + 0 + }; + let bi = if i < other.data.len() { + *other.data.get(i) + } else { + 0 + }; let (hi, lo) = BigDigit::from_uint( (ai as uint) + (bi as uint) + (carry as uint) ); @@ -232,9 +248,17 @@ impl Sub for BigUint { let new_len = cmp::max(self.data.len(), other.data.len()); let mut borrow = 0; - let diff = vec::from_fn(new_len, |i| { - let ai = if i < self.data.len() { self.data[i] } else { 0 }; - let bi = if i < other.data.len() { other.data[i] } else { 0 }; + let diff = Vec::from_fn(new_len, |i| { + let ai = if i < self.data.len() { + *self.data.get(i) + } else { + 0 + }; + let bi = if i < other.data.len() { + *other.data.get(i) + } else { + 0 + }; let (hi, lo) = BigDigit::from_uint( (BigDigit::base) + (ai as uint) - (bi as uint) - (borrow as uint) @@ -257,8 +281,8 @@ impl Mul for BigUint { if self.is_zero() || other.is_zero() { return Zero::zero(); } let (s_len, o_len) = (self.data.len(), other.data.len()); - if s_len == 1 { return mul_digit(other, self.data[0]); } - if o_len == 1 { return mul_digit(self, other.data[0]); } + if s_len == 1 { return mul_digit(other, *self.data.get(0)); } + if o_len == 1 { return mul_digit(self, *other.data.get(0)); } // Using Karatsuba multiplication // (a1 * base + a0) * (b1 * base + b0) @@ -295,7 +319,7 @@ impl Mul for BigUint { ); carry = hi; lo - }).collect::<~[BigDigit]>(); + }).collect:: >(); if carry != 0 { prod.push(carry); } return BigUint::new(prod); } @@ -453,14 +477,14 @@ impl Integer for BigUint { let an = a.data.slice(a.data.len() - n, a.data.len()); let bn = *b.data.last().unwrap(); - let mut d = ~[]; + let mut d = Vec::new(); let mut carry = 0; for elt in an.rev_iter() { let ai = BigDigit::to_uint(carry, *elt); let di = ai / (bn as uint); assert!(di < BigDigit::base); carry = (ai % (bn as uint)) as BigDigit; - d = ~[di as BigDigit] + d; + d = vec_ng::append(vec!(di as BigDigit), d.as_slice()); } let shift = (a.data.len() - an.len()) - (b.data.len() - 1); @@ -468,7 +492,7 @@ impl Integer for BigUint { return (BigUint::new(d), One::one(), (*b).clone()); } let one: BigUint = One::one(); - return (BigUint::from_slice(d).shl_unit(shift), + return (BigUint::from_slice(d.as_slice()).shl_unit(shift), one.shl_unit(shift), b.shl_unit(shift)); } @@ -509,7 +533,7 @@ impl Integer for BigUint { if self.data.is_empty() { true } else { - self.data[0].is_even() + self.data.get(0).is_even() } } @@ -538,18 +562,20 @@ impl ToPrimitive for BigUint { 0 => Some(0), 1 => Some(self.data[0] as u64), 2 => { - Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64) + Some(BigDigit::to_uint(*self.data.get(1), *self.data.get(0)) + as u64) } 3 => { - let n_lo = BigDigit::to_uint(self.data[1], self.data[0]) as - u64; - let n_hi = self.data[2] as u64; + let n_lo = BigDigit::to_uint(*self.data.get(1), + *self.data.get(0)) as u64; + let n_hi = *self.data.get(2) as u64; Some((n_hi << 32) + n_lo) } 4 => { - let n_lo = BigDigit::to_uint(self.data[1], self.data[0]) - as u64; - let n_hi = BigDigit::to_uint(self.data[3], self.data[2]) + let n_lo = BigDigit::to_uint(*self.data.get(1), + *self.data.get(0)) as u64; + let n_hi = BigDigit::to_uint(*self.data.get(3), + *self.data.get(2)) as u64; Some((n_hi << 32) + n_lo) } @@ -562,8 +588,9 @@ impl ToPrimitive for BigUint { fn to_u64(&self) -> Option { match self.data.len() { 0 => Some(0), - 1 => Some(self.data[0] as u64), - 2 => Some(BigDigit::to_uint(self.data[1], self.data[0]) as u64), + 1 => Some(*self.data.get(0) as u64), + 2 => Some(BigDigit::to_uint(*self.data.get(1), *self.data.get(0)) + as u64), _ => None } } @@ -589,10 +616,10 @@ impl FromPrimitive for BigUint { let n = match (BigDigit::from_uint(n_hi), BigDigit::from_uint(n_lo)) { ((0, 0), (0, 0)) => Zero::zero(), - ((0, 0), (0, n0)) => BigUint::new(~[n0]), - ((0, 0), (n1, n0)) => BigUint::new(~[n0, n1]), - ((0, n2), (n1, n0)) => BigUint::new(~[n0, n1, n2]), - ((n3, n2), (n1, n0)) => BigUint::new(~[n0, n1, n2, n3]), + ((0, 0), (0, n0)) => BigUint::new(vec!(n0)), + ((0, 0), (n1, n0)) => BigUint::new(vec!(n0, n1)), + ((0, n2), (n1, n0)) => BigUint::new(vec!(n0, n1, n2)), + ((n3, n2), (n1, n0)) => BigUint::new(vec!(n0, n1, n2, n3)), }; Some(n) } @@ -602,8 +629,8 @@ impl FromPrimitive for BigUint { fn from_u64(n: u64) -> Option { let n = match BigDigit::from_uint(n as uint) { (0, 0) => Zero::zero(), - (0, n0) => BigUint::new(~[n0]), - (n1, n0) => BigUint::new(~[n0, n1]) + (0, n0) => BigUint::new(vec!(n0)), + (n1, n0) => BigUint::new(vec!(n0, n1)) }; Some(n) } @@ -662,13 +689,15 @@ impl ToStrRadix for BigUint { assert!(1 < radix && radix <= 16); let (base, max_len) = get_radix_base(radix); if base == BigDigit::base { - return fill_concat(self.data, radix, max_len) + return fill_concat(self.data.as_slice(), radix, max_len) } - return fill_concat(convert_base((*self).clone(), base), radix, max_len); + return fill_concat(convert_base((*self).clone(), base).as_slice(), + radix, + max_len); - fn convert_base(n: BigUint, base: uint) -> ~[BigDigit] { + fn convert_base(n: BigUint, base: uint) -> Vec { let divider = FromPrimitive::from_uint(base).unwrap(); - let mut result = ~[]; + let mut result = Vec::new(); let mut m = n; while m >= divider { let (d, m0) = m.div_mod_floor(÷r); @@ -706,7 +735,7 @@ impl FromStrRadix for BigUint { impl BigUint { /// Creates and initializes a `BigUint`. #[inline] - pub fn new(v: ~[BigDigit]) -> BigUint { + pub fn new(v: Vec ) -> BigUint { // omit trailing zeros let new_len = v.iter().rposition(|n| *n != 0).map_or(0, |p| p + 1); @@ -719,7 +748,7 @@ impl BigUint { /// Creates and initializes a `BigUint`. #[inline] pub fn from_slice(slice: &[BigDigit]) -> BigUint { - return BigUint::new(slice.to_owned()); + return BigUint::new(Vec::from_slice(slice)); } /// Creates and initializes a `BigUint`. @@ -764,8 +793,9 @@ impl BigUint { fn shl_unit(&self, n_unit: uint) -> BigUint { if n_unit == 0 || self.is_zero() { return (*self).clone(); } - return BigUint::new(vec::from_elem(n_unit, ZERO_BIG_DIGIT) - + self.data); + return BigUint::new(vec_ng::append(Vec::from_elem(n_unit, + ZERO_BIG_DIGIT), + self.data.as_slice())); } #[inline] @@ -779,7 +809,7 @@ impl BigUint { ); carry = hi; lo - }).collect::<~[BigDigit]>(); + }).collect:: >(); if carry != 0 { shifted.push(carry); } return BigUint::new(shifted); } @@ -798,7 +828,7 @@ impl BigUint { if n_bits == 0 || self.data.is_empty() { return (*self).clone(); } let mut borrow = 0; - let mut shifted_rev = vec::with_capacity(self.data.len()); + let mut shifted_rev = Vec::with_capacity(self.data.len()); for elem in self.data.rev_iter() { shifted_rev.push((*elem >> n_bits) | borrow); borrow = *elem << (BigDigit::bits - n_bits); @@ -1351,7 +1381,7 @@ pub trait RandBigInt { impl RandBigInt for R { fn gen_biguint(&mut self, bit_size: uint) -> BigUint { let (digits, rem) = bit_size.div_rem(&BigDigit::bits); - let mut data = vec::with_capacity(digits+1); + let mut data = Vec::with_capacity(digits+1); for _ in range(0, digits) { data.push(self.gen()); } @@ -1414,7 +1444,7 @@ impl RandBigInt for R { impl BigInt { /// Creates and initializes a BigInt. #[inline] - pub fn new(sign: Sign, v: ~[BigDigit]) -> BigInt { + pub fn new(sign: Sign, v: Vec ) -> BigInt { BigInt::from_biguint(sign, BigUint::new(v)) } @@ -1473,12 +1503,12 @@ mod biguint_tests { use std::rand::{task_rng}; use std::str; use std::u64; - use std::vec; + use std::vec_ng::Vec; #[test] fn test_from_slice() { fn check(slice: &[BigDigit], data: &[BigDigit]) { - assert!(data == BigUint::from_slice(slice).data); + assert!(data == BigUint::from_slice(slice).data.as_slice()); } check([1], [1]); check([0, 0, 0], []); @@ -1490,8 +1520,8 @@ mod biguint_tests { #[test] fn test_cmp() { - let data: ~[BigUint] = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ] - .map(|v| BigUint::from_slice(*v)); + let data: Vec = [ &[], &[1], &[2], &[-1], &[0, 1], &[2, 1], &[1, 1, 1] ] + .iter().map(|v| BigUint::from_slice(*v)).collect(); for (i, ni) in data.iter().enumerate() { for (j0, nj) in data.slice(i, data.len()).iter().enumerate() { let j = j0 + i; @@ -1527,44 +1557,44 @@ mod biguint_tests { #[test] fn test_bitand() { - fn check(left: ~[BigDigit], - right: ~[BigDigit], - expected: ~[BigDigit]) { + fn check(left: Vec , + right: Vec , + expected: Vec ) { assert_eq!(BigUint::new(left) & BigUint::new(right), BigUint::new(expected)); } - check(~[], ~[], ~[]); - check(~[268, 482, 17], - ~[964, 54], - ~[260, 34]); + check(Vec::new(), Vec::new(), Vec::new()); + check(vec!(268, 482, 17), + vec!(964, 54), + vec!(260, 34)); } #[test] fn test_bitor() { - fn check(left: ~[BigDigit], - right: ~[BigDigit], - expected: ~[BigDigit]) { + fn check(left: Vec , + right: Vec , + expected: Vec ) { assert_eq!(BigUint::new(left) | BigUint::new(right), BigUint::new(expected)); } - check(~[], ~[], ~[]); - check(~[268, 482, 17], - ~[964, 54], - ~[972, 502, 17]); + check(Vec::new(), Vec::new(), Vec::new()); + check(vec!(268, 482, 17), + vec!(964, 54), + vec!(972, 502, 17)); } #[test] fn test_bitxor() { - fn check(left: ~[BigDigit], - right: ~[BigDigit], - expected: ~[BigDigit]) { + fn check(left: Vec , + right: Vec , + expected: Vec ) { assert_eq!(BigUint::new(left) ^ BigUint::new(right), BigUint::new(expected)); } - check(~[], ~[], ~[]); - check(~[268, 482, 17], - ~[964, 54], - ~[712, 468, 17]); + check(Vec::new(), Vec::new(), Vec::new()); + check(vec!(268, 482, 17), + vec!(964, 54), + vec!(712, 468, 17)); } #[test] @@ -1657,20 +1687,20 @@ mod biguint_tests { check(One::one(), 1); check(i64::MAX.to_biguint().unwrap(), i64::MAX); - check(BigUint::new(~[ ]), 0); - check(BigUint::new(~[ 1 ]), (1 << (0*BigDigit::bits))); - check(BigUint::new(~[-1 ]), (1 << (1*BigDigit::bits)) - 1); - check(BigUint::new(~[ 0, 1 ]), (1 << (1*BigDigit::bits))); - check(BigUint::new(~[-1, -1 ]), (1 << (2*BigDigit::bits)) - 1); - check(BigUint::new(~[ 0, 0, 1 ]), (1 << (2*BigDigit::bits))); - check(BigUint::new(~[-1, -1, -1 ]), (1 << (3*BigDigit::bits)) - 1); - check(BigUint::new(~[ 0, 0, 0, 1 ]), (1 << (3*BigDigit::bits))); - check(BigUint::new(~[-1, -1, -1, -1 >> 1]), i64::MAX); + check(BigUint::new(Vec::new( )), 0); + check(BigUint::new(vec!( 1 )), (1 << (0*BigDigit::bits))); + check(BigUint::new(vec!(-1 )), (1 << (1*BigDigit::bits)) - 1); + check(BigUint::new(vec!( 0, 1 )), (1 << (1*BigDigit::bits))); + check(BigUint::new(vec!(-1, -1 )), (1 << (2*BigDigit::bits)) - 1); + check(BigUint::new(vec!( 0, 0, 1 )), (1 << (2*BigDigit::bits))); + check(BigUint::new(vec!(-1, -1, -1 )), (1 << (3*BigDigit::bits)) - 1); + check(BigUint::new(vec!( 0, 0, 0, 1 )), (1 << (3*BigDigit::bits))); + check(BigUint::new(vec!(-1, -1, -1, -1 >> 1)), i64::MAX); assert_eq!(i64::MIN.to_biguint(), None); - assert_eq!(BigUint::new(~[-1, -1, -1, -1 ]).to_i64(), None); - assert_eq!(BigUint::new(~[ 0, 0, 0, 0, 1]).to_i64(), None); - assert_eq!(BigUint::new(~[-1, -1, -1, -1, -1]).to_i64(), None); + assert_eq!(BigUint::new(vec!(-1, -1, -1, -1 )).to_i64(), None); + assert_eq!(BigUint::new(vec!( 0, 0, 0, 0, 1)).to_i64(), None); + assert_eq!(BigUint::new(vec!(-1, -1, -1, -1, -1)).to_i64(), None); } #[cfg(target_word_size = "64")] @@ -1686,16 +1716,16 @@ mod biguint_tests { check(One::one(), 1); check(i64::MAX.to_biguint().unwrap(), i64::MAX); - check(BigUint::new(~[ ]), 0); - check(BigUint::new(~[ 1 ]), (1 << (0*BigDigit::bits))); - check(BigUint::new(~[-1 ]), (1 << (1*BigDigit::bits)) - 1); - check(BigUint::new(~[ 0, 1 ]), (1 << (1*BigDigit::bits))); - check(BigUint::new(~[-1, -1 >> 1]), i64::MAX); + check(BigUint::new(Vec::new( )), 0); + check(BigUint::new(vec!( 1 )), (1 << (0*BigDigit::bits))); + check(BigUint::new(vec!(-1 )), (1 << (1*BigDigit::bits)) - 1); + check(BigUint::new(vec!( 0, 1 )), (1 << (1*BigDigit::bits))); + check(BigUint::new(vec!(-1, -1 >> 1)), i64::MAX); assert_eq!(i64::MIN.to_biguint(), None); - assert_eq!(BigUint::new(~[-1, -1 ]).to_i64(), None); - assert_eq!(BigUint::new(~[ 0, 0, 1]).to_i64(), None); - assert_eq!(BigUint::new(~[-1, -1, -1]).to_i64(), None); + assert_eq!(BigUint::new(vec!(-1, -1 )).to_i64(), None); + assert_eq!(BigUint::new(vec!( 0, 0, 1)).to_i64(), None); + assert_eq!(BigUint::new(vec!(-1, -1, -1)).to_i64(), None); } #[cfg(target_word_size = "32")] @@ -1712,18 +1742,18 @@ mod biguint_tests { check(u64::MIN.to_biguint().unwrap(), u64::MIN); check(u64::MAX.to_biguint().unwrap(), u64::MAX); - check(BigUint::new(~[ ]), 0); - check(BigUint::new(~[ 1 ]), (1 << (0*BigDigit::bits))); - check(BigUint::new(~[-1 ]), (1 << (1*BigDigit::bits)) - 1); - check(BigUint::new(~[ 0, 1 ]), (1 << (1*BigDigit::bits))); - check(BigUint::new(~[-1, -1 ]), (1 << (2*BigDigit::bits)) - 1); - check(BigUint::new(~[ 0, 0, 1 ]), (1 << (2*BigDigit::bits))); - check(BigUint::new(~[-1, -1, -1 ]), (1 << (3*BigDigit::bits)) - 1); - check(BigUint::new(~[ 0, 0, 0, 1]), (1 << (3*BigDigit::bits))); - check(BigUint::new(~[-1, -1, -1, -1]), u64::MAX); + check(BigUint::new(Vec::new( )), 0); + check(BigUint::new(vec!( 1 )), (1 << (0*BigDigit::bits))); + check(BigUint::new(vec!(-1 )), (1 << (1*BigDigit::bits)) - 1); + check(BigUint::new(vec!( 0, 1 )), (1 << (1*BigDigit::bits))); + check(BigUint::new(vec!(-1, -1 )), (1 << (2*BigDigit::bits)) - 1); + check(BigUint::new(vec!( 0, 0, 1 )), (1 << (2*BigDigit::bits))); + check(BigUint::new(vec!(-1, -1, -1 )), (1 << (3*BigDigit::bits)) - 1); + check(BigUint::new(vec!( 0, 0, 0, 1)), (1 << (3*BigDigit::bits))); + check(BigUint::new(vec!(-1, -1, -1, -1)), u64::MAX); - assert_eq!(BigUint::new(~[ 0, 0, 0, 0, 1]).to_u64(), None); - assert_eq!(BigUint::new(~[-1, -1, -1, -1, -1]).to_u64(), None); + assert_eq!(BigUint::new(vec!( 0, 0, 0, 0, 1)).to_u64(), None); + assert_eq!(BigUint::new(vec!(-1, -1, -1, -1, -1)).to_u64(), None); } #[cfg(target_word_size = "64")] @@ -1740,14 +1770,14 @@ mod biguint_tests { check(u64::MIN.to_biguint().unwrap(), u64::MIN); check(u64::MAX.to_biguint().unwrap(), u64::MAX); - check(BigUint::new(~[ ]), 0); - check(BigUint::new(~[ 1 ]), (1 << (0*BigDigit::bits))); - check(BigUint::new(~[-1 ]), (1 << (1*BigDigit::bits)) - 1); - check(BigUint::new(~[ 0, 1]), (1 << (1*BigDigit::bits))); - check(BigUint::new(~[-1, -1]), u64::MAX); + check(BigUint::new(Vec::new( )), 0); + check(BigUint::new(vec!( 1 )), (1 << (0*BigDigit::bits))); + check(BigUint::new(vec!(-1 )), (1 << (1*BigDigit::bits)) - 1); + check(BigUint::new(vec!( 0, 1)), (1 << (1*BigDigit::bits))); + check(BigUint::new(vec!(-1, -1)), u64::MAX); - assert_eq!(BigUint::new(~[ 0, 0, 1]).to_u64(), None); - assert_eq!(BigUint::new(~[-1, -1, -1]).to_u64(), None); + assert_eq!(BigUint::new(vec!( 0, 0, 1)).to_u64(), None); + assert_eq!(BigUint::new(vec!(-1, -1, -1)).to_u64(), None); } #[test] @@ -1757,8 +1787,8 @@ mod biguint_tests { assert_eq!(n.to_bigint().unwrap().to_biguint().unwrap(), n); } check(Zero::zero(), Zero::zero()); - check(BigUint::new(~[1,2,3]), - BigInt::from_biguint(Plus, BigUint::new(~[1,2,3]))); + check(BigUint::new(vec!(1,2,3)), + BigInt::from_biguint(Plus, BigUint::new(vec!(1,2,3)))); } static sum_triples: &'static [(&'static [BigDigit], @@ -2017,11 +2047,11 @@ mod biguint_tests { assert!(((one << 64) + one).is_odd()); } - fn to_str_pairs() -> ~[ (BigUint, ~[(uint, ~str)]) ] { + fn to_str_pairs() -> Vec<(BigUint, Vec<(uint, ~str)> ) > { let bits = BigDigit::bits; - ~[( Zero::zero(), ~[ + vec!(( Zero::zero(), vec!( (2, ~"0"), (3, ~"0") - ]), ( BigUint::from_slice([ 0xff ]), ~[ + )), ( BigUint::from_slice([ 0xff ]), vec!( (2, ~"11111111"), (3, ~"100110"), (4, ~"3333"), @@ -2037,41 +2067,48 @@ mod biguint_tests { (14, ~"143"), (15, ~"120"), (16, ~"ff") - ]), ( BigUint::from_slice([ 0xfff ]), ~[ + )), ( BigUint::from_slice([ 0xfff ]), vec!( (2, ~"111111111111"), (4, ~"333333"), (16, ~"fff") - ]), ( BigUint::from_slice([ 1, 2 ]), ~[ + )), ( BigUint::from_slice([ 1, 2 ]), vec!( (2, ~"10" + - str::from_chars(vec::from_elem(bits - 1, '0')) + "1"), + str::from_chars(Vec::from_elem(bits - 1, '0').as_slice()) + "1"), (4, ~"2" + - str::from_chars(vec::from_elem(bits / 2 - 1, '0')) + "1"), + str::from_chars(Vec::from_elem(bits / 2 - 1, '0').as_slice()) + + "1"), (10, match bits { 32 => ~"8589934593", 16 => ~"131073", _ => fail!() }), (16, ~"2" + - str::from_chars(vec::from_elem(bits / 4 - 1, '0')) + "1") - ]), ( BigUint::from_slice([ 1, 2, 3 ]), ~[ + str::from_chars(Vec::from_elem(bits / 4 - 1, '0').as_slice()) + + "1") + )), ( BigUint::from_slice([ 1, 2, 3 ]), vec!( (2, ~"11" + - str::from_chars(vec::from_elem(bits - 2, '0')) + "10" + - str::from_chars(vec::from_elem(bits - 1, '0')) + "1"), + str::from_chars(Vec::from_elem(bits - 2, '0').as_slice()) + "10" + + str::from_chars(Vec::from_elem(bits - 1, '0').as_slice()) + + "1"), (4, ~"3" + - str::from_chars(vec::from_elem(bits / 2 - 1, '0')) + "2" + - str::from_chars(vec::from_elem(bits / 2 - 1, '0')) + "1"), + str::from_chars(Vec::from_elem(bits / 2 - 1, '0').as_slice()) + + "2" + + str::from_chars(Vec::from_elem(bits / 2 - 1, + '0').as_slice()) + "1"), (10, match bits { 32 => ~"55340232229718589441", 16 => ~"12885032961", _ => fail!() }), (16, ~"3" + - str::from_chars(vec::from_elem(bits / 4 - 1, '0')) + "2" + - str::from_chars(vec::from_elem(bits / 4 - 1, '0')) + "1") - ]) ] + str::from_chars(Vec::from_elem(bits / 4 - 1, '0').as_slice()) + + "2" + + str::from_chars(Vec::from_elem(bits / 4 - 1, '0').as_slice()) + + "1") + )) ) } #[test] @@ -2134,7 +2171,7 @@ mod biguint_tests { #[test] fn test_bits() { - assert_eq!(BigUint::new(~[0,0,0,0]).bits(), 0); + assert_eq!(BigUint::new(vec!(0,0,0,0)).bits(), 0); let n: BigUint = FromPrimitive::from_uint(0).unwrap(); assert_eq!(n.bits(), 0); let n: BigUint = FromPrimitive::from_uint(1).unwrap(); @@ -2207,6 +2244,7 @@ mod bigint_tests { use std::num::{ToPrimitive, FromPrimitive}; use std::rand::{task_rng}; use std::u64; + use std::vec_ng::Vec; #[test] fn test_from_biguint() { @@ -2224,12 +2262,14 @@ mod bigint_tests { #[test] fn test_cmp() { let vs = [ &[2 as BigDigit], &[1, 1], &[2, 1], &[1, 1, 1] ]; - let mut nums = ~[]; + let mut nums = Vec::new(); for s in vs.rev_iter() { nums.push(BigInt::from_slice(Minus, *s)); } nums.push(Zero::zero()); - nums.push_all_move(vs.map(|s| BigInt::from_slice(Plus, *s))); + nums.push_all_move(vs.iter() + .map(|s| BigInt::from_slice(Plus, *s)) + .collect()); for (i, ni) in nums.iter().enumerate() { for (j0, nj) in nums.slice(i, nums.len()).iter().enumerate() { @@ -2282,15 +2322,20 @@ mod bigint_tests { None); assert_eq!( - BigInt::from_biguint(Plus, BigUint::new(~[1, 2, 3, 4, 5])).to_i64(), + BigInt::from_biguint(Plus, BigUint::new(vec!(1, 2, 3, 4, 5))).to_i64(), None); assert_eq!( - BigInt::from_biguint(Minus, BigUint::new(~[1, 0, 0, 1<<(BigDigit::bits-1)])).to_i64(), + BigInt::from_biguint( + Minus, + BigUint::new(vec!(1, + 0, + 0, + 1<<(BigDigit::bits-1)))).to_i64(), None); assert_eq!( - BigInt::from_biguint(Minus, BigUint::new(~[1, 2, 3, 4, 5])).to_i64(), + BigInt::from_biguint(Minus, BigUint::new(vec!(1, 2, 3, 4, 5))).to_i64(), None); } @@ -2308,12 +2353,12 @@ mod bigint_tests { check(u64::MAX.to_bigint().unwrap(), u64::MAX); assert_eq!( - BigInt::from_biguint(Plus, BigUint::new(~[1, 2, 3, 4, 5])).to_u64(), + BigInt::from_biguint(Plus, BigUint::new(vec!(1, 2, 3, 4, 5))).to_u64(), None); let max_value: BigUint = FromPrimitive::from_u64(u64::MAX).unwrap(); assert_eq!(BigInt::from_biguint(Minus, max_value).to_u64(), None); - assert_eq!(BigInt::from_biguint(Minus, BigUint::new(~[1, 2, 3, 4, 5])).to_u64(), None); + assert_eq!(BigInt::from_biguint(Minus, BigUint::new(vec!(1, 2, 3, 4, 5))).to_u64(), None); } #[test] @@ -2325,11 +2370,11 @@ mod bigint_tests { let zero: BigInt = Zero::zero(); let unsigned_zero: BigUint = Zero::zero(); let positive = BigInt::from_biguint( - Plus, BigUint::new(~[1,2,3])); + Plus, BigUint::new(vec!(1,2,3))); let negative = -positive; check(zero, unsigned_zero); - check(positive, BigUint::new(~[1,2,3])); + check(positive, BigUint::new(vec!(1,2,3))); assert_eq!(negative.to_biguint(), None); } @@ -2727,10 +2772,10 @@ mod bigint_tests { #[test] fn test_neg() { - assert!(-BigInt::new(Plus, ~[1, 1, 1]) == - BigInt::new(Minus, ~[1, 1, 1])); - assert!(-BigInt::new(Minus, ~[1, 1, 1]) == - BigInt::new(Plus, ~[1, 1, 1])); + assert!(-BigInt::new(Plus, vec!(1, 1, 1)) == + BigInt::new(Minus, vec!(1, 1, 1))); + assert!(-BigInt::new(Minus, vec!(1, 1, 1)) == + BigInt::new(Plus, vec!(1, 1, 1))); let zero: BigInt = Zero::zero(); assert_eq!(-zero, zero); } diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index 79ff54cb90c68..ebc48fe1b697d 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -16,6 +16,7 @@ use std::cmp; use std::fmt; use std::from_str::FromStr; use std::num::{Zero,One,ToStrRadix,FromStrRadix,Round}; +use std::vec_ng::Vec; use bigint::{BigInt, BigUint, Sign, Plus, Minus}; /// Represents the ratio between 2 numbers. @@ -295,13 +296,13 @@ impl FromStr for Ratio { /// Parses `numer/denom`. fn from_str(s: &str) -> Option> { - let split: ~[&str] = s.splitn('/', 1).collect(); + let split: Vec<&str> = s.splitn('/', 1).collect(); if split.len() < 2 { return None } - let a_option: Option = FromStr::from_str(split[0]); + let a_option: Option = FromStr::from_str(*split.get(0)); a_option.and_then(|a| { - let b_option: Option = FromStr::from_str(split[1]); + let b_option: Option = FromStr::from_str(*split.get(1)); b_option.and_then(|b| { Some(Ratio::new(a.clone(), b.clone())) }) @@ -312,15 +313,16 @@ impl FromStrRadix for Ratio { /// Parses `numer/denom` where the numbers are in base `radix`. fn from_str_radix(s: &str, radix: uint) -> Option> { - let split: ~[&str] = s.splitn('/', 1).collect(); + let split: Vec<&str> = s.splitn('/', 1).collect(); if split.len() < 2 { None } else { - let a_option: Option = FromStrRadix::from_str_radix(split[0], - radix); + let a_option: Option = FromStrRadix::from_str_radix( + *split.get(0), + radix); a_option.and_then(|a| { let b_option: Option = - FromStrRadix::from_str_radix(split[1], radix); + FromStrRadix::from_str_radix(*split.get(1), radix); b_option.and_then(|b| { Some(Ratio::new(a.clone(), b.clone())) }) diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 2a92ef496c7be..5c234c3747bae 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -798,7 +798,7 @@ pub fn build_session_options(matches: &getopts::Matches) let flags = vec_ng::append(matches.opt_strs(level_short) .move_iter() .collect(), - matches.opt_strs(level_name)); + matches.opt_strs(level_name).as_slice()); for lint_name in flags.iter() { let lint_name = lint_name.replace("-", "_"); match lint_dict.find_equiv(&lint_name) { diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index af0acee07fd21..ee9fbd26f2031 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -239,7 +239,7 @@ pub fn run_compiler(args: &[~str]) { let lint_flags = vec_ng::append(matches.opt_strs("W") .move_iter() .collect(), - matches.opt_strs("warn")); + matches.opt_strs("warn").as_slice()); if lint_flags.iter().any(|x| x == &~"help") { describe_warnings(); return; @@ -269,7 +269,7 @@ pub fn run_compiler(args: &[~str]) { let (input, input_file_path) = match matches.free.len() { 0u => d::early_error("no input filename given"), 1u => { - let ifile = matches.free[0].as_slice(); + let ifile = matches.free.get(0).as_slice(); if ifile == "-" { let contents = io::stdin().read_to_end().unwrap(); let src = str::from_utf8_owned(contents).unwrap(); diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index f26977e211ca2..6d1bf9bb464fe 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -35,12 +35,6 @@ pub trait Clean { fn clean(&self) -> T; } -impl, U> Clean<~[U]> for ~[T] { - fn clean(&self) -> ~[U] { - self.iter().map(|x| x.clean()).collect() - } -} - impl, U> Clean> for Vec { fn clean(&self) -> Vec { self.iter().map(|x| x.clean()).collect() @@ -75,7 +69,7 @@ impl, U> Clean> for syntax::opt_vec::OptVec { pub struct Crate { name: ~str, module: Option, - externs: ~[(ast::CrateNum, ExternalCrate)], + externs: Vec<(ast::CrateNum, ExternalCrate)> , } impl<'a> Clean for visit_ast::RustdocVisitor<'a> { @@ -83,13 +77,13 @@ impl<'a> Clean for visit_ast::RustdocVisitor<'a> { use syntax::attr::find_crateid; let cx = local_data::get(super::ctxtkey, |x| *x.unwrap()); - let mut externs = ~[]; + let mut externs = Vec::new(); cx.sess.cstore.iter_crate_data(|n, meta| { externs.push((n, meta.clean())); }); Crate { - name: match find_crateid(self.attrs) { + name: match find_crateid(self.attrs.as_slice()) { Some(n) => n.name, None => fail!("rustdoc requires a `crate_id` crate attribute"), }, @@ -102,7 +96,7 @@ impl<'a> Clean for visit_ast::RustdocVisitor<'a> { #[deriving(Clone, Encodable, Decodable)] pub struct ExternalCrate { name: ~str, - attrs: ~[Attribute], + attrs: Vec , } impl Clean for cstore::crate_metadata { @@ -125,7 +119,7 @@ pub struct Item { source: Span, /// Not everything has a name. E.g., impls name: Option<~str>, - attrs: ~[Attribute], + attrs: Vec , inner: ItemEnum, visibility: Option, id: ast::NodeId, @@ -195,7 +189,7 @@ pub enum ItemEnum { #[deriving(Clone, Encodable, Decodable)] pub struct Module { - items: ~[Item], + items: Vec , is_crate: bool, } @@ -206,13 +200,13 @@ impl Clean for doctree::Module { } else { ~"" }; - let mut foreigns = ~[]; + let mut foreigns = Vec::new(); for subforeigns in self.foreigns.clean().move_iter() { for foreign in subforeigns.move_iter() { foreigns.push(foreign) } } - let items: ~[~[Item]] = ~[ + let items: Vec > = vec!( self.structs.clean().move_iter().collect(), self.enums.clean().move_iter().collect(), self.fns.clean().move_iter().collect(), @@ -224,7 +218,7 @@ impl Clean for doctree::Module { self.impls.clean().move_iter().collect(), self.view_items.clean().move_iter().collect(), self.macros.clean().move_iter().collect() - ]; + ); Item { name: Some(name), attrs: self.attrs.clean(), @@ -233,7 +227,9 @@ impl Clean for doctree::Module { id: self.id, inner: ModuleItem(Module { is_crate: self.is_crate, - items: items.concat_vec(), + items: items.iter() + .flat_map(|x| x.iter().map(|x| (*x).clone())) + .collect(), }) } } @@ -242,7 +238,7 @@ impl Clean for doctree::Module { #[deriving(Clone, Encodable, Decodable)] pub enum Attribute { Word(~str), - List(~str, ~[Attribute]), + List(~str, Vec ), NameValue(~str, ~str) } @@ -292,8 +288,7 @@ impl<'a> attr::AttrMetaMethods for &'a Attribute { pub struct TyParam { name: ~str, id: ast::NodeId, - bounds: ~[TyParamBound] -} + bounds: Vec } impl Clean for ast::TyParam { fn clean(&self) -> TyParam { @@ -340,9 +335,8 @@ impl Clean for ast::Lifetime { // maybe use a Generic enum and use ~[Generic]? #[deriving(Clone, Encodable, Decodable)] pub struct Generics { - lifetimes: ~[Lifetime], - type_params: ~[TyParam] -} + lifetimes: Vec , + type_params: Vec } impl Clean for ast::Generics { fn clean(&self) -> Generics { @@ -373,7 +367,7 @@ impl Clean for ast::Method { }, output: (self.decl.output.clean()), cf: self.decl.cf.clean(), - attrs: ~[] + attrs: Vec::new() }; Item { name: Some(self.ident.clean()), @@ -411,7 +405,7 @@ impl Clean for ast::TypeMethod { }, output: (self.decl.output.clean()), cf: self.decl.cf.clean(), - attrs: ~[] + attrs: Vec::new() }; Item { name: Some(self.ident.clean()), @@ -476,12 +470,11 @@ impl Clean for doctree::Function { pub struct ClosureDecl { sigil: ast::Sigil, region: Option, - lifetimes: ~[Lifetime], + lifetimes: Vec , decl: FnDecl, onceness: ast::Onceness, purity: ast::Purity, - bounds: ~[TyParamBound] -} + bounds: Vec } impl Clean for ast::ClosureTy { fn clean(&self) -> ClosureDecl { @@ -494,7 +487,7 @@ impl Clean for ast::ClosureTy { purity: self.purity, bounds: match self.bounds { Some(ref x) => x.clean().move_iter().collect(), - None => ~[] + None => Vec::new() }, } } @@ -505,12 +498,11 @@ pub struct FnDecl { inputs: Arguments, output: Type, cf: RetStyle, - attrs: ~[Attribute] -} + attrs: Vec } #[deriving(Clone, Encodable, Decodable)] pub struct Arguments { - values: ~[Argument], + values: Vec , } impl Clean for ast::FnDecl { @@ -521,7 +513,7 @@ impl Clean for ast::FnDecl { }, output: (self.output.clean()), cf: self.cf.clean(), - attrs: ~[] + attrs: Vec::new() } } } @@ -560,9 +552,9 @@ impl Clean for ast::RetStyle { #[deriving(Clone, Encodable, Decodable)] pub struct Trait { - methods: ~[TraitMethod], + methods: Vec , generics: Generics, - parents: ~[Type], + parents: Vec , } impl Clean for doctree::Trait { @@ -632,14 +624,14 @@ pub enum Type { /// structs/enums/traits (anything that'd be an ast::TyPath) ResolvedPath { path: Path, - typarams: Option<~[TyParamBound]>, + typarams: Option >, id: ast::NodeId, }, /// Same as above, but only external variants ExternalPath { path: Path, - typarams: Option<~[TyParamBound]>, - fqn: ~[~str], + typarams: Option >, + fqn: Vec<~str> , kind: TypeKind, krate: ast::CrateNum, }, @@ -655,7 +647,7 @@ pub enum Type { Closure(~ClosureDecl), /// extern "ABI" fn BareFunction(~BareFunctionDecl), - Tuple(~[Type]), + Tuple(Vec ), Vector(~Type), FixedVector(~Type, ~str), String, @@ -746,7 +738,7 @@ impl Clean> for ast::Visibility { pub struct Struct { struct_type: doctree::StructType, generics: Generics, - fields: ~[Item], + fields: Vec , fields_stripped: bool, } @@ -774,7 +766,7 @@ impl Clean for doctree::Struct { #[deriving(Clone, Encodable, Decodable)] pub struct VariantStruct { struct_type: doctree::StructType, - fields: ~[Item], + fields: Vec , fields_stripped: bool, } @@ -790,7 +782,7 @@ impl Clean for syntax::ast::StructDef { #[deriving(Clone, Encodable, Decodable)] pub struct Enum { - variants: ~[Item], + variants: Vec , generics: Generics, variants_stripped: bool, } @@ -835,7 +827,7 @@ impl Clean for doctree::Variant { #[deriving(Clone, Encodable, Decodable)] pub enum VariantKind { CLikeVariant, - TupleVariant(~[Type]), + TupleVariant(Vec ), StructVariant(VariantStruct), } @@ -882,7 +874,7 @@ impl Clean for syntax::codemap::Span { #[deriving(Clone, Encodable, Decodable)] pub struct Path { global: bool, - segments: ~[PathSegment], + segments: Vec , } impl Clean for ast::Path { @@ -897,8 +889,8 @@ impl Clean for ast::Path { #[deriving(Clone, Encodable, Decodable)] pub struct PathSegment { name: ~str, - lifetimes: ~[Lifetime], - types: ~[Type], + lifetimes: Vec , + types: Vec , } impl Clean for ast::PathSegment { @@ -969,7 +961,7 @@ impl Clean for ast::BareFnTy { purity: self.purity, generics: Generics { lifetimes: self.lifetimes.clean().move_iter().collect(), - type_params: ~[], + type_params: Vec::new(), }, decl: self.decl.clean(), abi: self.abis.to_str(), @@ -1025,7 +1017,7 @@ pub struct Impl { generics: Generics, trait_: Option, for_: Type, - methods: ~[Item], + methods: Vec , } impl Clean for doctree::Impl { @@ -1069,7 +1061,7 @@ impl Clean for ast::ViewItem { #[deriving(Clone, Encodable, Decodable)] pub enum ViewItemInner { ExternCrate(~str, Option<~str>, ast::NodeId), - Import(~[ViewPath]) + Import(Vec) } impl Clean for ast::ViewItem_ { @@ -1096,7 +1088,7 @@ pub enum ViewPath { // use source::*; GlobImport(ImportSource), // use source::{a, b, c}; - ImportList(ImportSource, ~[ViewListIdent]), + ImportList(ImportSource, Vec ), } #[deriving(Clone, Encodable, Decodable)] @@ -1231,7 +1223,7 @@ fn name_from_pat(p: &ast::Pat) -> ~str { } /// Given a Type, resolve it using the def_map -fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>, +fn resolve_type(path: Path, tpbs: Option >, id: ast::NodeId) -> Type { let cx = local_data::get(super::ctxtkey, |x| *x.unwrap()); let tycx = match cx.tycx { @@ -1274,9 +1266,14 @@ fn resolve_type(path: Path, tpbs: Option<~[TyParamBound]>, ResolvedPath{ path: path, typarams: tpbs, id: def_id.node } } else { let fqn = csearch::get_item_path(tycx, def_id); - let fqn = fqn.move_iter().map(|i| i.to_str()).to_owned_vec(); - ExternalPath{ path: path, typarams: tpbs, fqn: fqn, kind: kind, - krate: def_id.krate } + let fqn = fqn.move_iter().map(|i| i.to_str()).collect(); + ExternalPath { + path: path, + typarams: tpbs, + fqn: fqn, + kind: kind, + krate: def_id.krate, + } } } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 58bed8a9df993..a629a8ef9742b 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -21,6 +21,7 @@ use syntax; use std::cell::RefCell; use std::os; use std::local_data; +use std::vec_ng::Vec; use collections::HashSet; use visit_ast::RustdocVisitor; @@ -39,8 +40,8 @@ pub struct CrateAnalysis { } /// Parses, resolves, and typechecks the given crate -fn get_ast_and_resolve(cpath: &Path, - libs: HashSet, cfgs: ~[~str]) -> (DocContext, CrateAnalysis) { +fn get_ast_and_resolve(cpath: &Path, libs: HashSet, cfgs: Vec<~str>) + -> (DocContext, CrateAnalysis) { use syntax::codemap::dummy_spanned; use rustc::driver::driver::{FileInput, build_configuration, phase_1_parse_input, @@ -88,7 +89,8 @@ fn get_ast_and_resolve(cpath: &Path, }); } -pub fn run_core (libs: HashSet, cfgs: ~[~str], path: &Path) -> (clean::Crate, CrateAnalysis) { +pub fn run_core(libs: HashSet, cfgs: Vec<~str>, path: &Path) + -> (clean::Crate, CrateAnalysis) { let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs); let ctxt = @ctxt; local_data::set(super::ctxtkey, ctxt); diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index c5849f5aa28b6..8dbe85571bd71 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -11,6 +11,7 @@ //! This module is used to store stuff from Rust's AST in a more convenient //! manner (and with prettier names) before cleaning. +use std::vec_ng::Vec; use syntax; use syntax::codemap::Span; use syntax::ast; @@ -18,21 +19,21 @@ use syntax::ast::{Ident, NodeId}; pub struct Module { name: Option, - attrs: ~[ast::Attribute], + attrs: Vec , where: Span, - structs: ~[Struct], - enums: ~[Enum], - fns: ~[Function], - mods: ~[Module], + structs: Vec , + enums: Vec , + fns: Vec , + mods: Vec , id: NodeId, - typedefs: ~[Typedef], - statics: ~[Static], - traits: ~[Trait], + typedefs: Vec , + statics: Vec , + traits: Vec , vis: ast::Visibility, - impls: ~[Impl], - foreigns: ~[ast::ForeignMod], - view_items: ~[ast::ViewItem], - macros: ~[Macro], + impls: Vec , + foreigns: Vec , + view_items: Vec , + macros: Vec , is_crate: bool, } @@ -43,18 +44,18 @@ impl Module { id: 0, vis: ast::Private, where: syntax::codemap::DUMMY_SP, - attrs : ~[], - structs : ~[], - enums : ~[], - fns : ~[], - mods : ~[], - typedefs : ~[], - statics : ~[], - traits : ~[], - impls : ~[], - view_items : ~[], - foreigns : ~[], - macros : ~[], + attrs : Vec::new(), + structs : Vec::new(), + enums : Vec::new(), + fns : Vec::new(), + mods : Vec::new(), + typedefs : Vec::new(), + statics : Vec::new(), + traits : Vec::new(), + impls : Vec::new(), + view_items : Vec::new(), + foreigns : Vec::new(), + macros : Vec::new(), is_crate : false, } } @@ -83,16 +84,16 @@ pub struct Struct { struct_type: StructType, name: Ident, generics: ast::Generics, - attrs: ~[ast::Attribute], - fields: ~[ast::StructField], + attrs: Vec , + fields: Vec , where: Span, } pub struct Enum { vis: ast::Visibility, - variants: ~[Variant], + variants: Vec , generics: ast::Generics, - attrs: ~[ast::Attribute], + attrs: Vec , id: NodeId, where: Span, name: Ident, @@ -100,7 +101,7 @@ pub struct Enum { pub struct Variant { name: Ident, - attrs: ~[ast::Attribute], + attrs: Vec , kind: ast::VariantKind, id: ast::NodeId, vis: ast::Visibility, @@ -109,7 +110,7 @@ pub struct Variant { pub struct Function { decl: ast::FnDecl, - attrs: ~[ast::Attribute], + attrs: Vec , id: NodeId, name: Ident, vis: ast::Visibility, @@ -123,7 +124,7 @@ pub struct Typedef { gen: ast::Generics, name: Ident, id: ast::NodeId, - attrs: ~[ast::Attribute], + attrs: Vec , where: Span, vis: ast::Visibility, } @@ -133,7 +134,7 @@ pub struct Static { mutability: ast::Mutability, expr: @ast::Expr, name: Ident, - attrs: ~[ast::Attribute], + attrs: Vec , vis: ast::Visibility, id: ast::NodeId, where: Span, @@ -141,10 +142,10 @@ pub struct Static { pub struct Trait { name: Ident, - methods: ~[ast::TraitMethod], //should be TraitMethod + methods: Vec , //should be TraitMethod generics: ast::Generics, - parents: ~[ast::TraitRef], - attrs: ~[ast::Attribute], + parents: Vec , + attrs: Vec , id: ast::NodeId, where: Span, vis: ast::Visibility, @@ -154,8 +155,8 @@ pub struct Impl { generics: ast::Generics, trait_: Option, for_: ast::P, - methods: ~[@ast::Method], - attrs: ~[ast::Attribute], + methods: Vec<@ast::Method> , + attrs: Vec , where: Span, vis: ast::Visibility, id: ast::NodeId, @@ -164,7 +165,7 @@ pub struct Impl { pub struct Macro { name: Ident, id: ast::NodeId, - attrs: ~[ast::Attribute], + attrs: Vec , where: Span, } diff --git a/src/librustdoc/fold.rs b/src/librustdoc/fold.rs index 672b46afcd083..9274724e3ecdb 100644 --- a/src/librustdoc/fold.rs +++ b/src/librustdoc/fold.rs @@ -11,6 +11,7 @@ use clean::*; use std::iter::Extendable; use std::mem::{replace, swap}; +use std::vec_ng::Vec; pub trait DocFolder { fn fold_item(&mut self, item: Item) -> Option { @@ -23,7 +24,7 @@ pub trait DocFolder { let inner = inner; let inner = match inner { StructItem(mut i) => { - let mut foo = ~[]; swap(&mut foo, &mut i.fields); + let mut foo = Vec::new(); swap(&mut foo, &mut i.fields); let num_fields = foo.len(); i.fields.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x))); i.fields_stripped |= num_fields != i.fields.len(); @@ -33,7 +34,7 @@ pub trait DocFolder { ModuleItem(self.fold_mod(i)) }, EnumItem(mut i) => { - let mut foo = ~[]; swap(&mut foo, &mut i.variants); + let mut foo = Vec::new(); swap(&mut foo, &mut i.variants); let num_variants = foo.len(); i.variants.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x))); i.variants_stripped |= num_variants != i.variants.len(); @@ -56,12 +57,12 @@ pub trait DocFolder { }, } } - let mut foo = ~[]; swap(&mut foo, &mut i.methods); + let mut foo = Vec::new(); swap(&mut foo, &mut i.methods); i.methods.extend(&mut foo.move_iter().filter_map(|x| vtrm(self, x))); TraitItem(i) }, ImplItem(mut i) => { - let mut foo = ~[]; swap(&mut foo, &mut i.methods); + let mut foo = Vec::new(); swap(&mut foo, &mut i.methods); i.methods.extend(&mut foo.move_iter().filter_map(|x| self.fold_item(x))); ImplItem(i) }, @@ -69,7 +70,7 @@ pub trait DocFolder { let i2 = i.clone(); // this clone is small match i.kind { StructVariant(mut j) => { - let mut foo = ~[]; swap(&mut foo, &mut j.fields); + let mut foo = Vec::new(); swap(&mut foo, &mut j.fields); let num_fields = foo.len(); let c = |x| self.fold_item(x); j.fields.extend(&mut foo.move_iter().filter_map(c)); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index a8b7e374a6ab9..2b9aaebbbfd70 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -18,6 +18,7 @@ use std::fmt; use std::local_data; use std::io; +use std::vec_ng::Vec; use syntax::ast; use syntax::ast_util; @@ -170,7 +171,7 @@ fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool, } }, |_cache| { - Some((fqn.to_owned(), match kind { + Some((Vec::from_slice(fqn), match kind { clean::TypeStruct => "struct", clean::TypeEnum => "enum", clean::TypeFunction => "fn", @@ -181,7 +182,7 @@ fn external_path(w: &mut io::Writer, p: &clean::Path, print_all: bool, fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, root: |&render::Cache, &[~str]| -> Option<~str>, - info: |&render::Cache| -> Option<(~[~str], &'static str)>) + info: |&render::Cache| -> Option<(Vec<~str> , &'static str)>) -> fmt::Result { // The generics will get written to both the title and link @@ -210,7 +211,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, local_data::get(cache_key, |cache| { let cache = cache.unwrap().get(); let abs_root = root(cache, loc.as_slice()); - let rel_root = match path.segments[0].name.as_slice() { + let rel_root = match path.segments.get(0).name.as_slice() { "self" => Some(~"./"), _ => None, }; @@ -279,7 +280,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool, /// Helper to render type parameters fn typarams(w: &mut io::Writer, - typarams: &Option<~[clean::TyParamBound]>) -> fmt::Result { + typarams: &Option >) -> fmt::Result { match *typarams { Some(ref params) => { try!(write!(w, "<")); @@ -535,11 +536,11 @@ impl fmt::Show for clean::ViewListIdent { Some(did) if ast_util::is_local(did) => { let path = clean::Path { global: false, - segments: ~[clean::PathSegment { + segments: vec!(clean::PathSegment { name: self.name.clone(), - lifetimes: ~[], - types: ~[], - }] + lifetimes: Vec::new(), + types: Vec::new(), + }) }; resolved_path(f.buf, did.node, &path, false) } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index b705e976e4656..589c9a5d1e33b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -69,7 +69,7 @@ use html::highlight; pub struct Context { /// Current hierarchy of components leading down to what's currently being /// rendered - current: ~[~str], + current: Vec<~str> , /// String representation of how to get back to the root path of the 'doc/' /// folder in terms of a relative URL. root_path: ~str, @@ -84,7 +84,7 @@ pub struct Context { /// functions), and the value is the list of containers belonging to this /// header. This map will change depending on the surrounding context of the /// page. - sidebar: HashMap<~str, ~[~str]>, + sidebar: HashMap<~str, Vec<~str> >, /// This flag indicates whether [src] links should be generated or not. If /// the source files are present in the html rendering, then this will be /// `true`. @@ -131,14 +131,14 @@ pub struct Cache { /// /// The values of the map are a list of implementations and documentation /// found on that implementation. - impls: HashMap)]>, + impls: HashMap)> >, /// Maintains a mapping of local crate node ids to the fully qualified name /// and "short type description" of that node. This is used when generating /// URLs when a type is being linked to. External paths are not located in /// this map because the `External` type itself has all the information /// necessary. - paths: HashMap, + paths: HashMap , &'static str)>, /// This map contains information about all known traits of this crate. /// Implementations of a crate should inherit the documentation of the @@ -149,16 +149,16 @@ pub struct Cache { /// When rendering traits, it's often useful to be able to list all /// implementors of the trait, and this mapping is exactly, that: a mapping /// of trait ids to the list of known implementors of the trait - implementors: HashMap, + implementors: HashMap >, /// Cache of where external crate documentation can be found. extern_locations: HashMap, // Private fields only used when initially crawling a crate to build a cache - priv stack: ~[~str], - priv parent_stack: ~[ast::NodeId], - priv search_index: ~[IndexItem], + priv stack: Vec<~str> , + priv parent_stack: Vec , + priv search_index: Vec , priv privmod: bool, priv public_items: NodeSet, @@ -203,13 +203,13 @@ struct IndexItem { // TLS keys used to carry information around during rendering. local_data_key!(pub cache_key: Arc) -local_data_key!(pub current_location_key: ~[~str]) +local_data_key!(pub current_location_key: Vec<~str> ) /// Generates the documentation for `crate` into the directory `dst` pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { let mut cx = Context { dst: dst, - current: ~[], + current: Vec::new(), root_path: ~"", sidebar: HashMap::new(), layout: layout::Layout { @@ -251,9 +251,9 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { paths: HashMap::new(), traits: HashMap::new(), implementors: HashMap::new(), - stack: ~[], - parent_stack: ~[], - search_index: ~[], + stack: Vec::new(), + parent_stack: Vec::new(), + search_index: Vec::new(), extern_locations: HashMap::new(), privmod: false, public_items: public_items, @@ -530,7 +530,7 @@ impl DocFolder for Cache { match i.trait_ { Some(clean::ResolvedPath{ id, .. }) => { let v = self.implementors.find_or_insert_with(id, |_|{ - ~[] + Vec::new() }); match i.for_ { clean::ResolvedPath{..} => { @@ -661,7 +661,7 @@ impl DocFolder for Cache { match i.for_ { clean::ResolvedPath { id, .. } => { let v = self.impls.find_or_insert_with(id, |_| { - ~[] + Vec::new() }); // extract relevant documentation for this impl match attrs.move_iter().find(|a| { @@ -754,7 +754,7 @@ impl Context { // using a rwarc makes this parallelizable in the future local_data::set(cache_key, Arc::new(cache)); - let mut work = ~[(self, item)]; + let mut work = vec!((self, item)); loop { match work.pop() { Some((mut cx, item)) => try!(cx.item(item, |cx, item| { @@ -886,7 +886,7 @@ impl<'a> fmt::Show for Item<'a> { } if self.cx.include_sources { - let mut path = ~[]; + let mut path = Vec::new(); clean_srcpath(self.item.source.filename.as_bytes(), |component| { path.push(component.to_owned()); }); @@ -933,8 +933,9 @@ impl<'a> fmt::Show for Item<'a> { shortty(self.item), self.item.name.get_ref().as_slice())); match self.item.inner { - clean::ModuleItem(ref m) => item_module(fmt.buf, self.cx, - self.item, m.items), + clean::ModuleItem(ref m) => { + item_module(fmt.buf, self.cx, self.item, m.items.as_slice()) + } clean::FunctionItem(ref f) | clean::ForeignFunctionItem(ref f) => item_function(fmt.buf, self.item, f), clean::TraitItem(ref t) => item_trait(fmt.buf, self.item, t), @@ -1284,8 +1285,14 @@ fn render_method(w: &mut Writer, meth: &clean::Item) -> fmt::Result { fn item_struct(w: &mut Writer, it: &clean::Item, s: &clean::Struct) -> fmt::Result { try!(write!(w, "
"));
-    try!(render_struct(w, it, Some(&s.generics), s.struct_type, s.fields,
-                         s.fields_stripped, "", true));
+    try!(render_struct(w,
+                       it,
+                       Some(&s.generics),
+                       s.struct_type,
+                       s.fields.as_slice(),
+                       s.fields_stripped,
+                       "",
+                       true));
     try!(write!(w, "
")); try!(document(w, it)); @@ -1333,9 +1340,14 @@ fn item_enum(w: &mut Writer, it: &clean::Item, e: &clean::Enum) -> fmt::Result { try!(write!(w, ")")); } clean::StructVariant(ref s) => { - try!(render_struct(w, v, None, s.struct_type, - s.fields, s.fields_stripped, - " ", false)); + try!(render_struct(w, + v, + None, + s.struct_type, + s.fields.as_slice(), + s.fields_stripped, + " ", + false)); } } } @@ -1644,7 +1656,7 @@ impl<'a> fmt::Show for Sidebar<'a> { } } -fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> { +fn build_sidebar(m: &clean::Module) -> HashMap<~str, Vec<~str> > { let mut map = HashMap::new(); for item in m.items.iter() { let short = shortty(item); @@ -1652,12 +1664,12 @@ fn build_sidebar(m: &clean::Module) -> HashMap<~str, ~[~str]> { None => continue, Some(ref s) => s.to_owned(), }; - let v = map.find_or_insert_with(short.to_owned(), |_| ~[]); + let v = map.find_or_insert_with(short.to_owned(), |_| Vec::new()); v.push(myname); } for (_, items) in map.mut_iter() { - items.sort(); + items.as_mut_slice().sort(); } return map; } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 2d08dca97b986..419add30a7490 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -31,6 +31,7 @@ use std::local_data; use std::io; use std::io::{File, MemWriter}; use std::str; +use std::vec_ng::Vec; use serialize::{json, Decodable, Encodable}; pub mod clean; @@ -79,15 +80,15 @@ static DEFAULT_PASSES: &'static [&'static str] = &[ local_data_key!(pub ctxtkey: @core::DocContext) local_data_key!(pub analysiskey: core::CrateAnalysis) -type Output = (clean::Crate, ~[plugins::PluginJson]); +type Output = (clean::Crate, Vec ); pub fn main() { std::os::set_exit_status(main_args(std::os::args())); } -pub fn opts() -> ~[getopts::OptGroup] { +pub fn opts() -> Vec { use getopts::*; - ~[ + vec!( optflag("h", "help", "show this help message"), optflag("", "version", "print rustdoc's version"), optopt("r", "input-format", "the input type of the specified file", @@ -120,16 +121,18 @@ pub fn opts() -> ~[getopts::OptGroup] { optmulti("", "markdown-after-content", "files to include inline between the content and of a rendered \ Markdown file", - "FILES"), - ] + "FILES") + ) } pub fn usage(argv0: &str) { - println!("{}", getopts::usage(format!("{} [options] ", argv0), opts())); + println!("{}", + getopts::usage(format!("{} [options] ", argv0), + opts().as_slice())); } pub fn main_args(args: &[~str]) -> int { - let matches = match getopts::getopts(args.tail(), opts()) { + let matches = match getopts::getopts(args.tail(), opts().as_slice()) { Ok(m) => m, Err(err) => { println!("{}", err.to_err_msg()); @@ -151,13 +154,19 @@ pub fn main_args(args: &[~str]) -> int { println!("only one input file may be specified"); return 1; } - let input = matches.free[0].as_slice(); + let input = matches.free.get(0).as_slice(); - let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice())); - let libs = @RefCell::new(libs.move_iter().collect()); + let libs = matches.opt_strs("L") + .iter() + .map(|s| Path::new(s.as_slice())) + .collect(); + let libs = @RefCell::new(libs); let test_args = matches.opt_strs("test-args"); - let test_args = test_args.iter().flat_map(|s| s.words()).map(|s| s.to_owned()).to_owned_vec(); + let test_args: Vec<~str> = test_args.iter() + .flat_map(|s| s.words()) + .map(|s| s.to_owned()) + .collect(); let should_test = matches.opt_present("test"); let markdown_input = input.ends_with(".md") || input.ends_with(".markdown"); @@ -165,7 +174,11 @@ pub fn main_args(args: &[~str]) -> int { let output = matches.opt_str("o").map(|s| Path::new(s)); match (should_test, markdown_input) { - (true, true) => return markdown::test(input, libs, test_args), + (true, true) => { + return markdown::test(input, + libs, + test_args.move_iter().collect()) + } (true, false) => return test::run(input, libs, test_args), (false, true) => return markdown::render(input, output.unwrap_or(Path::new("doc")), @@ -173,7 +186,7 @@ pub fn main_args(args: &[~str]) -> int { (false, false) => {} } - if matches.opt_strs("passes") == ~[~"list"] { + if matches.opt_strs("passes").as_slice() == &[~"list"] { println!("Available passes for running rustdoc:"); for &(name, _, description) in PASSES.iter() { println!("{:>20s} - {}", name, description); @@ -248,13 +261,18 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { let mut plugins = matches.opt_strs("plugins"); // First, parse the crate and extract all relevant information. - let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice())); + let libs: Vec = matches.opt_strs("L") + .iter() + .map(|s| Path::new(s.as_slice())) + .collect(); let cfgs = matches.opt_strs("cfg"); let cr = Path::new(cratefile); info!("starting to run rustc"); let (krate, analysis) = std::task::try(proc() { let cr = cr; - core::run_core(libs.move_iter().collect(), cfgs, &cr) + core::run_core(libs.move_iter().collect(), + cfgs.move_iter().collect(), + &cr) }).unwrap(); info!("finished with rustc"); local_data::set(analysiskey, analysis); @@ -344,7 +362,7 @@ fn json_input(input: &str) -> Result { }; // FIXME: this should read from the "plugins" field, but currently // Json doesn't implement decodable... - let plugin_output = ~[]; + let plugin_output = Vec::new(); Ok((krate, plugin_output)) } Ok(..) => Err(~"malformed json input: expected an object at the top"), @@ -353,7 +371,7 @@ fn json_input(input: &str) -> Result { /// Outputs the crate/plugin json as a giant json blob at the specified /// destination. -fn json_output(krate: clean::Crate, res: ~[plugins::PluginJson], +fn json_output(krate: clean::Crate, res: Vec , dst: Path) -> io::IoResult<()> { // { // "schema": version, diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 7ab3fe017b905..f1524d501f9ad 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -88,9 +88,12 @@ pub fn render(input: &str, mut output: Path, matches: &getopts::Matches) -> int let input_str = load_or_return!(input, 1, 2); let (in_header, before_content, after_content) = - match (load_external_files(matches.opt_strs("markdown-in-header")), - load_external_files(matches.opt_strs("markdown-before-content")), - load_external_files(matches.opt_strs("markdown-after-content"))) { + match (load_external_files(matches.opt_strs("markdown-in-header") + .as_slice()), + load_external_files(matches.opt_strs("markdown-before-content") + .as_slice()), + load_external_files(matches.opt_strs("markdown-after-content") + .as_slice())) { (Some(a), Some(b), Some(c)) => (a,b,c), _ => return 3 }; diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index fdd637b1d0f78..64e7d49d0ea08 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -12,6 +12,7 @@ use std::cmp; use collections::HashSet; use std::local_data; use std::uint; +use std::vec_ng::Vec; use syntax::ast; use rustc::util::nodemap::NodeSet; @@ -220,7 +221,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult { impl fold::DocFolder for CommentCleaner { fn fold_item(&mut self, i: Item) -> Option { let mut i = i; - let mut avec: ~[clean::Attribute] = ~[]; + let mut avec: Vec = Vec::new(); for attr in i.attrs.iter() { match attr { &clean::NameValue(~"doc", ref s) => avec.push( @@ -252,7 +253,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { _ => () } } - let mut a: ~[clean::Attribute] = i.attrs.iter().filter(|&a| match a { + let mut a: Vec = i.attrs.iter().filter(|&a| match a { &clean::NameValue(~"doc", _) => false, _ => true }).map(|x| x.clone()).collect(); @@ -269,7 +270,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { } pub fn unindent(s: &str) -> ~str { - let lines = s.lines_any().collect::<~[&str]>(); + let lines = s.lines_any().collect:: >(); let mut saw_first_line = false; let mut saw_second_line = false; let min_indent = lines.iter().fold(uint::MAX, |min_indent, line| { @@ -313,7 +314,7 @@ pub fn unindent(s: &str) -> ~str { }); if lines.len() >= 1 { - let mut unindented = ~[ lines[0].trim() ]; + let mut unindented = vec!( lines.get(0).trim() ); unindented.push_all(lines.tail().map(|&line| { if line.is_whitespace() { line diff --git a/src/librustdoc/plugins.rs b/src/librustdoc/plugins.rs index 2e7c4224ee186..66f12e83c62f1 100644 --- a/src/librustdoc/plugins.rs +++ b/src/librustdoc/plugins.rs @@ -12,6 +12,7 @@ use clean; use serialize::json; use dl = std::unstable::dynamic_lib; +use std::vec_ng::Vec; pub type PluginJson = Option<(~str, json::Json)>; pub type PluginResult = (clean::Crate, PluginJson); @@ -19,8 +20,8 @@ pub type PluginCallback = fn (clean::Crate) -> PluginResult; /// Manages loading and running of plugins pub struct PluginManager { - priv dylibs: ~[dl::DynamicLibrary], - priv callbacks: ~[PluginCallback], + priv dylibs: Vec , + priv callbacks: Vec , /// The directory plugins will be loaded from prefix: Path, } @@ -29,8 +30,8 @@ impl PluginManager { /// Create a new plugin manager pub fn new(prefix: Path) -> PluginManager { PluginManager { - dylibs: ~[], - callbacks: ~[], + dylibs: Vec::new(), + callbacks: Vec::new(), prefix: prefix, } } @@ -57,8 +58,8 @@ impl PluginManager { self.callbacks.push(plugin); } /// Run all the loaded plugins over the crate, returning their results - pub fn run_plugins(&self, krate: clean::Crate) -> (clean::Crate, ~[PluginJson]) { - let mut out_json = ~[]; + pub fn run_plugins(&self, krate: clean::Crate) -> (clean::Crate, Vec ) { + let mut out_json = Vec::new(); let mut krate = krate; for &callback in self.callbacks.iter() { let (c, res) = callback(krate); diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 45607a0992e23..79e8d6fd79b9c 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -15,6 +15,7 @@ use std::io::Process; use std::local_data; use std::os; use std::str; +use std::vec_ng::Vec; use collections::HashSet; use testing; @@ -35,7 +36,10 @@ use html::markdown; use passes; use visit_ast::RustdocVisitor; -pub fn run(input: &str, libs: @RefCell>, mut test_args: ~[~str]) -> int { +pub fn run(input: &str, + libs: @RefCell>, + mut test_args: Vec<~str>) + -> int { let input_path = Path::new(input); let input = driver::FileInput(input_path.clone()); @@ -77,13 +81,16 @@ pub fn run(input: &str, libs: @RefCell>, mut test_args: ~[~str]) - let (krate, _) = passes::unindent_comments(krate); let (krate, _) = passes::collapse_docs(krate); - let mut collector = Collector::new(krate.name.to_owned(), libs, false, false); + let mut collector = Collector::new(krate.name.to_owned(), + libs, + false, + false); collector.fold_crate(krate); test_args.unshift(~"rustdoctest"); - testing::test_main(test_args, collector.tests); - + testing::test_main(test_args.as_slice(), + collector.tests.move_iter().collect()); 0 } @@ -194,8 +201,8 @@ fn maketest(s: &str, cratename: &str, loose_feature_gating: bool) -> ~str { } pub struct Collector { - tests: ~[testing::TestDescAndFn], - priv names: ~[~str], + tests: Vec, + priv names: Vec<~str>, priv libs: @RefCell>, priv cnt: uint, priv use_headers: bool, @@ -209,8 +216,8 @@ impl Collector { pub fn new(cratename: ~str, libs: @RefCell>, use_headers: bool, loose_feature_gating: bool) -> Collector { Collector { - tests: ~[], - names: ~[], + tests: Vec::new(), + names: Vec::new(), libs: libs, cnt: 0, use_headers: use_headers, diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 5ac623af37a31..adb1a7bb6bd39 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -23,7 +23,7 @@ use doctree::*; pub struct RustdocVisitor<'a> { module: Module, - attrs: ~[ast::Attribute], + attrs: Vec , cx: &'a core::DocContext, analysis: Option<&'a core::CrateAnalysis>, } @@ -33,7 +33,7 @@ impl<'a> RustdocVisitor<'a> { analysis: Option<&'b core::CrateAnalysis>) -> RustdocVisitor<'b> { RustdocVisitor { module: Module::new(None), - attrs: ~[], + attrs: Vec::new(), cx: cx, analysis: analysis, } @@ -73,7 +73,7 @@ impl<'a> RustdocVisitor<'a> { pub fn visit_enum_def(&mut self, it: &ast::Item, def: &ast::EnumDef, params: &ast::Generics) -> Enum { debug!("Visiting enum"); - let mut vars: ~[Variant] = ~[]; + let mut vars: Vec = Vec::new(); for x in def.variants.iter() { vars.push(Variant { name: x.node.name, @@ -111,7 +111,7 @@ impl<'a> RustdocVisitor<'a> { } } - pub fn visit_mod_contents(&mut self, span: Span, attrs: ~[ast::Attribute], + pub fn visit_mod_contents(&mut self, span: Span, attrs: Vec , vis: ast::Visibility, id: ast::NodeId, m: &ast::Mod, name: Option) -> Module { diff --git a/src/libsemver/lib.rs b/src/libsemver/lib.rs index 700dc9867940a..77465a2fa45f1 100644 --- a/src/libsemver/lib.rs +++ b/src/libsemver/lib.rs @@ -34,6 +34,7 @@ #[license = "MIT/ASL2"]; use std::char; +use std::vec_ng::Vec; use std::cmp; use std::fmt; use std::fmt::Show; @@ -83,9 +84,9 @@ pub struct Version { /// fixes are made. patch: uint, /// The pre-release version identifier, if one exists. - pre: ~[Identifier], + pre: Vec , /// The build metadata, ignored when determining version precedence. - build: ~[Identifier], + build: Vec , } impl fmt::Show for Version { @@ -216,8 +217,8 @@ fn parse_iter>(rdr: &mut T) -> Option { None => return None }; - let mut pre = ~[]; - let mut build = ~[]; + let mut pre = Vec::new(); + let mut build = Vec::new(); let mut ch = ch; if ch == Some('-') { @@ -290,66 +291,66 @@ fn test_parse() { major: 1u, minor: 2u, patch: 3u, - pre: ~[], - build: ~[], + pre: Vec::new(), + build: Vec::new(), })); assert!(parse(" 1.2.3 ") == Some(Version { major: 1u, minor: 2u, patch: 3u, - pre: ~[], - build: ~[], + pre: Vec::new(), + build: Vec::new(), })); assert!(parse("1.2.3-alpha1") == Some(Version { major: 1u, minor: 2u, patch: 3u, - pre: ~[AlphaNumeric(~"alpha1")], - build: ~[] + pre: vec!(AlphaNumeric(~"alpha1")), + build: Vec::new() })); assert!(parse(" 1.2.3-alpha1 ") == Some(Version { major: 1u, minor: 2u, patch: 3u, - pre: ~[AlphaNumeric(~"alpha1")], - build: ~[] + pre: vec!(AlphaNumeric(~"alpha1")), + build: Vec::new() })); assert!(parse("1.2.3+build5") == Some(Version { major: 1u, minor: 2u, patch: 3u, - pre: ~[], - build: ~[AlphaNumeric(~"build5")] + pre: Vec::new(), + build: vec!(AlphaNumeric(~"build5")) })); assert!(parse(" 1.2.3+build5 ") == Some(Version { major: 1u, minor: 2u, patch: 3u, - pre: ~[], - build: ~[AlphaNumeric(~"build5")] + pre: Vec::new(), + build: vec!(AlphaNumeric(~"build5")) })); assert!(parse("1.2.3-alpha1+build5") == Some(Version { major: 1u, minor: 2u, patch: 3u, - pre: ~[AlphaNumeric(~"alpha1")], - build: ~[AlphaNumeric(~"build5")] + pre: vec!(AlphaNumeric(~"alpha1")), + build: vec!(AlphaNumeric(~"build5")) })); assert!(parse(" 1.2.3-alpha1+build5 ") == Some(Version { major: 1u, minor: 2u, patch: 3u, - pre: ~[AlphaNumeric(~"alpha1")], - build: ~[AlphaNumeric(~"build5")] + pre: vec!(AlphaNumeric(~"alpha1")), + build: vec!(AlphaNumeric(~"build5")) })); assert!(parse("1.2.3-1.alpha1.9+build5.7.3aedf ") == Some(Version { major: 1u, minor: 2u, patch: 3u, - pre: ~[Numeric(1),AlphaNumeric(~"alpha1"),Numeric(9)], - build: ~[AlphaNumeric(~"build5"), + pre: vec!(Numeric(1),AlphaNumeric(~"alpha1"),Numeric(9)), + build: vec!(AlphaNumeric(~"build5"), Numeric(7), - AlphaNumeric(~"3aedf")] + AlphaNumeric(~"3aedf")) })); } diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index 29b3dcaa4f29a..0678fc2cf5b8d 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -21,7 +21,7 @@ use rt::global_heap; use rt::local::Local; use rt::task::Task; use raw; -use vec::ImmutableVector; +use vec::{ImmutableVector, Vector}; use vec_ng::Vec; // This has no meaning with out rtdebug also turned on. diff --git a/src/libstd/rt/logging.rs b/src/libstd/rt/logging.rs index aa024a53b89ec..3b597ade00ffb 100644 --- a/src/libstd/rt/logging.rs +++ b/src/libstd/rt/logging.rs @@ -16,7 +16,7 @@ use option::{Some, None, Option}; use os; use rt::crate_map::{ModEntry, CrateMap, iter_crate_map, get_crate_map}; use str::{Str, StrSlice}; -use vec::{ImmutableVector, MutableTotalOrdVector, OwnedVector}; +use vec::{ImmutableVector, MutableTotalOrdVector, OwnedVector, Vector}; use vec_ng::Vec; struct LogDirective<'a> { diff --git a/src/libstd/str.rs b/src/libstd/str.rs index 3464c4a1128e3..9b597d0a2e9ce 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -101,6 +101,7 @@ use ptr::RawPtr; use from_str::FromStr; use vec; use vec::{OwnedVector, OwnedCloneableVector, ImmutableVector, MutableVector}; +use vec::{Vector}; use vec_ng::Vec; use default::Default; use raw::Repr; diff --git a/src/libstd/vec_ng.rs b/src/libstd/vec_ng.rs index 76fd68a526513..b6a6f0feb0436 100644 --- a/src/libstd/vec_ng.rs +++ b/src/libstd/vec_ng.rs @@ -12,8 +12,9 @@ #[doc(hidden)]; use cast::{forget, transmute}; +use cast; use clone::Clone; -use cmp::{Ord, Eq, Ordering, TotalEq, TotalOrd}; +use cmp::{Eq, Equiv, Ord, Ordering, TotalEq, TotalOrd}; use container::{Container, Mutable}; use default::Default; use fmt; @@ -30,7 +31,7 @@ use ptr; use rt::global_heap::{malloc_raw, realloc_raw}; use raw::Slice; use vec::{ImmutableEqVector, ImmutableVector, Items, MutItems, MutableVector}; -use vec::{RevItems}; +use vec::{RevItems, Vector}; pub struct Vec { priv len: uint, @@ -184,6 +185,13 @@ impl TotalOrd for Vec { } } +impl<'a,T:Eq,V:Vector> Equiv for Vec { + #[inline] + fn equiv(&self, other: &V) -> bool { + self.as_slice() == other.as_slice() + } +} + impl Container for Vec { #[inline] fn len(&self) -> uint { @@ -280,12 +288,6 @@ impl Vec { self.len = len; } - #[inline] - pub fn as_slice<'a>(&'a self) -> &'a [T] { - let slice = Slice { data: self.ptr as *T, len: self.len }; - unsafe { transmute(slice) } - } - #[inline] pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] { let slice = Slice { data: self.ptr as *T, len: self.len }; @@ -362,6 +364,11 @@ impl Vec { self.as_mut_slice().mut_last() } + #[inline] + pub fn swap(&mut self, a: uint, b: uint) { + self.as_mut_slice().swap(a, b) + } + #[inline] pub fn swap_remove(&mut self, index: uint) -> Option { let length = self.len(); @@ -447,6 +454,48 @@ impl Vec { pub fn as_ptr(&self) -> *T { self.as_slice().as_ptr() } + + pub fn remove(&mut self, i: uint) -> Option { + let len = self.len(); + if i < len { + unsafe { // infallible + // the place we are taking from. + let ptr = self.as_mut_slice().as_mut_ptr().offset(i as int); + // copy it out, unsafely having a copy of the value on + // the stack and in the vector at the same time. + let ret = Some(ptr::read(ptr as *T)); + + // Shift everything down to fill in that spot. + ptr::copy_memory(ptr, &*ptr.offset(1), len - i - 1); + self.set_len(len - 1); + + ret + } + } else { + None + } + } + + #[inline] + pub fn shift(&mut self) -> Option { + self.remove(0) + } + + #[inline] + pub fn partition(self, f: |&T| -> bool) -> (Vec, Vec) { + let mut lefts = Vec::new(); + let mut rights = Vec::new(); + + for elt in self.move_iter() { + if f(&elt) { + lefts.push(elt); + } else { + rights.push(elt); + } + } + + (lefts, rights) + } } impl Mutable for Vec { @@ -457,6 +506,17 @@ impl Mutable for Vec { } } +impl Vector for Vec { + /// Work with `self` as a slice. + #[inline] + fn as_slice<'a>(&'a self) -> &'a [T] { + let slice = Slice { data: self.ptr as *T, len: self.len }; + unsafe { + cast::transmute(slice) + } + } +} + impl Vec { /// Return true if a vector contains an element with the given value pub fn contains(&self, x: &T) -> bool { diff --git a/src/libsync/arc.rs b/src/libsync/arc.rs index 17a35f331705d..000540c0acd1b 100644 --- a/src/libsync/arc.rs +++ b/src/libsync/arc.rs @@ -572,25 +572,26 @@ mod tests { use super::{Arc, RWArc, MutexArc, CowArc}; use std::task; + use std::vec_ng::Vec; #[test] fn manually_share_arc() { - let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); let (p, c) = Chan::new(); task::spawn(proc() { - let arc_v: Arc<~[int]> = p.recv(); + let arc_v: Arc > = p.recv(); let v = arc_v.get().clone(); - assert_eq!(v[3], 4); + assert_eq!(*v.get(3), 4); }); c.send(arc_v.clone()); - assert_eq!(arc_v.get()[2], 3); - assert_eq!(arc_v.get()[4], 5); + assert_eq!(*arc_v.get().get(2), 3); + assert_eq!(*arc_v.get().get(4), 5); info!("{:?}", arc_v); } @@ -792,7 +793,7 @@ mod tests { }); // Readers try to catch the writer in the act - let mut children = ~[]; + let mut children = Vec::new(); for _ in range(0, 5) { let arc3 = arc.clone(); let mut builder = task::task(); @@ -846,7 +847,7 @@ mod tests { let arc = RWArc::new(0); // Reader tasks - let mut reader_convos = ~[]; + let mut reader_convos = Vec::new(); for _ in range(0, 10) { let ((rp1, rc1), (rp2, rc2)) = (Chan::new(), Chan::new()); reader_convos.push((rc1, rp2)); diff --git a/src/libsync/sync/mod.rs b/src/libsync/sync/mod.rs index 34ec4ca28cfaf..fb91a1d692299 100644 --- a/src/libsync/sync/mod.rs +++ b/src/libsync/sync/mod.rs @@ -24,6 +24,7 @@ use std::mem::replace; use std::sync::arc::UnsafeArc; use std::sync::atomics; use std::unstable::finally::Finally; +use std::vec_ng::Vec; use arc::MutexArc; @@ -161,10 +162,10 @@ impl Sem { } #[doc(hidden)] -impl Sem<~[WaitQueue]> { +impl Sem > { fn new_and_signal(count: int, num_condvars: uint) - -> Sem<~[WaitQueue]> { - let mut queues = ~[]; + -> Sem > { + let mut queues = Vec::new(); for _ in range(0, num_condvars) { queues.push(WaitQueue::new()); } Sem::new(count, queues) } @@ -182,7 +183,7 @@ enum ReacquireOrderLock<'a> { pub struct Condvar<'a> { // The 'Sem' object associated with this condvar. This is the one that's // atomically-unlocked-and-descheduled upon and reacquired during wakeup. - priv sem: &'a Sem<~[WaitQueue]>, + priv sem: &'a Sem >, // This is (can be) an extra semaphore which is held around the reacquire // operation on the first one. This is only used in cvars associated with // rwlocks, and is needed to ensure that, when a downgrader is trying to @@ -230,7 +231,7 @@ impl<'a> Condvar<'a> { } // Create waiter nobe, and enqueue ourself to // be woken up by a signaller. - wait_end = Some(state.blocked[condvar_id].wait_end()); + wait_end = Some(state.blocked.get(condvar_id).wait_end()); } else { out_of_bounds = Some(state.blocked.len()); } @@ -265,7 +266,7 @@ impl<'a> Condvar<'a> { let mut result = false; self.sem.with(|state| { if condvar_id < state.blocked.len() { - result = state.blocked[condvar_id].signal(); + result = state.blocked.get(condvar_id).signal(); } else { out_of_bounds = Some(state.blocked.len()); } @@ -290,7 +291,7 @@ impl<'a> Condvar<'a> { // To avoid :broadcast_heavy, we make a new waitqueue, // swap it out with the old one, and broadcast on the // old one outside of the little-lock. - queue = Some(replace(&mut state.blocked[condvar_id], + queue = Some(replace(state.blocked.get_mut(condvar_id), WaitQueue::new())); } else { out_of_bounds = Some(state.blocked.len()); @@ -326,7 +327,7 @@ fn check_cvar_bounds( } #[doc(hidden)] -impl Sem<~[WaitQueue]> { +impl Sem > { // The only other places that condvars get built are rwlock.write_cond() // and rwlock_write_mode. pub fn access_cond(&self, blk: |c: &Condvar| -> U) -> U { @@ -391,7 +392,7 @@ impl Semaphore { * unwinds. */ -pub struct Mutex { priv sem: Sem<~[WaitQueue]> } +pub struct Mutex { priv sem: Sem > } impl Clone for Mutex { /// Create a new handle to the mutex. fn clone(&self) -> Mutex { @@ -461,7 +462,7 @@ struct RWLockInner { */ pub struct RWLock { priv order_lock: Semaphore, - priv access_lock: Sem<~[WaitQueue]>, + priv access_lock: Sem >, priv state: UnsafeArc, } @@ -765,6 +766,7 @@ mod tests { use std::result; use std::task; use std::comm::Empty; + use std::vec_ng::Vec; /************************************************************************ * Semaphore tests @@ -931,7 +933,7 @@ mod tests { #[cfg(test)] fn test_mutex_cond_broadcast_helper(num_waiters: uint) { let m = Mutex::new(); - let mut ports = ~[]; + let mut ports = Vec::new(); for _ in range(0, num_waiters) { let mi = m.clone(); @@ -1031,7 +1033,7 @@ mod tests { let (p, c) = Chan::new(); let result: result::Result<(), ~Any> = task::try(proc() { - let mut sibling_convos = ~[]; + let mut sibling_convos = Vec::new(); for _ in range(0, 2) { let (p, c) = Chan::new(); sibling_convos.push(p); @@ -1297,7 +1299,7 @@ mod tests { } } let x = RWLock::new(); - let mut ports = ~[]; + let mut ports = Vec::new(); for _ in range(0, num_waiters) { let xi = x.clone(); diff --git a/src/libsync/task_pool.rs b/src/libsync/task_pool.rs index 0d8cccfe2b9ae..ed7d6cb6e8357 100644 --- a/src/libsync/task_pool.rs +++ b/src/libsync/task_pool.rs @@ -15,7 +15,7 @@ use std::task; -use std::vec; +use std::vec_ng::Vec; enum Msg { Execute(proc(&T)), @@ -23,7 +23,7 @@ enum Msg { } pub struct TaskPool { - priv channels: ~[Chan>], + priv channels: Vec>> , priv next_index: uint, } @@ -47,7 +47,7 @@ impl TaskPool { -> TaskPool { assert!(n_tasks >= 1); - let channels = vec::from_fn(n_tasks, |i| { + let channels = Vec::from_fn(n_tasks, |i| { let (port, chan) = Chan::>::new(); let init_fn = init_fn_factory(); @@ -67,13 +67,16 @@ impl TaskPool { chan }); - return TaskPool { channels: channels, next_index: 0 }; + return TaskPool { + channels: channels, + next_index: 0, + }; } /// Executes the function `f` on a task in the pool. The function /// receives a reference to the local data returned by the `init_fn`. pub fn execute(&mut self, f: proc(&T)) { - self.channels[self.next_index].send(Execute(f)); + self.channels.get(self.next_index).send(Execute(f)); self.next_index += 1; if self.next_index == self.channels.len() { self.next_index = 0; } } diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 903fede5faa8e..b62b252e67b5f 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -25,8 +25,8 @@ extern crate collections; -use std::os; use std::io; +use std::os; use terminfo::TermInfo; use terminfo::searcher::open; use terminfo::parser::compiled::{parse, msys_terminfo}; @@ -150,10 +150,14 @@ impl Terminal { pub fn fg(&mut self, color: color::Color) -> io::IoResult { let color = self.dim_if_necessary(color); if self.num_colors > color { - let s = expand(*self.ti.strings.find_equiv(&("setaf")).unwrap(), + let s = expand(self.ti + .strings + .find_equiv(&("setaf")) + .unwrap() + .as_slice(), [Number(color as int)], &mut Variables::new()); if s.is_ok() { - try!(self.out.write(s.unwrap())); + try!(self.out.write(s.unwrap().as_slice())); return Ok(true) } else { warn!("{}", s.unwrap_err()); @@ -171,10 +175,14 @@ impl Terminal { pub fn bg(&mut self, color: color::Color) -> io::IoResult { let color = self.dim_if_necessary(color); if self.num_colors > color { - let s = expand(*self.ti.strings.find_equiv(&("setab")).unwrap(), + let s = expand(self.ti + .strings + .find_equiv(&("setab")) + .unwrap() + .as_slice(), [Number(color as int)], &mut Variables::new()); if s.is_ok() { - try!(self.out.write(s.unwrap())); + try!(self.out.write(s.unwrap().as_slice())); return Ok(true) } else { warn!("{}", s.unwrap_err()); @@ -194,9 +202,11 @@ impl Terminal { let cap = cap_for_attr(attr); let parm = self.ti.strings.find_equiv(&cap); if parm.is_some() { - let s = expand(*parm.unwrap(), [], &mut Variables::new()); + let s = expand(parm.unwrap().as_slice(), + [], + &mut Variables::new()); if s.is_ok() { - try!(self.out.write(s.unwrap())); + try!(self.out.write(s.unwrap().as_slice())); return Ok(true) } else { warn!("{}", s.unwrap_err()); @@ -232,10 +242,10 @@ impl Terminal { } } let s = cap.map_or(Err(~"can't find terminfo capability `sgr0`"), |op| { - expand(*op, [], &mut Variables::new()) + expand(op.as_slice(), [], &mut Variables::new()) }); if s.is_ok() { - return self.out.write(s.unwrap()) + return self.out.write(s.unwrap().as_slice()) } else if self.num_colors > 0 { warn!("{}", s.unwrap_err()); } else { diff --git a/src/libterm/terminfo/mod.rs b/src/libterm/terminfo/mod.rs index de8a1dcc363c7..575057c31f09a 100644 --- a/src/libterm/terminfo/mod.rs +++ b/src/libterm/terminfo/mod.rs @@ -11,17 +11,18 @@ #[allow(missing_doc)]; use collections::HashMap; +use std::vec_ng::Vec; /// A parsed terminfo entry. pub struct TermInfo { /// Names for the terminal - priv names: ~[~str], + priv names: Vec<~str> , /// Map of capability name to boolean value priv bools: HashMap<~str, bool>, /// Map of capability name to numeric value numbers: HashMap<~str, u16>, /// Map of capability name to raw (unexpanded) string - strings: HashMap<~str, ~[u8]> + strings: HashMap<~str, Vec > } pub mod searcher; diff --git a/src/libterm/terminfo/parm.rs b/src/libterm/terminfo/parm.rs index dfb6d6b1a8825..5e8bc82e031b9 100644 --- a/src/libterm/terminfo/parm.rs +++ b/src/libterm/terminfo/parm.rs @@ -10,8 +10,9 @@ //! Parameterized string expansion -use std::{char, vec}; +use std::char; use std::mem::replace; +use std::vec_ng::Vec; #[deriving(Eq)] enum States { @@ -89,13 +90,13 @@ impl Variables { multiple capabilities for the same terminal. */ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) - -> Result<~[u8], ~str> { + -> Result , ~str> { let mut state = Nothing; // expanded cap will only rarely be larger than the cap itself - let mut output = vec::with_capacity(cap.len()); + let mut output = Vec::with_capacity(cap.len()); - let mut stack: ~[Param] = ~[]; + let mut stack: Vec = Vec::new(); // Copy parameters into a local vector for mutability let mut mparams = [ @@ -248,7 +249,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) let flags = Flags::new(); let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), flags); if res.is_err() { return res } - output.push_all(res.unwrap()) + output.push_all(res.unwrap().as_slice()) } else { return Err(~"stack is empty") }, ':'|'#'|' '|'.'|'0'..'9' => { let mut flags = Flags::new(); @@ -343,7 +344,7 @@ pub fn expand(cap: &[u8], params: &[Param], vars: &mut Variables) (_,'d')|(_,'o')|(_,'x')|(_,'X')|(_,'s') => if stack.len() > 0 { let res = format(stack.pop().unwrap(), FormatOp::from_char(cur), *flags); if res.is_err() { return res } - output.push_all(res.unwrap()); + output.push_all(res.unwrap().as_slice()); old_state = state; // will cause state to go to Nothing } else { return Err(~"stack is empty") }, (FormatStateFlags,'#') => { @@ -476,10 +477,10 @@ impl FormatOp { } } -fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> { +fn format(val: Param, op: FormatOp, flags: Flags) -> Result ,~str> { let mut s = match val { Number(d) => { - let mut s = match (op, flags.sign) { + let s = match (op, flags.sign) { (FormatDigit, true) => format!("{:+d}", d).into_bytes(), (FormatDigit, false) => format!("{:d}", d).into_bytes(), (FormatOctal, _) => format!("{:o}", d).into_bytes(), @@ -487,8 +488,9 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> { (FormatHEX, _) => format!("{:X}", d).into_bytes(), (FormatString, _) => return Err(~"non-number on stack with %s"), }; + let mut s: Vec = s.move_iter().collect(); if flags.precision > s.len() { - let mut s_ = vec::with_capacity(flags.precision); + let mut s_ = Vec::with_capacity(flags.precision); let n = flags.precision - s.len(); s_.grow(n, &('0' as u8)); s_.push_all_move(s); @@ -497,25 +499,31 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> { assert!(!s.is_empty(), "string conversion produced empty result"); match op { FormatDigit => { - if flags.space && !(s[0] == '-' as u8 || s[0] == '+' as u8) { + if flags.space && !(*s.get(0) == '-' as u8 || + *s.get(0) == '+' as u8) { s.unshift(' ' as u8); } } FormatOctal => { - if flags.alternate && s[0] != '0' as u8 { + if flags.alternate && *s.get(0) != '0' as u8 { s.unshift('0' as u8); } } FormatHex => { if flags.alternate { - let s_ = replace(&mut s, ~['0' as u8, 'x' as u8]); + let s_ = replace(&mut s, vec!('0' as u8, 'x' as u8)); s.push_all_move(s_); } } FormatHEX => { - s = s.into_ascii().to_upper().into_bytes(); + s = s.as_slice() + .to_ascii() + .to_upper() + .into_bytes() + .move_iter() + .collect(); if flags.alternate { - let s_ = replace(&mut s, ~['0' as u8, 'X' as u8]); + let s_ = replace(&mut s, vec!('0' as u8, 'X' as u8)); s.push_all_move(s_); } } @@ -526,7 +534,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> { String(s) => { match op { FormatString => { - let mut s = s.as_bytes().to_owned(); + let mut s = Vec::from_slice(s.as_bytes()); if flags.precision > 0 && flags.precision < s.len() { s.truncate(flags.precision); } @@ -543,7 +551,7 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> { if flags.left { s.grow(n, &(' ' as u8)); } else { - let mut s_ = vec::with_capacity(flags.width); + let mut s_ = Vec::with_capacity(flags.width); s_.grow(n, &(' ' as u8)); s_.push_all_move(s); s = s_; @@ -556,18 +564,19 @@ fn format(val: Param, op: FormatOp, flags: Flags) -> Result<~[u8],~str> { mod test { use super::{expand,String,Variables,Number}; use std::result::Ok; + use std::vec_ng; #[test] fn test_basic_setabf() { let s = bytes!("\\E[48;5;%p1%dm"); assert_eq!(expand(s, [Number(1)], &mut Variables::new()).unwrap(), - bytes!("\\E[48;5;1m").to_owned()); + bytes!("\\E[48;5;1m").iter().map(|x| *x).collect()); } #[test] fn test_multiple_int_constants() { assert_eq!(expand(bytes!("%{1}%{2}%d%d"), [], &mut Variables::new()).unwrap(), - bytes!("21").to_owned()); + bytes!("21").iter().map(|x| *x).collect()); } #[test] @@ -575,9 +584,9 @@ mod test { let mut vars = Variables::new(); assert_eq!(expand(bytes!("%p1%d%p2%d%p3%d%i%p1%d%p2%d%p3%d"), [Number(1),Number(2),Number(3)], &mut vars), - Ok(bytes!("123233").to_owned())); + Ok(bytes!("123233").iter().map(|x| *x).collect())); assert_eq!(expand(bytes!("%p1%d%p2%d%i%p1%d%p2%d"), [], &mut vars), - Ok(bytes!("0011").to_owned())); + Ok(bytes!("0011").iter().map(|x| *x).collect())); } #[test] @@ -590,7 +599,12 @@ mod test { assert!(res.is_err(), "Op {} succeeded incorrectly with 0 stack entries", *cap); let p = if *cap == "%s" || *cap == "%l" { String(~"foo") } else { Number(97) }; - let res = expand((bytes!("%p1")).to_owned() + cap.as_bytes(), [p], vars); + let res = expand(vec_ng::append(bytes!("%p1").iter() + .map(|x| *x) + .collect(), + cap.as_bytes()).as_slice(), + [p], + vars); assert!(res.is_ok(), "Op {} failed with 1 stack entry: {}", *cap, res.unwrap_err()); } @@ -599,10 +613,20 @@ mod test { let res = expand(cap.as_bytes(), [], vars); assert!(res.is_err(), "Binop {} succeeded incorrectly with 0 stack entries", *cap); - let res = expand((bytes!("%{1}")).to_owned() + cap.as_bytes(), [], vars); + let res = expand(vec_ng::append(bytes!("%{1}").iter() + .map(|x| *x) + .collect(), + cap.as_bytes()).as_slice(), + [], + vars); assert!(res.is_err(), "Binop {} succeeded incorrectly with 1 stack entry", *cap); - let res = expand((bytes!("%{1}%{2}")).to_owned() + cap.as_bytes(), [], vars); + let res = expand(vec_ng::append(bytes!("%{1}%{2}").iter() + .map(|x| *x) + .collect(), + cap.as_bytes()).as_slice(), + [], + vars); assert!(res.is_ok(), "Binop {} failed with 2 stack entries: {}", *cap, res.unwrap_err()); } @@ -620,15 +644,15 @@ mod test { let s = format!("%\\{1\\}%\\{2\\}%{}%d", op); let res = expand(s.as_bytes(), [], &mut Variables::new()); assert!(res.is_ok(), res.unwrap_err()); - assert_eq!(res.unwrap(), ~['0' as u8 + bs[0]]); + assert_eq!(res.unwrap(), vec!('0' as u8 + bs[0])); let s = format!("%\\{1\\}%\\{1\\}%{}%d", op); let res = expand(s.as_bytes(), [], &mut Variables::new()); assert!(res.is_ok(), res.unwrap_err()); - assert_eq!(res.unwrap(), ~['0' as u8 + bs[1]]); + assert_eq!(res.unwrap(), vec!('0' as u8 + bs[1])); let s = format!("%\\{2\\}%\\{1\\}%{}%d", op); let res = expand(s.as_bytes(), [], &mut Variables::new()); assert!(res.is_ok(), res.unwrap_err()); - assert_eq!(res.unwrap(), ~['0' as u8 + bs[2]]); + assert_eq!(res.unwrap(), vec!('0' as u8 + bs[2])); } } @@ -638,13 +662,16 @@ mod test { let s = bytes!("\\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m"); let res = expand(s, [Number(1)], &mut vars); assert!(res.is_ok(), res.unwrap_err()); - assert_eq!(res.unwrap(), bytes!("\\E[31m").to_owned()); + assert_eq!(res.unwrap(), + bytes!("\\E[31m").iter().map(|x| *x).collect()); let res = expand(s, [Number(8)], &mut vars); assert!(res.is_ok(), res.unwrap_err()); - assert_eq!(res.unwrap(), bytes!("\\E[90m").to_owned()); + assert_eq!(res.unwrap(), + bytes!("\\E[90m").iter().map(|x| *x).collect()); let res = expand(s, [Number(42)], &mut vars); assert!(res.is_ok(), res.unwrap_err()); - assert_eq!(res.unwrap(), bytes!("\\E[38;5;42m").to_owned()); + assert_eq!(res.unwrap(), + bytes!("\\E[38;5;42m").iter().map(|x| *x).collect()); } #[test] @@ -653,13 +680,15 @@ mod test { let vars = &mut varstruct; assert_eq!(expand(bytes!("%p1%s%p2%2s%p3%2s%p4%.2s"), [String(~"foo"), String(~"foo"), String(~"f"), String(~"foo")], vars), - Ok(bytes!("foofoo ffo").to_owned())); + Ok(bytes!("foofoo ffo").iter().map(|x| *x).collect())); assert_eq!(expand(bytes!("%p1%:-4.2s"), [String(~"foo")], vars), - Ok(bytes!("fo ").to_owned())); + Ok(bytes!("fo ").iter().map(|x| *x).collect())); assert_eq!(expand(bytes!("%p1%d%p1%.3d%p1%5d%p1%:+d"), [Number(1)], vars), - Ok(bytes!("1001 1+1").to_owned())); + Ok(bytes!("1001 1+1").iter().map(|x| *x).collect())); assert_eq!(expand(bytes!("%p1%o%p1%#o%p2%6.4x%p2%#6.4X"), [Number(15), Number(27)], vars), - Ok(bytes!("17017 001b0X001B").to_owned())); + Ok(bytes!("17017 001b0X001B").iter() + .map(|x| *x) + .collect())); } } diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index e9d71d1c2f7a3..95e830b9b1f3d 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -12,10 +12,10 @@ /// ncurses-compatible compiled terminfo format parsing (term(5)) - -use std::{vec, str}; -use std::io; use collections::HashMap; +use std::io; +use std::{vec, str}; +use std::vec_ng::Vec; use super::super::TermInfo; // These are the orders ncurses uses in its compiled format (as of 5.9). Not sure if portable. @@ -225,7 +225,7 @@ pub fn parse(file: &mut io::Reader, Some(s) => s, None => return Err(~"input not utf-8"), }; - let term_names: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect(); + let term_names: Vec<~str> = names_str.split('|').map(|s| s.to_owned()).collect(); try!(file.read_byte()); // consume NUL @@ -298,7 +298,7 @@ pub fn parse(file: &mut io::Reader, if offset == 0xFFFE { // undocumented: FFFE indicates cap@, which means the capability is not present // unsure if the handling for this is correct - string_map.insert(name.to_owned(), ~[]); + string_map.insert(name.to_owned(), Vec::new()); continue; } @@ -309,8 +309,9 @@ pub fn parse(file: &mut io::Reader, match nulpos { Some(len) => { string_map.insert(name.to_owned(), - string_table.slice(offset as uint, - offset as uint + len).to_owned()) + Vec::from_slice( + string_table.slice(offset as uint, + offset as uint + len))) }, None => { return Err(~"invalid file: missing NUL in string_table"); @@ -326,12 +327,12 @@ pub fn parse(file: &mut io::Reader, /// Create a dummy TermInfo struct for msys terminals pub fn msys_terminfo() -> ~TermInfo { let mut strings = HashMap::new(); - strings.insert(~"sgr0", bytes!("\x1b[0m").to_owned()); - strings.insert(~"bold", bytes!("\x1b[1m").to_owned()); - strings.insert(~"setaf", bytes!("\x1b[3%p1%dm").to_owned()); - strings.insert(~"setab", bytes!("\x1b[4%p1%dm").to_owned()); + strings.insert(~"sgr0", Vec::from_slice(bytes!("\x1b[0m"))); + strings.insert(~"bold", Vec::from_slice(bytes!("\x1b[1m"))); + strings.insert(~"setaf", Vec::from_slice(bytes!("\x1b[3%p1%dm"))); + strings.insert(~"setab", Vec::from_slice(bytes!("\x1b[4%p1%dm"))); ~TermInfo { - names: ~[~"cygwin"], // msys is a fork of an older cygwin version + names: vec!(~"cygwin"), // msys is a fork of an older cygwin version bools: HashMap::new(), numbers: HashMap::new(), strings: strings diff --git a/src/libterm/terminfo/searcher.rs b/src/libterm/terminfo/searcher.rs index ef522da5e8c5f..14bbab09e09d0 100644 --- a/src/libterm/terminfo/searcher.rs +++ b/src/libterm/terminfo/searcher.rs @@ -13,6 +13,7 @@ use std::io::File; use std::os::getenv; +use std::vec_ng::Vec; use std::{os, str}; /// Return path to database entry for `term` @@ -23,7 +24,7 @@ pub fn get_dbpath_for_term(term: &str) -> Option<~Path> { let homedir = os::homedir(); - let mut dirs_to_search = ~[]; + let mut dirs_to_search = Vec::new(); let first_char = term.char_at(0); // Find search directory diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 9ebd7d72c9188..fbfca851ad9d7 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -49,6 +49,7 @@ use term::Terminal; use term::color::{Color, RED, YELLOW, GREEN, CYAN}; use std::cmp; +use std::vec_ng::Vec; use std::f64; use std::fmt; use std::from_str::FromStr; @@ -199,7 +200,7 @@ pub type MetricDiff = TreeMap<~str,MetricChange>; // The default console test runner. It accepts the command line // arguments and a vector of test_descs. -pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) { +pub fn test_main(args: &[~str], tests: Vec ) { let opts = match parse_opts(args) { Some(Ok(o)) => o, @@ -221,7 +222,7 @@ pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) { // semantics into parallel test runners, which in turn requires a ~[] // rather than a &[]. pub fn test_main_static(args: &[~str], tests: &[TestDescAndFn]) { - let owned_tests = tests.map(|t| { + let owned_tests = tests.iter().map(|t| { match t.testfn { StaticTestFn(f) => TestDescAndFn { testfn: StaticTestFn(f), desc: t.desc.clone() }, @@ -233,7 +234,7 @@ pub fn test_main_static(args: &[~str], tests: &[TestDescAndFn]) { fail!("non-static tests passed to test::test_main_static"); } } - }); + }).collect(); test_main(args, owned_tests) } @@ -252,8 +253,8 @@ pub struct TestOpts { /// Result of parsing the options. pub type OptRes = Result; -fn optgroups() -> ~[getopts::OptGroup] { - ~[getopts::optflag("", "ignored", "Run ignored tests"), +fn optgroups() -> Vec { + vec!(getopts::optflag("", "ignored", "Run ignored tests"), getopts::optflag("", "test", "Run tests and not benchmarks"), getopts::optflag("", "bench", "Run benchmarks instead of tests"), getopts::optflag("h", "help", "Display this message (longer with --help)"), @@ -269,12 +270,12 @@ fn optgroups() -> ~[getopts::OptGroup] { getopts::optopt("", "logfile", "Write logs to the specified file instead \ of stdout", "PATH"), getopts::optopt("", "test-shard", "run shard A, of B shards, worth of the testsuite", - "A.B")] + "A.B")) } fn usage(binary: &str, helpstr: &str) { let message = format!("Usage: {} [OPTIONS] [FILTER]", binary); - println!("{}", getopts::usage(message, optgroups())); + println!("{}", getopts::usage(message, optgroups().as_slice())); println!(""); if helpstr == "help" { println!("{}", "\ @@ -304,7 +305,7 @@ Test Attributes: pub fn parse_opts(args: &[~str]) -> Option { let args_ = args.tail(); let matches = - match getopts::getopts(args_, optgroups()) { + match getopts::getopts(args_, optgroups().as_slice()) { Ok(m) => m, Err(f) => return Some(Err(f.to_err_msg())) }; @@ -314,7 +315,7 @@ pub fn parse_opts(args: &[~str]) -> Option { let filter = if matches.free.len() > 0 { - Some((matches).free[0].clone()) + Some((*matches.free.get(0)).clone()) } else { None }; @@ -404,7 +405,7 @@ struct ConsoleTestState { ignored: uint, measured: uint, metrics: MetricMap, - failures: ~[(TestDesc, ~[u8])], + failures: Vec<(TestDesc, Vec )> , max_name_len: uint, // number of columns to fill when aligning names } @@ -429,7 +430,7 @@ impl ConsoleTestState { ignored: 0u, measured: 0u, metrics: MetricMap::new(), - failures: ~[], + failures: Vec::new(), max_name_len: 0u, }) } @@ -543,14 +544,14 @@ impl ConsoleTestState { pub fn write_failures(&mut self) -> io::IoResult<()> { try!(self.write_plain("\nfailures:\n")); - let mut failures = ~[]; + let mut failures = Vec::new(); let mut fail_out = ~""; for &(ref f, ref stdout) in self.failures.iter() { failures.push(f.name.to_str()); if stdout.len() > 0 { fail_out.push_str(format!("---- {} stdout ----\n\t", f.name.to_str())); - let output = str::from_utf8_lossy(*stdout); + let output = str::from_utf8_lossy(stdout.as_slice()); fail_out.push_str(output.as_slice().replace("\n", "\n\t")); fail_out.push_str("\n"); } @@ -561,7 +562,7 @@ impl ConsoleTestState { } try!(self.write_plain("\nfailures:\n")); - failures.sort(); + failures.as_mut_slice().sort(); for name in failures.iter() { try!(self.write_plain(format!(" {}\n", name.to_str()))); } @@ -661,7 +662,7 @@ impl ConsoleTestState { pub fn fmt_metrics(mm: &MetricMap) -> ~str { let MetricMap(ref mm) = *mm; - let v : ~[~str] = mm.iter() + let v : Vec<~str> = mm.iter() .map(|(k,v)| format!("{}: {} (+/- {})", *k, v.value as f64, @@ -685,7 +686,7 @@ pub fn fmt_bench_samples(bs: &BenchSamples) -> ~str { // A simple console test runner pub fn run_tests_console(opts: &TestOpts, - tests: ~[TestDescAndFn]) -> io::IoResult { + tests: Vec ) -> io::IoResult { fn callback(event: &TestEvent, st: &mut ConsoleTestState) -> io::IoResult<()> { debug!("callback(event={:?})", event); @@ -777,7 +778,7 @@ fn should_sort_failures_before_printing_them() { measured: 0u, max_name_len: 10u, metrics: MetricMap::new(), - failures: ~[(test_b, ~[]), (test_a, ~[])] + failures: vec!((test_b, Vec::new()), (test_a, Vec::new())) }; st.write_failures().unwrap(); @@ -795,18 +796,20 @@ fn use_color() -> bool { return get_concurrency() == 1; } #[deriving(Clone)] enum TestEvent { - TeFiltered(~[TestDesc]), + TeFiltered(Vec ), TeWait(TestDesc, NamePadding), - TeResult(TestDesc, TestResult, ~[u8] /* stdout */), + TeResult(TestDesc, TestResult, Vec ), } -pub type MonitorMsg = (TestDesc, TestResult, ~[u8] /* stdout */); +pub type MonitorMsg = (TestDesc, TestResult, Vec ); fn run_tests(opts: &TestOpts, - tests: ~[TestDescAndFn], + tests: Vec , callback: |e: TestEvent| -> io::IoResult<()>) -> io::IoResult<()> { let filtered_tests = filter_tests(opts, tests); - let filtered_descs = filtered_tests.map(|t| t.desc.clone()); + let filtered_descs = filtered_tests.iter() + .map(|t| t.desc.clone()) + .collect(); try!(callback(TeFiltered(filtered_descs))); @@ -879,8 +882,7 @@ fn get_concurrency() -> uint { pub fn filter_tests( opts: &TestOpts, - tests: ~[TestDescAndFn]) -> ~[TestDescAndFn] -{ + tests: Vec ) -> Vec { let mut filtered = tests; // Remove tests that don't match the test filter @@ -928,11 +930,12 @@ pub fn filter_tests( // Shard the remaining tests, if sharding requested. match opts.test_shard { None => filtered, - Some((a,b)) => + Some((a,b)) => { filtered.move_iter().enumerate() .filter(|&(i,_)| i % b == a) .map(|(_,t)| t) - .to_owned_vec() + .collect() + } } } @@ -943,7 +946,7 @@ pub fn run_test(force_ignore: bool, let TestDescAndFn {desc, testfn} = test; if force_ignore || desc.ignore { - monitor_ch.send((desc, TrIgnored, ~[])); + monitor_ch.send((desc, TrIgnored, Vec::new())); return; } @@ -964,7 +967,7 @@ pub fn run_test(force_ignore: bool, let result_future = task.future_result(); task.spawn(testfn); - let stdout = reader.read_to_end().unwrap(); + let stdout = reader.read_to_end().unwrap().move_iter().collect(); let task_result = result_future.recv(); let test_result = calc_result(&desc, task_result.is_ok()); monitor_ch.send((desc.clone(), test_result, stdout)); @@ -974,24 +977,24 @@ pub fn run_test(force_ignore: bool, match testfn { DynBenchFn(bencher) => { let bs = ::bench::benchmark(|harness| bencher.run(harness)); - monitor_ch.send((desc, TrBench(bs), ~[])); + monitor_ch.send((desc, TrBench(bs), Vec::new())); return; } StaticBenchFn(benchfn) => { let bs = ::bench::benchmark(|harness| benchfn(harness)); - monitor_ch.send((desc, TrBench(bs), ~[])); + monitor_ch.send((desc, TrBench(bs), Vec::new())); return; } DynMetricFn(f) => { let mut mm = MetricMap::new(); f(&mut mm); - monitor_ch.send((desc, TrMetrics(mm), ~[])); + monitor_ch.send((desc, TrMetrics(mm), Vec::new())); return; } StaticMetricFn(f) => { let mut mm = MetricMap::new(); f(&mut mm); - monitor_ch.send((desc, TrMetrics(mm), ~[])); + monitor_ch.send((desc, TrMetrics(mm), Vec::new())); return; } DynTestFn(f) => run_test_inner(desc, monitor_ch, f), @@ -1309,6 +1312,7 @@ mod tests { Improvement, Regression, LikelyNoise, StaticTestName, DynTestName, DynTestFn}; use extra::tempfile::TempDir; + use std::vec_ng::Vec; #[test] pub fn do_not_run_ignored_tests() { @@ -1380,8 +1384,8 @@ mod tests { #[test] fn first_free_arg_should_be_a_filter() { - let args = ~[~"progname", ~"filter"]; - let opts = match parse_opts(args) { + let args = vec!(~"progname", ~"filter"); + let opts = match parse_opts(args.as_slice()) { Some(Ok(o)) => o, _ => fail!("Malformed arg in first_free_arg_should_be_a_filter") }; @@ -1390,8 +1394,8 @@ mod tests { #[test] fn parse_ignored_flag() { - let args = ~[~"progname", ~"filter", ~"--ignored"]; - let opts = match parse_opts(args) { + let args = vec!(~"progname", ~"filter", ~"--ignored"); + let opts = match parse_opts(args.as_slice()) { Some(Ok(o)) => o, _ => fail!("Malformed arg in parse_ignored_flag") }; @@ -1415,7 +1419,7 @@ mod tests { test_shard: None }; - let tests = ~[ + let tests = vec!( TestDescAndFn { desc: TestDesc { name: StaticTestName("1"), @@ -1431,13 +1435,12 @@ mod tests { should_fail: false }, testfn: DynTestFn(proc() {}), - }, - ]; + }); let filtered = filter_tests(&opts, tests); assert_eq!(filtered.len(), 1); - assert_eq!(filtered[0].desc.name.to_str(), ~"1"); - assert!(filtered[0].desc.ignore == false); + assert_eq!(filtered.get(0).desc.name.to_str(), ~"1"); + assert!(filtered.get(0).desc.ignore == false); } #[test] @@ -1455,16 +1458,16 @@ mod tests { }; let names = - ~[~"sha1::test", ~"int::test_to_str", ~"int::test_pow", + vec!(~"sha1::test", ~"int::test_to_str", ~"int::test_pow", ~"test::do_not_run_ignored_tests", ~"test::ignored_tests_result_in_ignored", ~"test::first_free_arg_should_be_a_filter", ~"test::parse_ignored_flag", ~"test::filter_for_ignored_option", - ~"test::sort_tests"]; + ~"test::sort_tests"); let tests = { fn testfn() { } - let mut tests = ~[]; + let mut tests = Vec::new(); for name in names.iter() { let test = TestDescAndFn { desc: TestDesc { @@ -1481,13 +1484,13 @@ mod tests { let filtered = filter_tests(&opts, tests); let expected = - ~[~"int::test_pow", ~"int::test_to_str", ~"sha1::test", + vec!(~"int::test_pow", ~"int::test_to_str", ~"sha1::test", ~"test::do_not_run_ignored_tests", ~"test::filter_for_ignored_option", ~"test::first_free_arg_should_be_a_filter", ~"test::ignored_tests_result_in_ignored", ~"test::parse_ignored_flag", - ~"test::sort_tests"]; + ~"test::sort_tests"); for (a, b) in expected.iter().zip(filtered.iter()) { assert!(*a == b.desc.name.to_str()); diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index 7ac338a92a4c0..27f3ae980bed0 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -18,6 +18,7 @@ extern crate serialize; use std::io::BufReader; +use std::vec_ng::Vec; use std::libc; use std::num; use std::str; @@ -1018,7 +1019,7 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str { } } - let mut buf = ~[]; + let mut buf = Vec::new(); let mut rdr = BufReader::new(format.as_bytes()); loop { @@ -1037,7 +1038,7 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str { } } - str::from_utf8_owned(buf).unwrap() + str::from_utf8(buf.as_slice()).unwrap().to_str() } #[cfg(test)] diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 8dbdedc18483a..4368148f40baa 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -65,6 +65,7 @@ extern crate test; extern crate serialize; use std::cast::{transmute,transmute_copy}; +use std::vec_ng::Vec; use std::char::Char; use std::default::Default; use std::fmt; @@ -315,13 +316,13 @@ impl Uuid { /// /// Example: `936DA01F9ABD4d9d80C702AF85C822A8` pub fn to_simple_str(&self) -> ~str { - let mut s: ~[u8] = vec::from_elem(32, 0u8); + let mut s: Vec = Vec::from_elem(32, 0u8); for i in range(0u, 16u) { let digit = format!("{:02x}", self.bytes[i] as uint); - s[i*2+0] = digit[0]; - s[i*2+1] = digit[1]; + *s.get_mut(i*2+0) = digit[0]; + *s.get_mut(i*2+1) = digit[1]; } - str::from_utf8_owned(s).unwrap() + str::from_utf8(s.as_slice()).unwrap().to_str() } /// Returns a string of hexadecimal digits, separated into groups with a hyphen. @@ -385,17 +386,17 @@ impl Uuid { } // Split string up by hyphens into groups - let hex_groups: ~[&str] = us.split_str("-").collect(); + let hex_groups: Vec<&str> = us.split_str("-").collect(); // Get the length of each group - let group_lens: ~[uint] = hex_groups.iter().map(|&v| v.len()).collect(); + let group_lens: Vec = hex_groups.iter().map(|&v| v.len()).collect(); // Ensure the group lengths are valid match group_lens.len() { // Single group, no hyphens 1 => { - if group_lens[0] != 32 { - return Err(ErrorInvalidLength(group_lens[0])); + if *group_lens.get(0) != 32 { + return Err(ErrorInvalidLength(*group_lens.get(0))); } }, // Five groups, hyphens in between each @@ -526,6 +527,7 @@ mod test { use std::str; use std::rand; use std::io::MemWriter; + use std::vec_ng::Vec; #[test] fn test_nil() { @@ -685,7 +687,10 @@ mod test { let hs = uuid1.to_hyphenated_str(); let ss = uuid1.to_str(); - let hsn = str::from_chars(hs.chars().filter(|&c| c != '-').collect::<~[char]>()); + let hsn = str::from_chars(hs.chars() + .filter(|&c| c != '-') + .collect::>() + .as_slice()); assert!(hsn == ss); } @@ -719,9 +724,9 @@ mod test { let d1: u32 = 0xa1a2a3a4; let d2: u16 = 0xb1b2; let d3: u16 = 0xc1c2; - let d4: ~[u8] = ~[0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8]; + let d4: Vec = vec!(0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8); - let u = Uuid::from_fields(d1, d2, d3, d4); + let u = Uuid::from_fields(d1, d2, d3, d4.as_slice()); let expected = ~"a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; let result = u.to_simple_str(); @@ -730,10 +735,10 @@ mod test { #[test] fn test_from_bytes() { - let b = ~[ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, - 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ]; + let b = vec!( 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, + 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8 ); - let u = Uuid::from_bytes(b).unwrap(); + let u = Uuid::from_bytes(b.as_slice()).unwrap(); let expected = ~"a1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8"; assert!(u.to_simple_str() == expected); diff --git a/src/test/auxiliary/anon-extern-mod-cross-crate-1.rs b/src/test/auxiliary/anon-extern-mod-cross-crate-1.rs index aa6ee35a07792..823c856da13a6 100644 --- a/src/test/auxiliary/anon-extern-mod-cross-crate-1.rs +++ b/src/test/auxiliary/anon-extern-mod-cross-crate-1.rs @@ -12,6 +12,7 @@ use std::libc; +use std::vec_ng::Vec; #[link(name="rustrt")] extern { pub fn rust_get_test_int() -> libc::intptr_t; diff --git a/src/test/auxiliary/cci_class_6.rs b/src/test/auxiliary/cci_class_6.rs index 90344a544bff4..8258a668f46ef 100644 --- a/src/test/auxiliary/cci_class_6.rs +++ b/src/test/auxiliary/cci_class_6.rs @@ -9,22 +9,24 @@ // except according to those terms. pub mod kitties { + use std::vec_ng::Vec; + pub struct cat { - priv info : ~[U], + priv info : Vec , priv meows : uint, how_hungry : int, } impl cat { - pub fn speak(&mut self, stuff: ~[T]) { + pub fn speak(&mut self, stuff: Vec ) { self.meows += stuff.len(); } pub fn meow_count(&mut self) -> uint { self.meows } } - pub fn cat(in_x : uint, in_y : int, in_info: ~[U]) -> cat { + pub fn cat(in_x : uint, in_y : int, in_info: Vec ) -> cat { cat { meows: in_x, how_hungry: in_y, diff --git a/src/test/auxiliary/cci_nested_lib.rs b/src/test/auxiliary/cci_nested_lib.rs index 90b01f8888bef..8386a6f78c133 100644 --- a/src/test/auxiliary/cci_nested_lib.rs +++ b/src/test/auxiliary/cci_nested_lib.rs @@ -11,6 +11,7 @@ #[feature(managed_boxes)]; use std::cell::RefCell; +use std::vec_ng::Vec; pub struct Entry { key: A, @@ -19,7 +20,7 @@ pub struct Entry { pub struct alist { eq_fn: extern "Rust" fn(A,A) -> bool, - data: @RefCell<~[Entry]>, + data: @RefCell> >, } pub fn alist_add(lst: &alist, k: A, v: B) { @@ -47,7 +48,7 @@ pub fn new_int_alist() -> alist { fn eq_int(a: int, b: int) -> bool { a == b } return alist { eq_fn: eq_int, - data: @RefCell::new(~[]), + data: @RefCell::new(Vec::new()), }; } @@ -57,6 +58,6 @@ pub fn new_int_alist_2() -> alist { fn eq_int(a: int, b: int) -> bool { a == b } return alist { eq_fn: eq_int, - data: @RefCell::new(~[]), + data: @RefCell::new(Vec::new()), }; } diff --git a/src/test/auxiliary/cci_no_inline_lib.rs b/src/test/auxiliary/cci_no_inline_lib.rs index 87689474ca3e9..191313263aa9b 100644 --- a/src/test/auxiliary/cci_no_inline_lib.rs +++ b/src/test/auxiliary/cci_no_inline_lib.rs @@ -10,12 +10,14 @@ #[crate_id="cci_no_inline_lib"]; +use std::vec_ng::Vec; + // same as cci_iter_lib, more-or-less, but not marked inline -pub fn iter(v: ~[uint], f: |uint|) { +pub fn iter(v: Vec , f: |uint|) { let mut i = 0u; let n = v.len(); while i < n { - f(v[i]); + f(*v.get(i)); i += 1u; } } diff --git a/src/test/auxiliary/issue-2631-a.rs b/src/test/auxiliary/issue-2631-a.rs index 1a287b5e625cf..8ba9cdab79a4f 100644 --- a/src/test/auxiliary/issue-2631-a.rs +++ b/src/test/auxiliary/issue-2631-a.rs @@ -16,11 +16,12 @@ extern crate extra; extern crate collections; use std::cell::RefCell; +use std::vec_ng::Vec; use collections::HashMap; -pub type header_map = HashMap<~str, @RefCell<~[@~str]>>; +pub type header_map = HashMap<~str, @RefCell>>; // the unused ty param is necessary so this gets monomorphized pub fn request(req: &header_map) { - let _x = (*((**req.get(&~"METHOD")).clone()).get()[0u]).clone(); + let _x = (**((**req.get(&~"METHOD")).clone()).get().get(0)).clone(); } diff --git a/src/test/auxiliary/issue_2723_a.rs b/src/test/auxiliary/issue_2723_a.rs index b3fa8e73cc222..57acf3a7a9141 100644 --- a/src/test/auxiliary/issue_2723_a.rs +++ b/src/test/auxiliary/issue_2723_a.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub unsafe fn f(xs: ~[int]) { +use std::vec_ng::Vec; + +pub unsafe fn f(xs: Vec ) { xs.map(|_x| { unsafe fn q() { fail!(); } }); } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index 7b23e27e82a3c..8962e45fc9dff 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -20,7 +20,8 @@ use std::os; use std::rand::Rng; use std::rand; use std::str; -use std::vec; +use std::vec_ng::Vec; +use std::vec_ng; use std::io::File; macro_rules! bench ( @@ -61,8 +62,8 @@ fn maybe_run_test(argv: &[~str], name: ~str, test: ||) { } fn shift_push() { - let mut v1 = vec::from_elem(30000, 1); - let mut v2 = ~[]; + let mut v1 = Vec::from_elem(30000, 1); + let mut v2 = Vec::new(); while v1.len() > 0 { v2.push(v1.shift().unwrap()); @@ -85,14 +86,14 @@ fn read_line() { fn vec_plus() { let mut r = rand::rng(); - let mut v = ~[]; + let mut v = Vec::new(); let mut i = 0; while i < 1500 { - let rv = vec::from_elem(r.gen_range(0u, i + 1), i); + let rv = Vec::from_elem(r.gen_range(0u, i + 1), i); if r.gen() { v.push_all_move(rv); } else { - v = rv + v; + v = vec_ng::append(rv.clone(), v.as_slice()); } i += 1; } @@ -101,15 +102,15 @@ fn vec_plus() { fn vec_append() { let mut r = rand::rng(); - let mut v = ~[]; + let mut v = Vec::new(); let mut i = 0; while i < 1500 { - let rv = vec::from_elem(r.gen_range(0u, i + 1), i); + let rv = Vec::from_elem(r.gen_range(0u, i + 1), i); if r.gen() { - v = vec::append(v, rv); + v = vec_ng::append(v.clone(), rv.as_slice()); } else { - v = vec::append(rv, v); + v = vec_ng::append(rv.clone(), v.as_slice()); } i += 1; } @@ -118,24 +119,24 @@ fn vec_append() { fn vec_push_all() { let mut r = rand::rng(); - let mut v = ~[]; + let mut v = Vec::new(); for i in range(0u, 1500) { - let mut rv = vec::from_elem(r.gen_range(0u, i + 1), i); + let mut rv = Vec::from_elem(r.gen_range(0u, i + 1), i); if r.gen() { - v.push_all(rv); + v.push_all(rv.as_slice()); } else { swap(&mut v, &mut rv); - v.push_all(rv); + v.push_all(rv.as_slice()); } } } fn is_utf8_ascii() { - let mut v : ~[u8] = ~[]; + let mut v : Vec = Vec::new(); for _ in range(0u, 20000) { v.push('b' as u8); - if !str::is_utf8(v) { + if !str::is_utf8(v.as_slice()) { fail!("is_utf8 failed"); } } @@ -143,10 +144,10 @@ fn is_utf8_ascii() { fn is_utf8_multibyte() { let s = "b¢€𤭢"; - let mut v : ~[u8]= ~[]; + let mut v : Vec = Vec::new(); for _ in range(0u, 5000) { v.push_all(s.as_bytes()); - if !str::is_utf8(v) { + if !str::is_utf8(v.as_slice()) { fail!("is_utf8 failed"); } } diff --git a/src/test/bench/core-uint-to-str.rs b/src/test/bench/core-uint-to-str.rs index aec0bfb1e657c..b74ed7b25f788 100644 --- a/src/test/bench/core-uint-to-str.rs +++ b/src/test/bench/core-uint-to-str.rs @@ -10,18 +10,19 @@ use std::os; use std::uint; +use std::vec_ng::Vec; fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"10000000"] + vec!(~"", ~"10000000") } else if args.len() <= 1u { - ~[~"", ~"100000"] + vec!(~"", ~"100000") } else { - args + args.move_iter().collect() }; - let n = from_str::(args[1]).unwrap(); + let n = from_str::(*args.get(1)).unwrap(); for i in range(0u, n) { let x = i.to_str(); diff --git a/src/test/bench/msgsend-pipes-shared.rs b/src/test/bench/msgsend-pipes-shared.rs index 68f5bba159fc8..5b961a894dd16 100644 --- a/src/test/bench/msgsend-pipes-shared.rs +++ b/src/test/bench/msgsend-pipes-shared.rs @@ -24,6 +24,7 @@ use std::comm; use std::os; use std::task; use std::uint; +use std::vec_ng::Vec; fn move_out(_x: T) {} @@ -59,7 +60,7 @@ fn run(args: &[~str]) { let workers = from_str::(args[2]).unwrap(); let num_bytes = 100; let start = time::precise_time_s(); - let mut worker_results = ~[]; + let mut worker_results = Vec::new(); for _ in range(0u, workers) { let to_child = to_child.clone(); let mut builder = task::task(); @@ -96,13 +97,13 @@ fn run(args: &[~str]) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"1000000", ~"10000"] + vec!(~"", ~"1000000", ~"10000") } else if args.len() <= 1u { - ~[~"", ~"10000", ~"4"] + vec!(~"", ~"10000", ~"4") } else { - args.clone() + args.clone().move_iter().collect() }; info!("{:?}", args); - run(args); + run(args.as_slice()); } diff --git a/src/test/bench/msgsend-pipes.rs b/src/test/bench/msgsend-pipes.rs index 9da4a70656249..78e6a25ef92ba 100644 --- a/src/test/bench/msgsend-pipes.rs +++ b/src/test/bench/msgsend-pipes.rs @@ -19,6 +19,7 @@ extern crate time; use std::os; use std::task; use std::uint; +use std::vec_ng::Vec; fn move_out(_x: T) {} @@ -53,7 +54,7 @@ fn run(args: &[~str]) { let workers = from_str::(args[2]).unwrap(); let num_bytes = 100; let start = time::precise_time_s(); - let mut worker_results = ~[]; + let mut worker_results = Vec::new(); let from_parent = if workers == 1 { let (from_parent, to_child) = Chan::new(); let mut builder = task::task(); @@ -106,13 +107,13 @@ fn run(args: &[~str]) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"1000000", ~"8"] + vec!(~"", ~"1000000", ~"8") } else if args.len() <= 1u { - ~[~"", ~"10000", ~"4"] + vec!(~"", ~"10000", ~"4") } else { - args.clone() + args.clone().move_iter().collect() }; info!("{:?}", args); - run(args); + run(args.as_slice()); } diff --git a/src/test/bench/msgsend-ring-mutex-arcs.rs b/src/test/bench/msgsend-ring-mutex-arcs.rs index 6b91d1d534b62..96164d4e58432 100644 --- a/src/test/bench/msgsend-ring-mutex-arcs.rs +++ b/src/test/bench/msgsend-ring-mutex-arcs.rs @@ -23,9 +23,10 @@ use sync::MutexArc; use sync::Future; use std::os; use std::uint; +use std::vec_ng::Vec; // A poor man's pipe. -type pipe = MutexArc<~[uint]>; +type pipe = MutexArc >; fn send(p: &pipe, msg: uint) { unsafe { @@ -47,7 +48,7 @@ fn recv(p: &pipe) -> uint { } fn init() -> (pipe,pipe) { - let m = MutexArc::new(~[]); + let m = MutexArc::new(Vec::new()); ((&m).clone(), m) } @@ -71,22 +72,22 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"100", ~"10000"] + vec!(~"", ~"100", ~"10000") } else if args.len() <= 1u { - ~[~"", ~"10", ~"100"] + vec!(~"", ~"10", ~"100") } else { - args.clone() + args.clone().move_iter().collect() }; - let num_tasks = from_str::(args[1]).unwrap(); - let msg_per_task = from_str::(args[2]).unwrap(); + let num_tasks = from_str::(*args.get(1)).unwrap(); + let msg_per_task = from_str::(*args.get(2)).unwrap(); let (mut num_chan, num_port) = init(); let start = time::precise_time_s(); // create the ring - let mut futures = ~[]; + let mut futures = Vec::new(); for i in range(1u, num_tasks) { //error!("spawning %?", i); diff --git a/src/test/bench/msgsend-ring-rw-arcs.rs b/src/test/bench/msgsend-ring-rw-arcs.rs index 2d52f125747e8..6c528912376c8 100644 --- a/src/test/bench/msgsend-ring-rw-arcs.rs +++ b/src/test/bench/msgsend-ring-rw-arcs.rs @@ -22,9 +22,10 @@ use sync::RWArc; use sync::Future; use std::os; use std::uint; +use std::vec_ng::Vec; // A poor man's pipe. -type pipe = RWArc<~[uint]>; +type pipe = RWArc >; fn send(p: &pipe, msg: uint) { p.write_cond(|state, cond| { @@ -42,7 +43,7 @@ fn recv(p: &pipe) -> uint { } fn init() -> (pipe,pipe) { - let x = RWArc::new(~[]); + let x = RWArc::new(Vec::new()); ((&x).clone(), x) } @@ -66,22 +67,22 @@ fn thread_ring(i: uint, count: uint, num_chan: pipe, num_port: pipe) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"100", ~"10000"] + vec!(~"", ~"100", ~"10000") } else if args.len() <= 1u { - ~[~"", ~"10", ~"100"] + vec!(~"", ~"10", ~"100") } else { - args.clone() + args.clone().move_iter().collect() }; - let num_tasks = from_str::(args[1]).unwrap(); - let msg_per_task = from_str::(args[2]).unwrap(); + let num_tasks = from_str::(*args.get(1)).unwrap(); + let msg_per_task = from_str::(*args.get(2)).unwrap(); let (mut num_chan, num_port) = init(); let start = time::precise_time_s(); // create the ring - let mut futures = ~[]; + let mut futures = Vec::new(); for i in range(1u, num_tasks) { //error!("spawning %?", i); diff --git a/src/test/bench/shootout-ackermann.rs b/src/test/bench/shootout-ackermann.rs index d308ed6a7d1d7..f934771503d1d 100644 --- a/src/test/bench/shootout-ackermann.rs +++ b/src/test/bench/shootout-ackermann.rs @@ -11,6 +11,7 @@ extern crate extra; use std::os; +use std::vec_ng::Vec; fn ack(m: int, n: int) -> int { if m == 0 { @@ -27,12 +28,12 @@ fn ack(m: int, n: int) -> int { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"12"] + vec!(~"", ~"12") } else if args.len() <= 1u { - ~[~"", ~"8"] + vec!(~"", ~"8") } else { - args + args.move_iter().collect() }; - let n = from_str::(args[1]).unwrap(); + let n = from_str::(*args.get(1)).unwrap(); println!("Ack(3,{}): {}\n", n, ack(3, n)); } diff --git a/src/test/bench/shootout-chameneos-redux.rs b/src/test/bench/shootout-chameneos-redux.rs index a6bbea0ac14da..5de7c54b80d9f 100644 --- a/src/test/bench/shootout-chameneos-redux.rs +++ b/src/test/bench/shootout-chameneos-redux.rs @@ -15,6 +15,7 @@ extern crate extra; use std::option; use std::os; use std::task; +use std::vec_ng::Vec; fn print_complements() { let all = [Blue, Red, Yellow]; @@ -41,7 +42,7 @@ fn show_color(cc: color) -> ~str { } } -fn show_color_list(set: ~[color]) -> ~str { +fn show_color_list(set: Vec) -> ~str { let mut out = ~""; for col in set.iter() { out.push_char(' '); @@ -134,7 +135,7 @@ fn creature( } } -fn rendezvous(nn: uint, set: ~[color]) { +fn rendezvous(nn: uint, set: Vec) { // these ports will allow us to hear from the creatures let (from_creatures, to_rendezvous) = Chan::::new(); @@ -143,7 +144,7 @@ fn rendezvous(nn: uint, set: ~[color]) { // these channels will be passed to the creatures so they can talk to us // these channels will allow us to talk to each creature by 'name'/index - let to_creature: ~[Chan>] = + let mut to_creature: Vec>> = set.iter().enumerate().map(|(ii, col)| { // create each creature as a listener with a port, and // give us a channel to talk to each @@ -166,13 +167,13 @@ fn rendezvous(nn: uint, set: ~[color]) { // set up meetings... for _ in range(0, nn) { - let fst_creature: CreatureInfo = from_creatures.recv(); - let snd_creature: CreatureInfo = from_creatures.recv(); + let mut fst_creature: CreatureInfo = from_creatures.recv(); + let mut snd_creature: CreatureInfo = from_creatures.recv(); creatures_met += 2; - to_creature[fst_creature.name].send(Some(snd_creature)); - to_creature[snd_creature.name].send(Some(fst_creature)); + to_creature.get_mut(fst_creature.name).send(Some(snd_creature)); + to_creature.get_mut(snd_creature.name).send(Some(fst_creature)); } // tell each creature to stop @@ -181,7 +182,7 @@ fn rendezvous(nn: uint, set: ~[color]) { } // save each creature's meeting stats - let mut report = ~[]; + let mut report = Vec::new(); for _to_one in to_creature.iter() { report.push(from_creatures_log.recv()); } @@ -201,21 +202,21 @@ fn rendezvous(nn: uint, set: ~[color]) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"200000"] + vec!(~"", ~"200000") } else if args.len() <= 1u { - ~[~"", ~"600"] + vec!(~"", ~"600") } else { - args + args.move_iter().collect() }; - let nn = from_str::(args[1]).unwrap(); + let nn = from_str::(*args.get(1)).unwrap(); print_complements(); println!(""); - rendezvous(nn, ~[Blue, Red, Yellow]); + rendezvous(nn, vec!(Blue, Red, Yellow)); println!(""); rendezvous(nn, - ~[Blue, Red, Yellow, Red, Yellow, Blue, Red, Yellow, Red, Blue]); + vec!(Blue, Red, Yellow, Red, Yellow, Blue, Red, Yellow, Red, Blue)); } diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 532bc714d3165..b208c1c6e03d2 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -13,6 +13,7 @@ use std::io::{stdout, IoResult}; use std::os; use std::vec::bytes::copy_memory; use std::vec; +use std::vec_ng::Vec; static LINE_LEN: uint = 60; static LOOKUP_SIZE: uint = 4 * 1024; @@ -59,8 +60,8 @@ static HOMO_SAPIENS: [AminoAcid, ..4] = [ ]; // FIXME: Use map(). -fn sum_and_scale(a: &'static [AminoAcid]) -> ~[AminoAcid] { - let mut result = ~[]; +fn sum_and_scale(a: &'static [AminoAcid]) -> Vec { + let mut result = Vec::new(); let mut p = 0f32; for a_i in a.iter() { let mut a_i = *a_i; @@ -68,7 +69,8 @@ fn sum_and_scale(a: &'static [AminoAcid]) -> ~[AminoAcid] { a_i.p = p * LOOKUP_SCALE; result.push(a_i); } - result[result.len() - 1].p = LOOKUP_SCALE; + let result_len = result.len(); + result.get_mut(result_len - 1).p = LOOKUP_SCALE; result } @@ -193,12 +195,12 @@ fn main() { out.write_line(">TWO IUB ambiguity codes").unwrap(); let iub = sum_and_scale(IUB); - let mut random = RandomFasta::new(&mut out, iub); + let mut random = RandomFasta::new(&mut out, iub.as_slice()); random.make(n * 3).unwrap(); random.out.write_line(">THREE Homo sapiens frequency").unwrap(); let homo_sapiens = sum_and_scale(HOMO_SAPIENS); - random.lookup = make_lookup(homo_sapiens); + random.lookup = make_lookup(homo_sapiens.as_slice()); random.make(n * 5).unwrap(); random.out.write_str("\n").unwrap(); diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index ae0bd069c906d..017099bbafacd 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -18,6 +18,7 @@ use std::io; use std::io::{BufferedWriter, File}; use std::cmp::min; use std::os; +use std::vec_ng::Vec; static LINE_LENGTH: uint = 60; static IM: u32 = 139968; @@ -36,8 +37,7 @@ impl MyRandom { struct AAGen<'a> { rng: &'a mut MyRandom, - data: ~[(u32, u8)] -} + data: Vec<(u32, u8)> } impl<'a> AAGen<'a> { fn new<'b>(rng: &'b mut MyRandom, aa: &[(char, f32)]) -> AAGen<'b> { let mut cum = 0.; diff --git a/src/test/bench/shootout-fibo.rs b/src/test/bench/shootout-fibo.rs index 4a4b2e8e875ca..f09e6b017a97d 100644 --- a/src/test/bench/shootout-fibo.rs +++ b/src/test/bench/shootout-fibo.rs @@ -11,6 +11,7 @@ extern crate extra; use std::os; +use std::vec_ng::Vec; fn fib(n: int) -> int { if n < 2 { @@ -23,12 +24,12 @@ fn fib(n: int) -> int { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"40"] + vec!(~"", ~"40") } else if args.len() <= 1u { - ~[~"", ~"30"] + vec!(~"", ~"30") } else { - args + args.move_iter().collect() }; - let n = from_str::(args[1]).unwrap(); + let n = from_str::(*args.get(1)).unwrap(); println!("{}\n", fib(n)); } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 7188e119a8d63..fc5b0ef7051bb 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -25,7 +25,8 @@ use std::os; use std::io; use std::str; use std::task; -use std::vec; +use std::vec_ng::Vec; +use std::vec_ng; fn f64_cmp(x: f64, y: f64) -> Ordering { // arbitrarily decide that NaNs are larger than everything. @@ -43,19 +44,19 @@ fn f64_cmp(x: f64, y: f64) -> Ordering { } // given a map, print a sorted version of it -fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { +fn sort_and_fmt(mm: &HashMap , uint>, total: uint) -> ~str { fn pct(xx: uint, yy: uint) -> f64 { return (xx as f64) * 100.0 / (yy as f64); } // sort by key, then by value - fn sortKV(mut orig: ~[(~[u8],f64)]) -> ~[(~[u8],f64)] { + fn sortKV(mut orig: Vec<(Vec ,f64)> ) -> Vec<(Vec ,f64)> { orig.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b)); orig.sort_by(|&(_, a), &(_, b)| f64_cmp(b, a)); orig } - let mut pairs = ~[]; + let mut pairs = Vec::new(); // map -> [(k,%)] for (key, &val) in mm.iter() { @@ -69,7 +70,10 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { for &(ref k, v) in pairs_sorted.iter() { unsafe { buffer.push_str(format!("{} {:0.3f}\n", - k.to_ascii().to_upper().into_str(), v)); + k.as_slice() + .to_ascii() + .to_upper() + .into_str(), v)); } } @@ -77,7 +81,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { } // given a map, search for the frequency of a pattern -fn find(mm: &HashMap<~[u8], uint>, key: ~str) -> uint { +fn find(mm: &HashMap , uint>, key: ~str) -> uint { let key = key.into_ascii().to_lower().into_str(); match mm.find_equiv(&key.as_bytes()) { option::None => { return 0u; } @@ -86,8 +90,8 @@ fn find(mm: &HashMap<~[u8], uint>, key: ~str) -> uint { } // given a map, increment the counter for a key -fn update_freq(mm: &mut HashMap<~[u8], uint>, key: &[u8]) { - let key = key.to_owned(); +fn update_freq(mm: &mut HashMap , uint>, key: &[u8]) { + let key = Vec::from_slice(key); let newval = match mm.pop(&key) { Some(v) => v + 1, None => 1 @@ -95,10 +99,10 @@ fn update_freq(mm: &mut HashMap<~[u8], uint>, key: &[u8]) { mm.insert(key, newval); } -// given a ~[u8], for each window call a function +// given a Vec, for each window call a function // i.e., for "hello" and windows of size four, // run it("hell") and it("ello"), then return "llo" -fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> ~[u8] { +fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> Vec { let mut ii = 0u; let len = bb.len(); @@ -107,24 +111,27 @@ fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> ~[u8] { ii += 1u; } - return bb.slice(len - (nn - 1u), len).to_owned(); + return Vec::from_slice(bb.slice(len - (nn - 1u), len)); } fn make_sequence_processor(sz: uint, - from_parent: &Port<~[u8]>, + from_parent: &Port >, to_parent: &Chan<~str>) { - let mut freqs: HashMap<~[u8], uint> = HashMap::new(); - let mut carry: ~[u8] = ~[]; + let mut freqs: HashMap , uint> = HashMap::new(); + let mut carry: Vec = Vec::new(); let mut total: uint = 0u; - let mut line: ~[u8]; + let mut line: Vec; loop { line = from_parent.recv(); - if line == ~[] { break; } + if line == Vec::new() { break; } - carry = windows_with_carry(carry + line, sz, |window| { + carry = windows_with_carry(vec_ng::append(carry, + line.as_slice()).as_slice(), + sz, + |window| { update_freq(&mut freqs, window); total += 1u; }); @@ -157,9 +164,9 @@ fn main() { let mut rdr = BufferedReader::new(rdr); // initialize each sequence sorter - let sizes = ~[1u,2,3,4,6,12,18]; - let mut streams = vec::from_fn(sizes.len(), |_| Some(Chan::<~str>::new())); - let mut from_child = ~[]; + let sizes = vec!(1u,2,3,4,6,12,18); + let mut streams = Vec::from_fn(sizes.len(), |_| Some(Chan::<~str>::new())); + let mut from_child = Vec::new(); let to_child = sizes.iter().zip(streams.mut_iter()).map(|(sz, stream_ref)| { let sz = *sz; let stream = replace(stream_ref, None); @@ -174,7 +181,7 @@ fn main() { }); to_child - }).collect::<~[Chan<~[u8]>]>(); + }).collect:: >> >(); // latch stores true after we've started @@ -204,8 +211,8 @@ fn main() { let line_bytes = line.as_bytes(); for (ii, _sz) in sizes.iter().enumerate() { - let lb = line_bytes.to_owned(); - to_child[ii].send(lb); + let lb = Vec::from_slice(line_bytes); + to_child.get(ii).send(lb); } } @@ -216,11 +223,11 @@ fn main() { // finish... for (ii, _sz) in sizes.iter().enumerate() { - to_child[ii].send(~[]); + to_child.get(ii).send(Vec::new()); } // now fetch and print result messages for (ii, _sz) in sizes.iter().enumerate() { - println!("{}", from_child[ii].recv()); + println!("{}", from_child.get(ii).recv()); } } diff --git a/src/test/bench/shootout-k-nucleotide.rs b/src/test/bench/shootout-k-nucleotide.rs index 2ddea19b4c9df..a3b75ffe592dc 100644 --- a/src/test/bench/shootout-k-nucleotide.rs +++ b/src/test/bench/shootout-k-nucleotide.rs @@ -12,6 +12,7 @@ use std::str; use std::vec; +use std::vec_ng::Vec; static TABLE: [u8, ..4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ]; static TABLE_SIZE: uint = 2 << 16; @@ -50,14 +51,14 @@ impl Code { // FIXME: Inefficient. fn unpack(&self, frame: i32) -> ~str { let mut key = self.hash(); - let mut result = ~[]; + let mut result = Vec::new(); for _ in range(0, frame) { result.push(unpack_symbol((key as u8) & 3)); key >>= 2; } result.reverse(); - str::from_utf8_owned(result).unwrap() + str::from_utf8_owned(result.move_iter().collect()).unwrap() } } @@ -92,8 +93,7 @@ struct Entry { struct Table { count: i32, - items: ~[Option<~Entry>] -} + items: Vec> } struct Items<'a> { cur: Option<&'a Entry>, @@ -104,7 +104,7 @@ impl Table { fn new() -> Table { Table { count: 0, - items: vec::from_fn(TABLE_SIZE, |_| None), + items: Vec::from_fn(TABLE_SIZE, |_| None), } } @@ -134,20 +134,20 @@ impl Table { let index = key.hash() % (TABLE_SIZE as u64); { - if self.items[index].is_none() { + if self.items.get(index as uint).is_none() { let mut entry = ~Entry { code: key, count: 0, next: None, }; c.f(entry); - self.items[index] = Some(entry); + *self.items.get_mut(index as uint) = Some(entry); return; } } { - let entry = &mut *self.items[index].get_mut_ref(); + let entry = &mut *self.items.get_mut(index as uint).get_mut_ref(); if entry.code == key { c.f(*entry); return; @@ -237,11 +237,11 @@ fn generate_frequencies(frequencies: &mut Table, } fn print_frequencies(frequencies: &Table, frame: i32) { - let mut vector = ~[]; + let mut vector = Vec::new(); for entry in frequencies.iter() { vector.push((entry.code, entry.count)); } - vector.sort(); + vector.as_mut_slice().sort(); let mut total_count = 0; for &(_, count) in vector.iter() { diff --git a/src/test/bench/shootout-meteor.rs b/src/test/bench/shootout-meteor.rs index 496e09b465164..fbe19af27fd90 100644 --- a/src/test/bench/shootout-meteor.rs +++ b/src/test/bench/shootout-meteor.rs @@ -12,6 +12,8 @@ // Utilities. // +use std::vec_ng::Vec; + // returns an infinite iterator of repeated applications of f to x, // i.e. [x, f(x), f(f(x)), ...], as haskell iterate function. fn iterate<'a, T>(x: T, f: 'a |&T| -> T) -> Iterate<'a, T> { @@ -63,8 +65,8 @@ impl<'a, T> Iterator<&'a T> for ListIterator<'a, T> { // corresponding mirrored piece), with, as minimum coordinates, (0, // 0). If all is false, only generate half of the possibilities (used // to break the symetry of the board). -fn transform(piece: ~[(int, int)], all: bool) -> ~[~[(int, int)]] { - let mut res = +fn transform(piece: Vec<(int, int)> , all: bool) -> Vec> { + let mut res: Vec> = // rotations iterate(piece, |rot| rot.iter().map(|&(y, x)| (x + y, -y)).collect()) .take(if all {6} else {3}) @@ -72,7 +74,7 @@ fn transform(piece: ~[(int, int)], all: bool) -> ~[~[(int, int)]] { .flat_map(|cur_piece| { iterate(cur_piece, |mir| mir.iter().map(|&(y, x)| (x, y)).collect()) .take(2) - }).to_owned_vec(); + }).collect(); // translating to (0, 0) as minimum coordinates. for cur_piece in res.mut_iter() { @@ -107,30 +109,30 @@ fn mask(dy: int, dx: int, id: uint, p: &[(int, int)]) -> Option { // Makes every possible masks. masks[id][i] correspond to every // possible masks for piece with identifier id with minimum coordinate // (i/5, i%5). -fn make_masks() -> ~[~[~[u64]]] { - let pieces = ~[ - ~[(0,0),(0,1),(0,2),(0,3),(1,3)], - ~[(0,0),(0,2),(0,3),(1,0),(1,1)], - ~[(0,0),(0,1),(0,2),(1,2),(2,1)], - ~[(0,0),(0,1),(0,2),(1,1),(2,1)], - ~[(0,0),(0,2),(1,0),(1,1),(2,1)], - ~[(0,0),(0,1),(0,2),(1,1),(1,2)], - ~[(0,0),(0,1),(1,1),(1,2),(2,1)], - ~[(0,0),(0,1),(0,2),(1,0),(1,2)], - ~[(0,0),(0,1),(0,2),(1,2),(1,3)], - ~[(0,0),(0,1),(0,2),(0,3),(1,2)]]; - let mut res = ~[]; +fn make_masks() -> Vec > > { + let pieces = vec!( + vec!((0,0),(0,1),(0,2),(0,3),(1,3)), + vec!((0,0),(0,2),(0,3),(1,0),(1,1)), + vec!((0,0),(0,1),(0,2),(1,2),(2,1)), + vec!((0,0),(0,1),(0,2),(1,1),(2,1)), + vec!((0,0),(0,2),(1,0),(1,1),(2,1)), + vec!((0,0),(0,1),(0,2),(1,1),(1,2)), + vec!((0,0),(0,1),(1,1),(1,2),(2,1)), + vec!((0,0),(0,1),(0,2),(1,0),(1,2)), + vec!((0,0),(0,1),(0,2),(1,2),(1,3)), + vec!((0,0),(0,1),(0,2),(0,3),(1,2))); + let mut res = Vec::new(); for (id, p) in pieces.move_iter().enumerate() { // To break the central symetry of the problem, every // transformation must be taken except for one piece (piece 3 // here). let trans = transform(p, id != 3); - let mut cur_piece = ~[]; + let mut cur_piece = Vec::new(); for dy in range(0, 10) { for dx in range(0, 5) { let masks = trans.iter() - .filter_map(|t| mask(dy, dx, id, *t)) + .filter_map(|t| mask(dy, dx, id, t.as_slice())) .collect(); cur_piece.push(masks); } @@ -142,12 +144,12 @@ fn make_masks() -> ~[~[~[u64]]] { // Check if all coordinates can be covered by an unused piece and that // all unused piece can be placed on the board. -fn is_board_unfeasible(board: u64, masks: &[~[~[u64]]]) -> bool { +fn is_board_unfeasible(board: u64, masks: &[Vec > ]) -> bool { let mut coverable = board; for i in range(0, 50).filter(|&i| board & 1 << i == 0) { for (cur_id, pos_masks) in masks.iter().enumerate() { if board & 1 << (50 + cur_id) != 0 {continue;} - for &cur_m in pos_masks[i].iter() { + for &cur_m in pos_masks.get(i as uint).iter() { if cur_m & board == 0 {coverable |= cur_m;} } } @@ -159,7 +161,7 @@ fn is_board_unfeasible(board: u64, masks: &[~[~[u64]]]) -> bool { } // Filter the masks that we can prove to result to unfeasible board. -fn filter_masks(masks: &[~[~[u64]]]) -> ~[~[~[u64]]] { +fn filter_masks(masks: &[Vec > ]) -> Vec > > { masks.iter().map( |p| p.iter().map( |p| p.iter() @@ -180,14 +182,16 @@ fn get_id(m: u64) -> u8 { // Converts a list of mask to a ~str. fn to_utf8(raw_sol: &List) -> ~str { - let mut sol: ~[u8] = std::vec::from_elem(50, '.' as u8); + let mut sol: Vec = Vec::from_elem(50, '.' as u8); for &m in raw_sol.iter() { let id = get_id(m); for i in range(0, 50) { - if m & 1 << i != 0 {sol[i] = '0' as u8 + id;} + if m & 1 << i != 0 { + *sol.get_mut(i as uint) = '0' as u8 + id; + } } } - std::str::from_utf8_owned(sol).unwrap() + std::str::from_utf8_owned(sol.move_iter().collect()).unwrap() } // Prints a solution in ~str form. @@ -237,7 +241,7 @@ fn handle_sol(raw_sol: &List, data: &mut Data) -> bool { // Search for every solutions. Returns false if the search was // stopped before the end. fn search( - masks: &[~[~[u64]]], + masks: &[Vec > ], board: u64, mut i: int, cur: List, @@ -252,7 +256,9 @@ fn search( // for every unused piece for id in range(0, 10).filter(|id| board & (1 << (id + 50)) == 0) { // for each mask that fits on the board - for &m in masks[id][i].iter().filter(|&m| board & *m == 0) { + for &m in masks[id].get(i as uint) + .iter() + .filter(|&m| board & *m == 0) { // This check is too costy. //if is_board_unfeasible(board | m, masks) {continue;} if !search(masks, board | m, i + 1, Cons(m, &cur), data) { @@ -271,9 +277,9 @@ fn main () { from_str(args[1]).unwrap() }; let masks = make_masks(); - let masks = filter_masks(masks); + let masks = filter_masks(masks.as_slice()); let mut data = Data {stop_after: stop_after, nb: 0, min: ~"", max: ~""}; - search(masks, 0, 0, Nil, &mut data); + search(masks.as_slice(), 0, 0, Nil, &mut data); println!("{} solutions found", data.nb); print_sol(data.min); print_sol(data.max); diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index ce49b8b2141ef..b4c96a48ded75 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -9,6 +9,7 @@ // except according to those terms. use std::os; +use std::vec_ng::Vec; static PI: f64 = 3.141592653589793; static SOLAR_MASS: f64 = 4.0 * PI * PI; @@ -148,14 +149,14 @@ fn offset_momentum(bodies: &mut [Planet, ..N_BODIES]) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"1000"] + vec!(~"", ~"1000") } else if args.len() <= 1u { - ~[~"", ~"1000"] + vec!(~"", ~"1000") } else { - args + args.move_iter().collect() }; - let n: i32 = from_str::(args[1]).unwrap(); + let n: i32 = from_str::(*args.get(1)).unwrap(); let mut bodies = BODIES; offset_momentum(&mut bodies); diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index 11a843d6cb573..36722dabbb04a 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -25,6 +25,7 @@ use std::os; use std::result::{Ok, Err}; use std::task; use std::uint; +use std::vec_ng::Vec; fn fib(n: int) -> int { fn pfib(c: &Chan, n: int) { @@ -51,12 +52,12 @@ struct Config { stress: bool } -fn parse_opts(argv: ~[~str]) -> Config { - let opts = ~[getopts::optflag("", "stress", "")]; +fn parse_opts(argv: Vec<~str> ) -> Config { + let opts = vec!(getopts::optflag("", "stress", "")); let opt_args = argv.slice(1, argv.len()); - match getopts::getopts(opt_args, opts) { + match getopts::getopts(opt_args, opts.as_slice()) { Ok(ref m) => { return Config {stress: m.opt_present("stress")} } @@ -75,7 +76,7 @@ fn stress_task(id: int) { } fn stress(num_tasks: int) { - let mut results = ~[]; + let mut results = Vec::new(); for i in range(0, num_tasks) { let mut builder = task::task(); results.push(builder.future_result()); @@ -91,11 +92,11 @@ fn stress(num_tasks: int) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"20"] + vec!(~"", ~"20") } else if args.len() <= 1u { - ~[~"", ~"8"] + vec!(~"", ~"8") } else { - args + args.move_iter().collect() }; let opts = parse_opts(args.clone()); @@ -103,7 +104,8 @@ fn main() { if opts.stress { stress(2); } else { - let max = uint::parse_bytes(args[1].as_bytes(), 10u).unwrap() as int; + let max = uint::parse_bytes(args.get(1).as_bytes(), 10u).unwrap() as + int; let num_trials = 10; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 7a393ad785081..7674a917a673d 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -29,14 +29,15 @@ fn dot(v: &[f64], u: &[f64]) -> f64 { sum } -fn mult(v: RWArc<~[f64]>, out: RWArc<~[f64]>, f: fn(&~[f64], uint) -> f64) { - // We lanch in different tasks the work to be done. To finish +fn mult(v: RWArc>, + out: RWArc>, + f: fn(&Vec, uint) -> f64) { + // We launch in different tasks the work to be done. To finish // this fuction, we need to wait for the completion of every // tasks. To do that, we give to each tasks a wait_chan that we // drop at the end of the work. At the end of this function, we // wait until the channel hang up. let (wait_port, wait_chan) = Chan::new(); - let len = out.read(|out| out.len()); let chunk = len / 100 + 1; for chk in count(0, chunk) { @@ -58,7 +59,7 @@ fn mult(v: RWArc<~[f64]>, out: RWArc<~[f64]>, f: fn(&~[f64], uint) -> f64) { for () in wait_port.iter() {} } -fn mult_Av_impl(v: &~[f64], i: uint) -> f64 { +fn mult_Av_impl(v: &Vec , i: uint) -> f64 { let mut sum = 0.; for (j, &v_j) in v.iter().enumerate() { sum += v_j / A(i, j); @@ -66,11 +67,11 @@ fn mult_Av_impl(v: &~[f64], i: uint) -> f64 { sum } -fn mult_Av(v: RWArc<~[f64]>, out: RWArc<~[f64]>) { +fn mult_Av(v: RWArc >, out: RWArc >) { mult(v, out, mult_Av_impl); } -fn mult_Atv_impl(v: &~[f64], i: uint) -> f64 { +fn mult_Atv_impl(v: &Vec , i: uint) -> f64 { let mut sum = 0.; for (j, &v_j) in v.iter().enumerate() { sum += v_j / A(j, i); @@ -78,11 +79,11 @@ fn mult_Atv_impl(v: &~[f64], i: uint) -> f64 { sum } -fn mult_Atv(v: RWArc<~[f64]>, out: RWArc<~[f64]>) { +fn mult_Atv(v: RWArc >, out: RWArc >) { mult(v, out, mult_Atv_impl); } -fn mult_AtAv(v: RWArc<~[f64]>, out: RWArc<~[f64]>, tmp: RWArc<~[f64]>) { +fn mult_AtAv(v: RWArc >, out: RWArc >, tmp: RWArc >) { mult_Av(v, tmp.clone()); mult_Atv(tmp, out); } diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs index 6ce6fb503a1d8..a442e5340296a 100644 --- a/src/test/bench/shootout-threadring.rs +++ b/src/test/bench/shootout-threadring.rs @@ -58,19 +58,18 @@ fn main() { use std::from_str::FromStr; let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"2000000", ~"503"] - } - else { - os::args() + vec!(~"", ~"2000000", ~"503") + } else { + os::args().move_iter().collect() }; let token = if args.len() > 1u { - FromStr::from_str(args[1]).unwrap() + FromStr::from_str(*args.get(1)).unwrap() } else { 1000 }; let n_tasks = if args.len() > 2u { - FromStr::from_str(args[2]).unwrap() + FromStr::from_str(*args.get(2)).unwrap() } else { 503 diff --git a/src/test/bench/std-smallintmap.rs b/src/test/bench/std-smallintmap.rs index 98deeec7e1818..7bafdd81b7cc7 100644 --- a/src/test/bench/std-smallintmap.rs +++ b/src/test/bench/std-smallintmap.rs @@ -16,6 +16,7 @@ extern crate time; use collections::SmallIntMap; use std::os; use std::uint; +use std::vec_ng::Vec; fn append_sequential(min: uint, max: uint, map: &mut SmallIntMap) { for i in range(min, max) { @@ -32,14 +33,14 @@ fn check_sequential(min: uint, max: uint, map: &SmallIntMap) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"100000", ~"100"] + vec!(~"", ~"100000", ~"100") } else if args.len() <= 1u { - ~[~"", ~"10000", ~"50"] + vec!(~"", ~"10000", ~"50") } else { - args + args.move_iter().collect() }; - let max = from_str::(args[1]).unwrap(); - let rep = from_str::(args[2]).unwrap(); + let max = from_str::(*args.get(1)).unwrap(); + let rep = from_str::(*args.get(2)).unwrap(); let mut checkf = 0.0; let mut appendf = 0.0; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index b77180e8e4ccf..6e58aa583123f 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -20,6 +20,7 @@ use std::io::BufferedReader; use std::os; use std::intrinsics::cttz16; use std::vec; +use std::vec_ng::Vec; // Computes a single solution to a given 9x9 sudoku // @@ -38,7 +39,7 @@ use std::vec; // // internal type of sudoku grids -type grid = ~[~[u8]]; +type grid = Vec > ; struct Sudoku { grid: grid @@ -50,8 +51,8 @@ impl Sudoku { } pub fn from_vec(vec: &[[u8, ..9], ..9]) -> Sudoku { - let g = vec::from_fn(9u, |i| { - vec::from_fn(9u, |j| { vec[i][j] }) + let g = Vec::from_fn(9u, |i| { + Vec::from_fn(9u, |j| { vec[i][j] }) }); return Sudoku::new(g) } @@ -59,7 +60,8 @@ impl Sudoku { pub fn equal(&self, other: &Sudoku) -> bool { for row in range(0u8, 9u8) { for col in range(0u8, 9u8) { - if self.grid[row][col] != other.grid[row][col] { + if *self.grid.get(row as uint).get(col as uint) != + *other.grid.get(row as uint).get(col as uint) { return false; } } @@ -70,14 +72,15 @@ impl Sudoku { pub fn read(mut reader: BufferedReader) -> Sudoku { assert!(reader.read_line().unwrap() == ~"9,9"); /* assert first line is exactly "9,9" */ - let mut g = vec::from_fn(10u, { |_i| ~[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] }); + let mut g = Vec::from_fn(10u, { |_i| vec!(0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8) }); for line in reader.lines() { - let comps: ~[&str] = line.trim().split(',').collect(); + let comps: Vec<&str> = line.trim().split(',').collect(); if comps.len() == 3u { - let row = from_str::(comps[0]).unwrap() as u8; - let col = from_str::(comps[1]).unwrap() as u8; - g[row][col] = from_str::(comps[2]).unwrap() as u8; + let row = from_str::(*comps.get(0)).unwrap() as u8; + let col = from_str::(*comps.get(1)).unwrap() as u8; + *g.get_mut(row as uint).get_mut(col as uint) = + from_str::(*comps.get(2)).unwrap() as u8; } else { fail!("Invalid sudoku file"); @@ -88,9 +91,11 @@ impl Sudoku { pub fn write(&self, writer: &mut io::Writer) { for row in range(0u8, 9u8) { - write!(writer, "{}", self.grid[row][0]); + write!(writer, "{}", *self.grid.get(row as uint).get(0)); for col in range(1u8, 9u8) { - write!(writer, " {}", self.grid[row][col]); + write!(writer, " {}", *self.grid + .get(row as uint) + .get(col as uint)); } write!(writer, "\n"); } @@ -98,10 +103,10 @@ impl Sudoku { // solve sudoku grid pub fn solve(&mut self) { - let mut work: ~[(u8, u8)] = ~[]; /* queue of uncolored fields */ + let mut work: Vec<(u8, u8)> = Vec::new(); /* queue of uncolored fields */ for row in range(0u8, 9u8) { for col in range(0u8, 9u8) { - let color = self.grid[row][col]; + let color = *self.grid.get(row as uint).get(col as uint); if color == 0u8 { work.push((row, col)); } @@ -111,9 +116,11 @@ impl Sudoku { let mut ptr = 0u; let end = work.len(); while ptr < end { - let (row, col) = work[ptr]; + let (row, col) = *work.get(ptr); // is there another color to try? - if self.next_color(row, col, self.grid[row][col] + (1 as u8)) { + let the_color = *self.grid.get(row as uint).get(col as uint) + + (1 as u8); + if self.next_color(row, col, the_color) { // yes: advance work list ptr = ptr + 1u; } else { @@ -134,18 +141,22 @@ impl Sudoku { // find first remaining color that is available let next = avail.next(); - self.grid[row][col] = next; + *self.grid.get_mut(row as uint).get_mut(col as uint) = next; return 0u8 != next; } - self.grid[row][col] = 0u8; + *self.grid.get_mut(row as uint).get_mut(col as uint) = 0u8; return false; } // find colors available in neighbourhood of (row, col) fn drop_colors(&mut self, avail: &mut Colors, row: u8, col: u8) { for idx in range(0u8, 9u8) { - avail.remove(self.grid[idx][col]); /* check same column fields */ - avail.remove(self.grid[row][idx]); /* check same row fields */ + avail.remove(*self.grid + .get(idx as uint) + .get(col as uint)); /* check same column fields */ + avail.remove(*self.grid + .get(row as uint) + .get(idx as uint)); /* check same row fields */ } // check same block fields @@ -153,7 +164,9 @@ impl Sudoku { let col0 = (col / 3u8) * 3u8; for alt_row in range(row0, row0 + 3u8) { for alt_col in range(col0, col0 + 3u8) { - avail.remove(self.grid[alt_row][alt_col]); + avail.remove(*self.grid + .get(alt_row as uint) + .get(alt_col as uint)); } } } diff --git a/src/test/bench/task-perf-alloc-unwind.rs b/src/test/bench/task-perf-alloc-unwind.rs index d4f9d0572b0fe..78c282b98cc78 100644 --- a/src/test/bench/task-perf-alloc-unwind.rs +++ b/src/test/bench/task-perf-alloc-unwind.rs @@ -17,6 +17,8 @@ use collections::list::{List, Cons, Nil}; use time::precise_time_s; use std::os; use std::task; +use std::vec_ng::Vec; +use std::vec_ng; enum UniqueList { ULNil, ULCons(~UniqueList) @@ -50,7 +52,7 @@ struct State { managed: @nillist, unique: ~nillist, tuple: (@nillist, ~nillist), - vec: ~[@nillist], + vec: Vec<@nillist>, res: r } @@ -82,7 +84,7 @@ fn recurse_or_fail(depth: int, st: Option) { managed: @Nil, unique: ~Nil, tuple: (@Nil, ~Nil), - vec: ~[@Nil], + vec: vec!(@Nil), res: r(@Nil) } } @@ -92,7 +94,8 @@ fn recurse_or_fail(depth: int, st: Option) { unique: ~Cons((), @*st.unique), tuple: (@Cons((), st.tuple.ref0().clone()), ~Cons((), @*st.tuple.ref1().clone())), - vec: st.vec + &[@Cons((), *st.vec.last().unwrap())], + vec: vec_ng::append(st.vec.clone(), + &[@Cons((), *st.vec.last().unwrap())]), res: r(@Cons((), st.res._l)) } } diff --git a/src/test/bench/task-perf-jargon-metal-smoke.rs b/src/test/bench/task-perf-jargon-metal-smoke.rs index 98dde73e59679..62838ad1a347a 100644 --- a/src/test/bench/task-perf-jargon-metal-smoke.rs +++ b/src/test/bench/task-perf-jargon-metal-smoke.rs @@ -21,6 +21,7 @@ use std::comm; use std::os; use std::task; use std::uint; +use std::vec_ng::Vec; fn child_generation(gens_left: uint, c: comm::Chan<()>) { // This used to be O(n^2) in the number of generations that ever existed. @@ -41,15 +42,15 @@ fn child_generation(gens_left: uint, c: comm::Chan<()>) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"100000"] + vec!(~"", ~"100000") } else if args.len() <= 1 { - ~[~"", ~"100"] + vec!(~"", ~"100") } else { - args.clone() + args.clone().move_iter().collect() }; let (p,c) = Chan::new(); - child_generation(from_str::(args[1]).unwrap(), c); + child_generation(from_str::(*args.get(1)).unwrap(), c); if p.recv_opt().is_none() { fail!("it happened when we slumbered"); } diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index 5eb597ac9cdf7..dcd5df2b21cff 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -19,7 +19,7 @@ use std::vec; fn calc(children: uint, parent_wait_chan: &Chan>>) { - let wait_ports: ~[Port>>] = vec::from_fn(children, |_| { + let wait_ports: Vec>>> = vec::from_fn(children, |_| { let (wait_port, wait_chan) = stream::>>(); task::spawn(proc() { calc(children / 2, &wait_chan); @@ -27,14 +27,14 @@ fn calc(children: uint, parent_wait_chan: &Chan>>) { wait_port }); - let child_start_chans: ~[Chan>] = + let child_start_chans: Vec>> = wait_ports.move_iter().map(|port| port.recv()).collect(); let (start_port, start_chan) = stream::>(); parent_wait_chan.send(start_chan); let parent_result_chan: Chan = start_port.recv(); - let child_sum_ports: ~[Port] = + let child_sum_ports: Vec> = child_start_chans.move_iter().map(|child_start_chan| { let (child_sum_port, child_sum_chan) = stream::(); child_start_chan.send(child_sum_chan); @@ -49,9 +49,9 @@ fn calc(children: uint, parent_wait_chan: &Chan>>) { fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"30"] + vec!(~"", ~"30") } else if args.len() <= 1u { - ~[~"", ~"10"] + vec!(~"", ~"10") } else { args }; diff --git a/src/test/bench/task-perf-spawnalot.rs b/src/test/bench/task-perf-spawnalot.rs index e322aceb5e661..c5da4a4359364 100644 --- a/src/test/bench/task-perf-spawnalot.rs +++ b/src/test/bench/task-perf-spawnalot.rs @@ -11,6 +11,7 @@ use std::os; use std::task; use std::uint; +use std::vec_ng::Vec; fn f(n: uint) { let mut i = 0u; @@ -25,13 +26,13 @@ fn g() { } fn main() { let args = os::args(); let args = if os::getenv("RUST_BENCH").is_some() { - ~[~"", ~"400"] + vec!(~"", ~"400") } else if args.len() <= 1u { - ~[~"", ~"10"] + vec!(~"", ~"10") } else { - args + args.move_iter().collect() }; - let n = from_str::(args[1]).unwrap(); + let n = from_str::(*args.get(1)).unwrap(); let mut i = 0u; while i < n { task::spawn(proc() f(n) ); i += 1u; } } diff --git a/src/test/compile-fail/access-mode-in-closures.rs b/src/test/compile-fail/access-mode-in-closures.rs index ef853f57ef5e1..8dbf292277be9 100644 --- a/src/test/compile-fail/access-mode-in-closures.rs +++ b/src/test/compile-fail/access-mode-in-closures.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; -struct sty(~[int]); +struct sty(Vec ); -fn unpack(_unpack: |v: &sty| -> ~[int]) {} +fn unpack(_unpack: |v: &sty| -> Vec ) {} fn main() { let _foo = unpack(|s| { diff --git a/src/test/compile-fail/ambig_impl_unify.rs b/src/test/compile-fail/ambig_impl_unify.rs index 1327f69630b1b..24a4c9863f76e 100644 --- a/src/test/compile-fail/ambig_impl_unify.rs +++ b/src/test/compile-fail/ambig_impl_unify.rs @@ -8,19 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + trait foo { fn foo(&self) -> int; } -impl foo for ~[uint] { - fn foo(&self) -> int {1} //~ NOTE candidate #1 is `~[uint].foo::foo` +impl foo for Vec { + fn foo(&self) -> int {1} //~ NOTE candidate #1 is `Vec.foo::foo` } -impl foo for ~[int] { - fn foo(&self) -> int {2} //~ NOTE candidate #2 is `~[int].foo::foo` +impl foo for Vec { + fn foo(&self) -> int {2} //~ NOTE candidate #2 is `Vec.foo::foo` } fn main() { - let x = ~[]; + let x = Vec::new(); x.foo(); //~ ERROR multiple applicable methods in scope } diff --git a/src/test/compile-fail/auto-ref-slice-plus-ref.rs b/src/test/compile-fail/auto-ref-slice-plus-ref.rs index 6a0f5a39202a9..8810421f6c412 100644 --- a/src/test/compile-fail/auto-ref-slice-plus-ref.rs +++ b/src/test/compile-fail/auto-ref-slice-plus-ref.rs @@ -17,7 +17,7 @@ fn main() { // reference. That would allow creating a mutable pointer to a // temporary, which would be a source of confusion - let mut a = ~[0]; + let mut a = vec!(0); a.test_mut(); //~ ERROR does not implement any method in scope named `test_mut` } diff --git a/src/test/compile-fail/bad-expr-path.rs b/src/test/compile-fail/bad-expr-path.rs index c17baf40d6446..6e73427f80f95 100644 --- a/src/test/compile-fail/bad-expr-path.rs +++ b/src/test/compile-fail/bad-expr-path.rs @@ -12,4 +12,4 @@ mod m1 {} -fn main(args: ~[str]) { log(debug, m1::a); } +fn main(args: Vec<~str>) { log(debug, m1::a); } diff --git a/src/test/compile-fail/bad-expr-path2.rs b/src/test/compile-fail/bad-expr-path2.rs index 936f893ae8e66..d2b3a57868683 100644 --- a/src/test/compile-fail/bad-expr-path2.rs +++ b/src/test/compile-fail/bad-expr-path2.rs @@ -14,4 +14,6 @@ mod m1 { pub mod a {} } -fn main(args: ~[str]) { log(debug, m1::a); } +fn main(args: Vec<~str>) { + log(debug, m1::a); +} diff --git a/src/test/compile-fail/bad-module.rs b/src/test/compile-fail/bad-module.rs index 90164c52bc757..edc118cb0399b 100644 --- a/src/test/compile-fail/bad-module.rs +++ b/src/test/compile-fail/bad-module.rs @@ -10,4 +10,4 @@ // error-pattern: unresolved name -fn main() { let foo = thing::len(~[]); } +fn main() { let foo = thing::len(Vec::new()); } diff --git a/src/test/compile-fail/borrowck-assign-comp-idx.rs b/src/test/compile-fail/borrowck-assign-comp-idx.rs index dec248a3015d5..8c0826a329965 100644 --- a/src/test/compile-fail/borrowck-assign-comp-idx.rs +++ b/src/test/compile-fail/borrowck-assign-comp-idx.rs @@ -14,12 +14,12 @@ struct Point { } fn a() { - let mut p = ~[1]; + let mut p = vec!(1); // Create an immutable pointer into p's contents: - let q: &int = &p[0]; + let q: &int = p.get(0); - p[0] = 5; //~ ERROR cannot assign + *p.get_mut(0) = 5; //~ ERROR cannot borrow info!("{}", *q); } @@ -30,19 +30,19 @@ fn b() { // here we alias the mutable vector into an imm slice and try to // modify the original: - let mut p = ~[1]; + let mut p = vec!(1); borrow( - p, - || p[0] = 5); //~ ERROR cannot borrow `p` as mutable + p.as_slice(), + || *p.get_mut(0) = 5); //~ ERROR cannot borrow `p` as mutable } fn c() { // Legal because the scope of the borrow does not include the // modification: - let mut p = ~[1]; - borrow(p, ||{}); - p[0] = 5; + let mut p = vec!(1); + borrow(p.as_slice(), ||{}); + *p.get_mut(0) = 5; } fn main() { diff --git a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs index 646ec69286304..f4d7f3ab77ed0 100644 --- a/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs +++ b/src/test/compile-fail/borrowck-borrowed-uniq-rvalue-2.rs @@ -28,6 +28,7 @@ fn defer<'r>(x: &'r [&'r str]) -> defer<'r> { } fn main() { - let x = defer(~["Goodbye", "world!"]); //~ ERROR borrowed value does not live long enough + let x = defer(vec!("Goodbye", "world!").as_slice()); + //~^ ERROR borrowed value does not live long enough x.x[0]; } diff --git a/src/test/compile-fail/borrowck-init-op-equal.rs b/src/test/compile-fail/borrowck-init-op-equal.rs index cbe805551c200..8d4cb6714bcb0 100644 --- a/src/test/compile-fail/borrowck-init-op-equal.rs +++ b/src/test/compile-fail/borrowck-init-op-equal.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn test() { let v: int; v += 1; //~ ERROR use of possibly uninitialized variable: `v` diff --git a/src/test/compile-fail/borrowck-loan-vec-content.rs b/src/test/compile-fail/borrowck-loan-vec-content.rs index 0e721d7107f8b..393b528869a94 100644 --- a/src/test/compile-fail/borrowck-loan-vec-content.rs +++ b/src/test/compile-fail/borrowck-loan-vec-content.rs @@ -17,16 +17,16 @@ fn takes_imm_elt(_v: &int, f: ||) { } fn has_mut_vec_and_does_not_try_to_change_it() { - let mut v = ~[1, 2, 3]; - takes_imm_elt(&v[0], || {}) + let mut v = vec!(1, 2, 3); + takes_imm_elt(v.get(0), || {}) } fn has_mut_vec_but_tries_to_change_it() { - let mut v = ~[1, 2, 3]; + let mut v = vec!(1, 2, 3); takes_imm_elt( - &v[0], + v.get(0), || { //~ ERROR cannot borrow `v` as mutable - v[1] = 4; + *v.get_mut(1) = 4; }) } diff --git a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs index 67b83ee84e406..0ab71c7f8a5c9 100644 --- a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs +++ b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs @@ -16,12 +16,12 @@ struct Foo { } pub fn main() { - let x = ~[ + let x = vec!( Foo { string: ~"foo" }, Foo { string: ~"bar" }, Foo { string: ~"baz" } - ]; - let x: &[Foo] = x; + ); + let x: &[Foo] = x.as_slice(); match x { [_, ..tail] => { match tail { diff --git a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs index ec17976c5065c..283d6398e9ad3 100644 --- a/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs +++ b/src/test/compile-fail/borrowck-mut-slice-of-imm-vec.rs @@ -13,6 +13,6 @@ fn write(v: &mut [int]) { } fn main() { - let v = ~[1, 2, 3]; - write(v); //~ ERROR cannot borrow + let v = vec!(1, 2, 3); + write(v.as_mut_slice()); //~ ERROR cannot borrow } diff --git a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs index 00252069f2dd8..3da284175541d 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-element-loan.rs @@ -9,8 +9,8 @@ // except according to those terms. fn a() -> &[int] { - let vec = ~[1, 2, 3, 4]; - let vec: &[int] = vec; //~ ERROR does not live long enough + let vec = vec!(1, 2, 3, 4); + let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough let tail = match vec { [_, ..tail] => tail, _ => fail!("a") @@ -19,8 +19,8 @@ fn a() -> &[int] { } fn b() -> &[int] { - let vec = ~[1, 2, 3, 4]; - let vec: &[int] = vec; //~ ERROR does not live long enough + let vec = vec!(1, 2, 3, 4); + let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough let init = match vec { [..init, _] => init, _ => fail!("b") @@ -29,8 +29,8 @@ fn b() -> &[int] { } fn c() -> &[int] { - let vec = ~[1, 2, 3, 4]; - let vec: &[int] = vec; //~ ERROR does not live long enough + let vec = vec!(1, 2, 3, 4); + let vec: &[int] = vec.as_slice(); //~ ERROR does not live long enough let slice = match vec { [_, ..slice, _] => slice, _ => fail!("c") diff --git a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs index d3f23a3497819..393ec8b0b1b3b 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-loan-from-mut.rs @@ -9,8 +9,8 @@ // except according to those terms. fn a() { - let mut v = ~[1, 2, 3]; - let vb: &mut [int] = v; + let mut v = vec!(1, 2, 3); + let vb: &mut [int] = v.as_mut_slice(); match vb { [_a, ..tail] => { v.push(tail[0] + tail[1]); //~ ERROR cannot borrow diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index b85c2a82aeaff..e96ccd2aa8b20 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -18,8 +18,8 @@ fn a() { } fn b() { - let mut vec = ~[~1, ~2, ~3]; - let vec: &mut [~int] = vec; + let mut vec = vec!(~1, ~2, ~3); + let vec: &mut [~int] = vec.as_mut_slice(); match vec { [.._b] => { vec[0] = ~4; //~ ERROR cannot assign @@ -28,8 +28,8 @@ fn b() { } fn c() { - let mut vec = ~[~1, ~2, ~3]; - let vec: &mut [~int] = vec; + let mut vec = vec!(~1, ~2, ~3); + let vec: &mut [~int] = vec.as_mut_slice(); match vec { [_a, .._b] => { //~^ ERROR cannot move out @@ -46,8 +46,8 @@ fn c() { } fn d() { - let mut vec = ~[~1, ~2, ~3]; - let vec: &mut [~int] = vec; + let mut vec = vec!(~1, ~2, ~3); + let vec: &mut [~int] = vec.as_mut_slice(); match vec { [.._a, _b] => { //~^ ERROR cannot move out @@ -58,8 +58,8 @@ fn d() { } fn e() { - let mut vec = ~[~1, ~2, ~3]; - let vec: &mut [~int] = vec; + let mut vec = vec!(~1, ~2, ~3); + let vec: &mut [~int] = vec.as_mut_slice(); match vec { [_a, _b, _c] => {} //~ ERROR cannot move out //~^ ERROR cannot move out diff --git a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs index ea972e8238aac..26dc853859c92 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-tail-element-loan.rs @@ -9,8 +9,8 @@ // except according to those terms. fn a() -> &int { - let vec = ~[1, 2, 3, 4]; - let vec: &[int] = vec; //~ ERROR `vec[..]` does not live long enough + let vec = vec!(1, 2, 3, 4); + let vec: &[int] = vec.as_slice(); //~ ERROR `vec` does not live long enough let tail = match vec { [_a, ..tail] => &tail[0], _ => fail!("foo") diff --git a/src/test/compile-fail/drop-on-non-struct.rs b/src/test/compile-fail/drop-on-non-struct.rs index 0d01fe4e8c732..09274aaa50445 100644 --- a/src/test/compile-fail/drop-on-non-struct.rs +++ b/src/test/compile-fail/drop-on-non-struct.rs @@ -10,10 +10,13 @@ #[feature(managed_boxes)]; -type Foo = ~[u8]; +use std::vec_ng::Vec; -impl Drop for Foo { //~ ERROR the Drop trait may only be implemented +type Foo = Vec; + +impl Drop for Foo { //~ ERROR conflicting implementations //~^ ERROR cannot provide an extension implementation +//~^^ ERROR multiple applicable methods fn drop(&mut self) { println!("kaboom"); } diff --git a/src/test/compile-fail/empty-vec-trailing-comma.rs b/src/test/compile-fail/empty-vec-trailing-comma.rs deleted file mode 100644 index 9191c866afd33..0000000000000 --- a/src/test/compile-fail/empty-vec-trailing-comma.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn main() { - let v = ~[,]; //~ ERROR unexpected token: `,` -} diff --git a/src/test/compile-fail/evec-subtyping.rs b/src/test/compile-fail/evec-subtyping.rs deleted file mode 100644 index 9a0227b7d31a2..0000000000000 --- a/src/test/compile-fail/evec-subtyping.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[feature(managed_boxes)]; - -fn wants_uniq(x: ~[uint]) { } -fn wants_three(x: [uint, ..3]) { } - -fn has_uniq(x: ~[uint]) { - wants_uniq(x); - wants_three(x); //~ ERROR [] storage differs: expected `3` but found `~` -} - -fn has_three(x: [uint, ..3]) { - wants_uniq(x); //~ ERROR [] storage differs: expected `~` but found `3` - wants_three(x); -} - -fn has_four(x: [uint, ..4]) { - wants_uniq(x); //~ ERROR [] storage differs: expected `~` but found `4` - wants_three(x); //~ ERROR [] storage differs: expected `3` but found `4` -} - -fn main() { -} diff --git a/src/test/compile-fail/import.rs b/src/test/compile-fail/import.rs index 5177dc4e47570..51d3d652f7b13 100644 --- a/src/test/compile-fail/import.rs +++ b/src/test/compile-fail/import.rs @@ -11,7 +11,10 @@ // error-pattern:failed to resolve import use zed::bar; use zed::baz; + +use std::vec_ng::Vec; + mod zed { pub fn bar() { info!("bar"); } } -fn main(args: ~[str]) { bar(); } +fn main(args: Vec<~str>) { bar(); } diff --git a/src/test/compile-fail/import2.rs b/src/test/compile-fail/import2.rs index e67a79130b1f9..fd0892f19e259 100644 --- a/src/test/compile-fail/import2.rs +++ b/src/test/compile-fail/import2.rs @@ -11,8 +11,10 @@ use baz::zed::bar; //~ ERROR unresolved import //~^ ERROR failed to resolve import +use std::vec_ng::Vec; + mod baz {} mod zed { pub fn bar() { info!("bar3"); } } -fn main(args: ~[str]) { bar(); } +fn main(args: Vec<~str>) { bar(); } diff --git a/src/test/compile-fail/import3.rs b/src/test/compile-fail/import3.rs index 7a7f4f20aea07..f801760a7db89 100644 --- a/src/test/compile-fail/import3.rs +++ b/src/test/compile-fail/import3.rs @@ -11,4 +11,6 @@ // error-pattern: unresolved use main::bar; -fn main(args: ~[str]) { info!("foo"); } +use std::vec_ng::Vec; + +fn main(args: Vec<~str>) { info!("foo"); } diff --git a/src/test/compile-fail/import4.rs b/src/test/compile-fail/import4.rs index 087842d78c709..6005a1c22fac8 100644 --- a/src/test/compile-fail/import4.rs +++ b/src/test/compile-fail/import4.rs @@ -10,7 +10,9 @@ // error-pattern: import +use std::vec_ng::Vec; + mod a { pub use b::foo; } mod b { pub use a::foo; } -fn main(args: ~[str]) { info!("loop"); } +fn main(args: Vec<~str>) { info!("loop"); } diff --git a/src/test/compile-fail/infinite-vec-type-recursion.rs b/src/test/compile-fail/infinite-vec-type-recursion.rs index 9f9fd43fcdf80..c52199ecedd38 100644 --- a/src/test/compile-fail/infinite-vec-type-recursion.rs +++ b/src/test/compile-fail/infinite-vec-type-recursion.rs @@ -10,6 +10,8 @@ // error-pattern: illegal recursive type -type x = ~[x]; +use std::vec_ng::Vec; -fn main() { let b: x = ~[]; } +type x = Vec; + +fn main() { let b: x = Vec::new(); } diff --git a/src/test/compile-fail/issue-10412.rs b/src/test/compile-fail/issue-10412.rs index 79af6617ab341..e0bac1e9e4a60 100644 --- a/src/test/compile-fail/issue-10412.rs +++ b/src/test/compile-fail/issue-10412.rs @@ -10,13 +10,13 @@ trait Serializable<'self, T> { //~ ERROR: no longer a special lifetime - fn serialize(val : &'self T) -> ~[u8]; + fn serialize(val : &'self T) -> Vec ; fn deserialize(repr : &[u8]) -> &'self T; } impl<'self> Serializable for &'self str { - fn serialize(val : &'self str) -> ~[u8] { - ~[1] + fn serialize(val : &'self str) -> Vec { + vec!(1) } fn deserialize(repr: &[u8]) -> &'self str { "hi" diff --git a/src/test/compile-fail/issue-10487.rs b/src/test/compile-fail/issue-10487.rs deleted file mode 100644 index 01fb2ea942737..0000000000000 --- a/src/test/compile-fail/issue-10487.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[feature(managed_boxes)]; - -static x: ~[int] = ~[123, 456]; //~ ERROR: static items are not allowed to have owned pointers - -fn main() {} diff --git a/src/test/compile-fail/issue-1655.rs b/src/test/compile-fail/issue-1655.rs index 37cfc642405dd..88233e62aa749 100644 --- a/src/test/compile-fail/issue-1655.rs +++ b/src/test/compile-fail/issue-1655.rs @@ -10,12 +10,12 @@ // error-pattern:expected item mod blade_runner { - #~[doc( + #vec!(doc( brief = "Blade Runner is probably the best movie ever", desc = "I like that in the world of Blade Runner it is always raining, and that it's always night time. And Aliens was also a really good movie. Alien 3 was crap though." - )] + )) } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 8d2bdd2d2eb36..29f7e344b3093 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -8,12 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + trait vec_monad { - fn bind(&self, f: |A| -> ~[B]); + fn bind(&self, f: |A| -> Vec ); } -impl vec_monad for ~[A] { - fn bind(&self, f: |A| -> ~[B]) { +impl vec_monad for Vec { + fn bind(&self, f: |A| -> Vec ) { let mut r = fail!(); for elt in self.iter() { r = r + f(*elt); } //~^ ERROR the type of this value must be known diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index 2c54b62202115..341fafe6f636f 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -12,7 +12,9 @@ #[allow(unused_variable)]; #[allow(dead_code)]; -fn fail_len(v: ~[int]) -> uint { +use std::vec_ng::Vec; + +fn fail_len(v: Vec ) -> uint { let mut i = 3; fail!(); for x in v.iter() { i += 1u; } diff --git a/src/test/compile-fail/issue-2281-part1.rs b/src/test/compile-fail/issue-2281-part1.rs index 7896d91443dad..68ded64820713 100644 --- a/src/test/compile-fail/issue-2281-part1.rs +++ b/src/test/compile-fail/issue-2281-part1.rs @@ -10,4 +10,6 @@ // error-pattern: unresolved name `foobar`. -fn main(args: ~[str]) { info!("{:?}", foobar); } +use std::vec_ng::Vec; + +fn main(args: Vec) { info!("{:?}", foobar); } diff --git a/src/test/compile-fail/issue-2548.rs b/src/test/compile-fail/issue-2548.rs deleted file mode 100644 index 19bd9b2476b04..0000000000000 --- a/src/test/compile-fail/issue-2548.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[feature(managed_boxes)]; - -// A test case for #2548. - -use std::cell::Cell; - -struct foo { - x: @Cell, -} - -#[unsafe_destructor] -impl Drop for foo { - fn drop(&mut self) { - unsafe { - println!("Goodbye, World!"); - self.x.set(self.x.get() + 1); - } - } -} - -fn foo(x: @Cell) -> foo { - foo { x: x } -} - -fn main() { - let x = @Cell::new(0); - - { - let mut res = foo(x); - - let mut v = ~[]; - v = ~[(res)] + v; //~ failed to find an implementation of trait - assert_eq!(v.len(), 2); - } - - assert_eq!(x.get(), 1); -} diff --git a/src/test/compile-fail/issue-2590.rs b/src/test/compile-fail/issue-2590.rs index a2bb583a3d698..a3f2da150a3c4 100644 --- a/src/test/compile-fail/issue-2590.rs +++ b/src/test/compile-fail/issue-2590.rs @@ -8,16 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + struct parser { - tokens: ~[int], + tokens: Vec , } trait parse { - fn parse(&self) -> ~[int]; + fn parse(&self) -> Vec ; } impl parse for parser { - fn parse(&self) -> ~[int] { + fn parse(&self) -> Vec { self.tokens //~ ERROR cannot move out of dereference of `&`-pointer } } diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index 5fab2ed195cec..076c60152684d 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn main() { - let needlesArr: ~[char] = ~['a', 'f']; + let needlesArr: Vec = vec!('a', 'f'); needlesArr.iter().fold(|x, y| { }); //~^^ ERROR this function takes 2 parameters but 1 parameter was supplied diff --git a/src/test/compile-fail/issue-7573.rs b/src/test/compile-fail/issue-7573.rs index 3b8eda8f78388..633be15ef9922 100644 --- a/src/test/compile-fail/issue-7573.rs +++ b/src/test/compile-fail/issue-7573.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + pub struct CrateId { local_path: ~str, junk: ~str @@ -23,7 +25,7 @@ impl CrateId { } pub fn remove_package_from_database() { - let mut lines_to_use: ~[&CrateId] = ~[]; //~ ERROR cannot infer an appropriate lifetime + let mut lines_to_use: Vec<&CrateId> = Vec::new(); //~ ERROR cannot infer an appropriate lifetime let push_id = |installed_id: &CrateId| { lines_to_use.push(installed_id); }; diff --git a/src/test/compile-fail/issue-8727.rs b/src/test/compile-fail/issue-8727.rs index 003f1d67cdb8a..e018bf4077182 100644 --- a/src/test/compile-fail/issue-8727.rs +++ b/src/test/compile-fail/issue-8727.rs @@ -8,21 +8,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - // Verify the compiler fails with an error on infinite function // recursions. +use std::vec_ng::Vec; + struct Data(~Option); -fn generic( _ : ~[(Data,T)] ) { +fn generic( _ : Vec<(Data,T)> ) { //~^ ERROR overly deep expansion of inlined function - let rec : ~[(Data,(bool,T))] = ~[]; + let rec : Vec<(Data,(bool,T))> = Vec::new(); generic( rec ); } fn main () { // Use generic at least once to trigger instantiation. - let input : ~[(Data,())] = ~[]; + let input : Vec<(Data,())> = Vec::new(); generic(input); } diff --git a/src/test/compile-fail/kindck-freeze.rs b/src/test/compile-fail/kindck-freeze.rs index 474c1b1d3cfa4..c5977678aba11 100644 --- a/src/test/compile-fail/kindck-freeze.rs +++ b/src/test/compile-fail/kindck-freeze.rs @@ -10,6 +10,8 @@ // Test which of the builtin types are considered freezeable. +use std::vec_ng::Vec; + fn assert_freeze() { } trait Dummy { } @@ -27,7 +29,7 @@ fn test<'a,T,U:Freeze>(_: &'a int) { // ~ pointers are ok assert_freeze::<~int>(); assert_freeze::<~str>(); - assert_freeze::<~[int]>(); + assert_freeze:: >(); // but not if they own a bad thing assert_freeze::<~&'a mut int>(); //~ ERROR does not fulfill `Freeze` diff --git a/src/test/compile-fail/kindck-pod.rs b/src/test/compile-fail/kindck-pod.rs index 60de67e214c0c..bc4ee14d89eb5 100644 --- a/src/test/compile-fail/kindck-pod.rs +++ b/src/test/compile-fail/kindck-pod.rs @@ -13,6 +13,7 @@ #[feature(managed_boxes)]; use std::rc::Rc; +use std::vec_ng::Vec; fn assert_pod() { } trait Dummy { } @@ -40,7 +41,7 @@ fn test<'a,T,U:Pod>(_: &'a int) { // ~ pointers are not ok assert_pod::<~int>(); //~ ERROR does not fulfill `Pod` assert_pod::<~str>(); //~ ERROR does not fulfill `Pod` - assert_pod::<~[int]>(); //~ ERROR does not fulfill `Pod` + assert_pod:: >(); //~ ERROR does not fulfill `Pod` assert_pod::<~&'a mut int>(); //~ ERROR does not fulfill `Pod` // borrowed object types are generally ok diff --git a/src/test/compile-fail/kindck-send.rs b/src/test/compile-fail/kindck-send.rs index bfef15ea1731c..0eb3656cea787 100644 --- a/src/test/compile-fail/kindck-send.rs +++ b/src/test/compile-fail/kindck-send.rs @@ -10,6 +10,8 @@ // Test which of the builtin types are considered sendable. +use std::vec_ng::Vec; + fn assert_send() { } trait Dummy { } @@ -30,7 +32,7 @@ fn test<'a,T,U:Send>(_: &'a int) { // ~ pointers are ok assert_send::<~int>(); assert_send::<~str>(); - assert_send::<~[int]>(); + assert_send:: >(); // but not if they own a bad thing assert_send::<~&'a int>(); //~ ERROR does not fulfill `Send` diff --git a/src/test/compile-fail/lint-heap-memory.rs b/src/test/compile-fail/lint-heap-memory.rs index fa359dcd538f7..853abbbd295f2 100644 --- a/src/test/compile-fail/lint-heap-memory.rs +++ b/src/test/compile-fail/lint-heap-memory.rs @@ -24,8 +24,6 @@ fn main() { @2; //~ ERROR type uses managed ~2; //~ ERROR type uses owned - ~[1]; //~ ERROR type uses owned - //~^ ERROR type uses owned fn g(_: ~Clone) {} //~ ERROR type uses owned ~""; //~ ERROR type uses owned //~^ ERROR type uses owned diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 271aedd3f6a6b..47c0bf99afca7 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -15,12 +15,14 @@ #[allow(dead_code)]; #[deny(unused_mut)]; +use std::vec_ng::Vec; + fn main() { // negative cases let mut a = 3; //~ ERROR: variable does not need to be mutable let mut a = 2; //~ ERROR: variable does not need to be mutable let mut b = 3; //~ ERROR: variable does not need to be mutable - let mut a = ~[3]; //~ ERROR: variable does not need to be mutable + let mut a = vec!(3); //~ ERROR: variable does not need to be mutable let (mut a, b) = (1, 2); //~ ERROR: variable does not need to be mutable match 30 { @@ -33,9 +35,9 @@ fn main() { // positive cases let mut a = 2; a = 3; - let mut a = ~[]; + let mut a = Vec::new(); a.push(3); - let mut a = ~[]; + let mut a = Vec::new(); callback(|| { a.push(3); }); @@ -62,5 +64,5 @@ fn callback(f: ||) {} #[allow(unused_mut)] fn foo(mut a: int) { let mut a = 3; - let mut b = ~[2]; + let mut b = vec!(2); } diff --git a/src/test/compile-fail/lint-unused-unsafe.rs b/src/test/compile-fail/lint-unused-unsafe.rs index 96a4c2adca32c..084f0d1dab8cb 100644 --- a/src/test/compile-fail/lint-unused-unsafe.rs +++ b/src/test/compile-fail/lint-unused-unsafe.rs @@ -13,6 +13,8 @@ #[allow(dead_code)]; #[deny(unused_unsafe)]; +use std::vec_ng::Vec; + mod foo { extern { pub fn bar(); @@ -49,7 +51,7 @@ fn good2() { sure that when purity is inherited that the source of the unsafe-ness is tracked correctly */ unsafe { - unsafe fn what() -> ~[~str] { fail!() } + unsafe fn what() -> Vec<~str> { fail!() } callback(|| { what(); diff --git a/src/test/compile-fail/liveness-issue-2163.rs b/src/test/compile-fail/liveness-issue-2163.rs index fbb6d03b22002..3a8b90cad3d52 100644 --- a/src/test/compile-fail/liveness-issue-2163.rs +++ b/src/test/compile-fail/liveness-issue-2163.rs @@ -9,9 +9,10 @@ // except according to those terms. use std::vec; +use std::vec_ng::Vec; fn main() { - let a: ~[int] = ~[]; + let a: Vec = Vec::new(); a.iter().advance(|_| -> bool { //~^ ERROR mismatched types }); diff --git a/src/test/compile-fail/match-vec-invalid.rs b/src/test/compile-fail/match-vec-invalid.rs index 5a50cb48da665..389e26aa400dc 100644 --- a/src/test/compile-fail/match-vec-invalid.rs +++ b/src/test/compile-fail/match-vec-invalid.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let a = ~[]; + let a = Vec::new(); match a { [1, ..tail, ..tail] => {}, //~ ERROR: unexpected token: `..` _ => () diff --git a/src/test/compile-fail/match-vec-unreachable.rs b/src/test/compile-fail/match-vec-unreachable.rs index e2a052bd2638e..06e6609e46fb6 100644 --- a/src/test/compile-fail/match-vec-unreachable.rs +++ b/src/test/compile-fail/match-vec-unreachable.rs @@ -8,25 +8,27 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn main() { - let x: ~[(int, int)] = ~[]; - let x: &[(int, int)] = x; + let x: Vec<(int, int)> = Vec::new(); + let x: &[(int, int)] = x.as_slice(); match x { [a, (2, 3), _] => (), [(1, 2), (2, 3), b] => (), //~ ERROR unreachable pattern _ => () } - let x: ~[~str] = ~[~"foo", ~"bar", ~"baz"]; - let x: &[~str] = x; + let x: Vec<~str> = vec!(~"foo", ~"bar", ~"baz"); + let x: &[~str] = x.as_slice(); match x { [a, _, _, ..] => { println!("{}", a); } [~"foo", ~"bar", ~"baz", ~"foo", ~"bar"] => { } //~ ERROR unreachable pattern _ => { } } - let x: ~[char] = ~['a', 'b', 'c']; - let x: &[char] = x; + let x: Vec = vec!('a', 'b', 'c'); + let x: &[char] = x.as_slice(); match x { ['a', 'b', 'c', .._tail] => {} ['a', 'b', 'c'] => {} //~ ERROR unreachable pattern diff --git a/src/test/compile-fail/moves-based-on-type-access-to-field.rs b/src/test/compile-fail/moves-based-on-type-access-to-field.rs index 1557b290c2cb1..657d5ad03e8a8 100644 --- a/src/test/compile-fail/moves-based-on-type-access-to-field.rs +++ b/src/test/compile-fail/moves-based-on-type-access-to-field.rs @@ -22,9 +22,9 @@ fn f10() { } fn f20() { - let x = ~[~"hi"]; - consume(x[0]); - touch(&x[0]); //~ ERROR use of partially moved value: `x` + let x = vec!(~"hi"); + consume(x.move_iter().next().unwrap()); + touch(x.get(0)); //~ ERROR use of moved value: `x` } fn main() {} diff --git a/src/test/compile-fail/moves-based-on-type-exprs.rs b/src/test/compile-fail/moves-based-on-type-exprs.rs index 4c62e47965e08..967612e7c5016 100644 --- a/src/test/compile-fail/moves-based-on-type-exprs.rs +++ b/src/test/compile-fail/moves-based-on-type-exprs.rs @@ -30,8 +30,8 @@ fn f20() { } fn f21() { - let x = ~[1, 2, 3]; - let _y = (x[0], 3); + let x = vec!(1, 2, 3); + let _y = (*x.get(0), 3); touch(&x); } @@ -78,27 +78,27 @@ fn f70() { fn f80() { let x = ~"hi"; - let _y = ~[x]; + let _y = vec!(x); touch(&x); //~ ERROR use of moved value: `x` } fn f100() { - let x = ~[~"hi"]; - let _y = x[0]; - touch(&x); //~ ERROR use of partially moved value: `x` + let x = vec!(~"hi"); + let _y = x.move_iter().next().unwrap(); + touch(&x); //~ ERROR use of moved value: `x` } fn f110() { - let x = ~[~"hi"]; - let _y = [x[0], ..1]; - touch(&x); //~ ERROR use of partially moved value: `x` + let x = vec!(~"hi"); + let _y = [x.move_iter().next().unwrap(), ..1]; + touch(&x); //~ ERROR use of moved value: `x` } fn f120() { - let mut x = ~[~"hi", ~"ho"]; + let mut x = vec!(~"hi", ~"ho"); x.swap(0, 1); - touch(&x[0]); - touch(&x[1]); + touch(x.get(0)); + touch(x.get(1)); } fn main() {} diff --git a/src/test/compile-fail/nested-ty-params.rs b/src/test/compile-fail/nested-ty-params.rs index daf92b700e7f3..7b7ce6bee2ffb 100644 --- a/src/test/compile-fail/nested-ty-params.rs +++ b/src/test/compile-fail/nested-ty-params.rs @@ -9,7 +9,7 @@ // except according to those terms. // error-pattern:attempt to use a type argument out of scope -fn hd(v: ~[U]) -> U { +fn hd(v: Vec ) -> U { fn hd1(w: [U]) -> U { return w[0]; } return hd1(v); diff --git a/src/test/compile-fail/no-capture-arc.rs b/src/test/compile-fail/no-capture-arc.rs index 8df156d8332fe..eb11cd4840f69 100644 --- a/src/test/compile-fail/no-capture-arc.rs +++ b/src/test/compile-fail/no-capture-arc.rs @@ -16,15 +16,15 @@ use sync::Arc; use std::task; fn main() { - let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); task::spawn(proc() { let v = arc_v.get(); - assert_eq!(v[3], 4); + assert_eq!(*v.get(3), 4); }); - assert_eq!((arc_v.get())[2], 3); + assert_eq!(*(arc_v.get()).get(2), 3); info!("{:?}", arc_v); } diff --git a/src/test/compile-fail/no-reuse-move-arc.rs b/src/test/compile-fail/no-reuse-move-arc.rs index b387d3a1719e9..d1326e9733b5f 100644 --- a/src/test/compile-fail/no-reuse-move-arc.rs +++ b/src/test/compile-fail/no-reuse-move-arc.rs @@ -14,15 +14,15 @@ use sync::Arc; use std::task; fn main() { - let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + let v = vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); let arc_v = Arc::new(v); task::spawn(proc() { let v = arc_v.get(); - assert_eq!(v[3], 4); + assert_eq!(*v.get(3), 4); }); - assert_eq!((arc_v.get())[2], 3); //~ ERROR use of moved value: `arc_v` + assert_eq!(*(arc_v.get()).get(2), 3); //~ ERROR use of moved value: `arc_v` info!("{:?}", arc_v); //~ ERROR use of moved value: `arc_v` } diff --git a/src/test/compile-fail/non-constant-enum-for-vec-repeat.rs b/src/test/compile-fail/non-constant-enum-for-vec-repeat.rs index a4eba4b4cbf77..fd857129c3569 100644 --- a/src/test/compile-fail/non-constant-enum-for-vec-repeat.rs +++ b/src/test/compile-fail/non-constant-enum-for-vec-repeat.rs @@ -11,6 +11,6 @@ enum State { ST_NULL, ST_WHITESPACE } fn main() { - ~[ST_NULL, ..(ST_WHITESPACE as uint)]; + [ST_NULL, ..(ST_WHITESPACE as uint)]; //~^ ERROR expected constant integer for repeat count but found variable } diff --git a/src/test/compile-fail/non-copyable-void.rs b/src/test/compile-fail/non-copyable-void.rs index 64d29a5575635..2b3722196c119 100644 --- a/src/test/compile-fail/non-copyable-void.rs +++ b/src/test/compile-fail/non-copyable-void.rs @@ -9,9 +9,10 @@ // except according to those terms. use std::libc; +use std::vec_ng::Vec; fn main() { - let x : *~[int] = &~[1,2,3]; + let x : *Vec = &vec!(1,2,3); let y : *libc::c_void = x as *libc::c_void; unsafe { let _z = (*y).clone(); diff --git a/src/test/compile-fail/non-exhaustive-match.rs b/src/test/compile-fail/non-exhaustive-match.rs index 0d65bc90eb546..a07fec853fc52 100644 --- a/src/test/compile-fail/non-exhaustive-match.rs +++ b/src/test/compile-fail/non-exhaustive-match.rs @@ -35,30 +35,30 @@ fn main() { (_, a) => {} (b, b) => {} } - let vec = ~[Some(42), None, Some(21)]; - let vec: &[Option] = vec; + let vec = vec!(Some(42), None, Some(21)); + let vec: &[Option] = vec.as_slice(); match vec { //~^ ERROR non-exhaustive patterns: vectors of length 0 not covered [Some(..), None, ..tail] => {} [Some(..), Some(..), ..tail] => {} [None] => {} } - let vec = ~[1]; - let vec: &[int] = vec; + let vec = vec!(1); + let vec: &[int] = vec.as_slice(); match vec { [_, ..tail] => (), [] => () } - let vec = ~[0.5]; - let vec: &[f32] = vec; + let vec = vec!(0.5); + let vec: &[f32] = vec.as_slice(); match vec { //~ ERROR non-exhaustive patterns: vectors of length 4 not covered [0.1, 0.2, 0.3] => (), [0.1, 0.2] => (), [0.1] => (), [] => () } - let vec = ~[Some(42), None, Some(21)]; - let vec: &[Option] = vec; + let vec = vec!(Some(42), None, Some(21)); + let vec: &[Option] = vec.as_slice(); match vec { [Some(..), None, ..tail] => {} [Some(..), Some(..), ..tail] => {} diff --git a/src/test/compile-fail/pattern-tyvar-2.rs b/src/test/compile-fail/pattern-tyvar-2.rs index e58c4b1468588..f80b250dd8264 100644 --- a/src/test/compile-fail/pattern-tyvar-2.rs +++ b/src/test/compile-fail/pattern-tyvar-2.rs @@ -8,10 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - extern crate extra; -enum bar { t1((), Option<~[int]>), t2, } +use std::vec_ng::Vec; + +enum bar { t1((), Option >), t2, } // n.b. my change changes this error message, but I think it's right -- tjc fn foo(t: bar) -> int { match t { t1(_, Some(x)) => { return x * 3; } _ => { fail!(); } } } diff --git a/src/test/compile-fail/pattern-tyvar.rs b/src/test/compile-fail/pattern-tyvar.rs index b687a225754e0..2545d7b929271 100644 --- a/src/test/compile-fail/pattern-tyvar.rs +++ b/src/test/compile-fail/pattern-tyvar.rs @@ -10,9 +10,11 @@ extern crate extra; +use std::vec_ng::Vec; + // error-pattern: mismatched types -enum bar { t1((), Option<~[int]>), t2, } +enum bar { t1((), Option >), t2, } fn foo(t: bar) { match t { diff --git a/src/test/compile-fail/qquote-1.rs b/src/test/compile-fail/qquote-1.rs index d45759e38d99e..fff57128c45ad 100644 --- a/src/test/compile-fail/qquote-1.rs +++ b/src/test/compile-fail/qquote-1.rs @@ -34,7 +34,7 @@ trait fake_ext_ctxt { type fake_session = parse::parse_sess; impl fake_ext_ctxt for fake_session { - fn cfg() -> ast::CrateConfig { ~[] } + fn cfg() -> ast::CrateConfig { Vec::new() } fn parse_sess() -> parse::parse_sess { self } fn call_site() -> span { codemap::span { diff --git a/src/test/compile-fail/qquote-2.rs b/src/test/compile-fail/qquote-2.rs index b5c2dee61c736..30cdb21d402b6 100644 --- a/src/test/compile-fail/qquote-2.rs +++ b/src/test/compile-fail/qquote-2.rs @@ -33,7 +33,7 @@ trait fake_ext_ctxt { type fake_session = parse::parse_sess; impl fake_ext_ctxt for fake_session { - fn cfg() -> ast::CrateConfig { ~[] } + fn cfg() -> ast::CrateConfig { Vec::new() } fn parse_sess() -> parse::parse_sess { self } fn call_site() -> span { codemap::span { diff --git a/src/test/compile-fail/regions-escape-loop-via-vec.rs b/src/test/compile-fail/regions-escape-loop-via-vec.rs index ccfcc52945daf..7d9629a522053 100644 --- a/src/test/compile-fail/regions-escape-loop-via-vec.rs +++ b/src/test/compile-fail/regions-escape-loop-via-vec.rs @@ -11,7 +11,7 @@ // The type of `y` ends up getting inferred to the type of the block. fn broken() { let mut x = 3; - let mut _y = ~[&mut x]; + let mut _y = vec!(&mut x); while x < 10 { let mut z = x; _y.push(&mut z); //~ ERROR `z` does not live long enough diff --git a/src/test/compile-fail/repeat_count.rs b/src/test/compile-fail/repeat_count.rs index 579575e2008f8..692c51b5b5ff7 100644 --- a/src/test/compile-fail/repeat_count.rs +++ b/src/test/compile-fail/repeat_count.rs @@ -12,5 +12,5 @@ fn main() { let n = 1; - let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable + let a = [0, ..n]; //~ ERROR expected constant integer for repeat count but found variable } diff --git a/src/test/compile-fail/seq-args.rs b/src/test/compile-fail/seq-args.rs index f543d442a2391..4e23e76b25520 100644 --- a/src/test/compile-fail/seq-args.rs +++ b/src/test/compile-fail/seq-args.rs @@ -9,10 +9,13 @@ // except according to those terms. extern crate extra; + +use std::vec_ng::Vec; + fn main() { trait seq { } -impl seq for ~[T] { //~ ERROR wrong number of type arguments +impl seq for Vec { //~ ERROR wrong number of type arguments /* ... */ } impl seq for u32 { diff --git a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs index 0fc3b3912b17b..59c80474c4c77 100644 --- a/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs +++ b/src/test/compile-fail/tag-that-dare-not-speak-its-name.rs @@ -13,7 +13,9 @@ #[no_implicit_prelude]; -fn last(v: ~[&T]) -> std::option::Option { +use std::vec_ng::Vec; + +fn last(v: Vec<&T> ) -> std::option::Option { fail!(); } diff --git a/src/test/compile-fail/uninstantiable-fixed-length-vec.rs b/src/test/compile-fail/uninstantiable-fixed-length-vec.rs deleted file mode 100644 index bb2c3247e030f..0000000000000 --- a/src/test/compile-fail/uninstantiable-fixed-length-vec.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// issue #11659, the compiler needs to know that a fixed length vector -// always requires instantiable contents to instantiable itself -// (unlike a ~[] vector which can have length zero). - -// ~ to avoid infinite size. -struct Uninstantiable { //~ ERROR cannot be instantiated without an instance of itself - p: ~[Uninstantiable, .. 1] -} - -struct Instantiable { p: ~[Instantiable, .. 0] } - - -fn main() { - let _ = None::; - let _ = Instantiable { p: ~([]) }; -} diff --git a/src/test/compile-fail/unique-vec-res.rs b/src/test/compile-fail/unique-vec-res.rs index c604e66507e0a..84e8272d7887c 100644 --- a/src/test/compile-fail/unique-vec-res.rs +++ b/src/test/compile-fail/unique-vec-res.rs @@ -11,6 +11,7 @@ #[feature(managed_boxes)]; use std::cell::Cell; +use std::vec_ng::Vec; struct r { i: @Cell, @@ -25,14 +26,14 @@ impl Drop for r { } } -fn f(_i: ~[T], _j: ~[T]) { +fn f(_i: Vec , _j: Vec ) { } fn main() { let i1 = @Cell::new(0); let i2 = @Cell::new(1); - let r1 = ~[~r { i: i1 }]; - let r2 = ~[~r { i: i2 }]; + let r1 = vec!(~r { i: i1 }); + let r2 = vec!(~r { i: i2 }); f(r1.clone(), r2.clone()); //~^ ERROR failed to find an implementation of info!("{:?}", (r2, i1.get())); diff --git a/src/test/compile-fail/use-after-move-implicity-coerced-object.rs b/src/test/compile-fail/use-after-move-implicity-coerced-object.rs index 085ed5db6df09..4dd3b26bad966 100644 --- a/src/test/compile-fail/use-after-move-implicity-coerced-object.rs +++ b/src/test/compile-fail/use-after-move-implicity-coerced-object.rs @@ -11,6 +11,7 @@ // ignore-tidy-linelength use std::fmt; +use std::vec_ng::Vec; struct Number { n: i64 @@ -23,8 +24,7 @@ impl fmt::Show for Number { } struct List { - list: ~[~ToStr] -} + list: Vec<~ToStr> } impl List { fn push(&mut self, n: ~ToStr) { @@ -34,7 +34,7 @@ impl List { fn main() { let n = ~Number { n: 42 }; - let mut l = ~List { list: ~[] }; + let mut l = ~List { list: Vec::new() }; l.push(n); let x = n.to_str(); //~^ ERROR: use of moved value: `n` diff --git a/src/test/compile-fail/vec-field.rs b/src/test/compile-fail/vec-field.rs index d97c32a64a47c..d7d1804da75a8 100644 --- a/src/test/compile-fail/vec-field.rs +++ b/src/test/compile-fail/vec-field.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:attempted access of field `some_field_name` on type `~[int]` +// error-pattern:attempted access of field `some_field_name` // issue #367 fn f() { - let v = ~[1i]; + let v = vec!(1i); info!("{}", v.some_field_name); //type error } diff --git a/src/test/compile-fail/vec-mut-iter-borrow.rs b/src/test/compile-fail/vec-mut-iter-borrow.rs index 72dbd82e947f1..a3c7fc2d4c8af 100644 --- a/src/test/compile-fail/vec-mut-iter-borrow.rs +++ b/src/test/compile-fail/vec-mut-iter-borrow.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let mut xs = ~[1, 2, 3, 4]; + let mut xs = vec!(1, 2, 3, 4); for x in xs.mut_iter() { xs.push(1) //~ ERROR cannot borrow `xs` diff --git a/src/test/compile-fail/vec-res-add.rs b/src/test/compile-fail/vec-res-add.rs index 3545392d5d9f7..4513b7861b64b 100644 --- a/src/test/compile-fail/vec-res-add.rs +++ b/src/test/compile-fail/vec-res-add.rs @@ -22,8 +22,8 @@ impl Drop for r { fn main() { // This can't make sense as it would copy the classes - let i = ~[r(0)]; - let j = ~[r(1)]; + let i = vec!(r(0)); + let j = vec!(r(1)); let k = i + j; info!("{}", j); } diff --git a/src/test/compile-fail/vector-no-ann.rs b/src/test/compile-fail/vector-no-ann.rs index 4dc3490522741..985a094d5a8c2 100644 --- a/src/test/compile-fail/vector-no-ann.rs +++ b/src/test/compile-fail/vector-no-ann.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn main() { - let _foo = ~[]; //~ ERROR unconstrained type + let _foo = Vec::new(); //~ ERROR unconstrained type } diff --git a/src/test/compile-fail/writing-to-immutable-vec.rs b/src/test/compile-fail/writing-to-immutable-vec.rs index faa3d6cfe47e7..00d537f95bf98 100644 --- a/src/test/compile-fail/writing-to-immutable-vec.rs +++ b/src/test/compile-fail/writing-to-immutable-vec.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn main() { - let v: ~[int] = ~[1, 2, 3]; - v[1] = 4; //~ ERROR cannot assign + let v: Vec = vec!(1, 2, 3); + *v.get(1) = 4; //~ ERROR cannot assign } diff --git a/src/test/debug-info/boxed-vec.rs b/src/test/debug-info/boxed-vec.rs index 810f0d2468aaa..5ddce3c60e177 100644 --- a/src/test/debug-info/boxed-vec.rs +++ b/src/test/debug-info/boxed-vec.rs @@ -26,7 +26,7 @@ fn main() { - let unique: ~[i64] = ~[10, 11, 12, 13]; + let unique: Vec = vec!(10, 11, 12, 13); zzz(); } diff --git a/src/test/debug-info/issue11600.rs b/src/test/debug-info/issue11600.rs index 83ad5c4c7fabf..baf020672ec52 100644 --- a/src/test/debug-info/issue11600.rs +++ b/src/test/debug-info/issue11600.rs @@ -9,7 +9,7 @@ // except according to those terms. fn main() { - let args : ~[~str] = ::std::os::args(); + let args : Vec<~str> = ::std::os::args(); ::std::io::println(args[0]); } diff --git a/src/test/debug-info/managed-pointer-within-unique-vec.rs b/src/test/debug-info/managed-pointer-within-unique-vec.rs index 5b9ab0e8ce5aa..50f394613929a 100644 --- a/src/test/debug-info/managed-pointer-within-unique-vec.rs +++ b/src/test/debug-info/managed-pointer-within-unique-vec.rs @@ -33,7 +33,7 @@ fn main() { - let unique: ~[@i64] = ~[@10, @11, @12, @13]; + let unique: Vec<@i64> = vec!(@10, @11, @12, @13); zzz(); } diff --git a/src/test/pretty/block-disambig.rs b/src/test/pretty/block-disambig.rs index 3f789fa456a9c..acc03831290d0 100644 --- a/src/test/pretty/block-disambig.rs +++ b/src/test/pretty/block-disambig.rs @@ -15,6 +15,7 @@ #[feature(managed_boxes)]; use std::cell::Cell; +use std::vec_ng::Vec; fn test1() { let val = @0; { } *val; } @@ -59,9 +60,9 @@ fn test9() { } fn test10() -> int { - let regs = @~[0]; + let regs = @vec!(0); match true { true => { } _ => { } } - (*regs)[0] + *(*regs).get(0) } -fn test11() -> ~[int] { if true { } ~[1, 2] } +fn test11() -> Vec { if true { } vec!(1, 2) } diff --git a/src/test/pretty/match-naked-expr-medium.rs b/src/test/pretty/match-naked-expr-medium.rs index 4ae129c7b7307..5b52acdff5069 100644 --- a/src/test/pretty/match-naked-expr-medium.rs +++ b/src/test/pretty/match-naked-expr-medium.rs @@ -14,7 +14,7 @@ fn main() { let x = Some(3); let _y = match x { - Some(_) => ~[~"some(_)", ~"not", ~"SO", ~"long", ~"string"], - None => ~[~"none"] + Some(_) => [~"some(_)", ~"not", ~"SO", ~"long", ~"string"], + None => [~"none", ~"a", ~"a", ~"a", ~"a"] }; } diff --git a/src/test/pretty/vec-comments.pp b/src/test/pretty/vec-comments.pp index a09e341a9402f..dc2dae1044dac 100644 --- a/src/test/pretty/vec-comments.pp +++ b/src/test/pretty/vec-comments.pp @@ -13,27 +13,27 @@ // pp-exact:vec-comments.pp fn main() { let _v1 = - ~[ - // Comment - 0, - // Comment - 1, - // Comment - 2]; + [ + // Comment + 0, + // Comment + 1, + // Comment + 2]; let _v2 = - ~[0, // Comment - 1, // Comment - 2]; // Comment + [0, // Comment + 1, // Comment + 2]; // Comment let _v3 = - ~[ - /* Comment */ - 0, - /* Comment */ - 1, - /* Comment */ - 2]; + [ + /* Comment */ + 0, + /* Comment */ + 1, + /* Comment */ + 2]; let _v4 = - ~[0, /* Comment */ - 1, /* Comment */ - 2]; /* Comment */ + [0, /* Comment */ + 1, /* Comment */ + 2]; /* Comment */ } diff --git a/src/test/pretty/vec-comments.rs b/src/test/pretty/vec-comments.rs index a09e341a9402f..dc2dae1044dac 100644 --- a/src/test/pretty/vec-comments.rs +++ b/src/test/pretty/vec-comments.rs @@ -13,27 +13,27 @@ // pp-exact:vec-comments.pp fn main() { let _v1 = - ~[ - // Comment - 0, - // Comment - 1, - // Comment - 2]; + [ + // Comment + 0, + // Comment + 1, + // Comment + 2]; let _v2 = - ~[0, // Comment - 1, // Comment - 2]; // Comment + [0, // Comment + 1, // Comment + 2]; // Comment let _v3 = - ~[ - /* Comment */ - 0, - /* Comment */ - 1, - /* Comment */ - 2]; + [ + /* Comment */ + 0, + /* Comment */ + 1, + /* Comment */ + 2]; let _v4 = - ~[0, /* Comment */ - 1, /* Comment */ - 2]; /* Comment */ + [0, /* Comment */ + 1, /* Comment */ + 2]; /* Comment */ } diff --git a/src/test/pretty/vec-type.pp b/src/test/pretty/vec-type.pp deleted file mode 100644 index d84f43d70050c..0000000000000 --- a/src/test/pretty/vec-type.pp +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// pp-exact:vec-type.pp - -fn f1(_x: ~[int]) { } - -fn g1() { f1(~[1, 2, 3]); } diff --git a/src/test/pretty/vec-type.rs b/src/test/pretty/vec-type.rs deleted file mode 100644 index d84f43d70050c..0000000000000 --- a/src/test/pretty/vec-type.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// pp-exact:vec-type.pp - -fn f1(_x: ~[int]) { } - -fn g1() { f1(~[1, 2, 3]); } diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs b/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs index 0541dcca64d4d..16e37e128abea 100644 --- a/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs +++ b/src/test/run-fail/bug-2470-bounds-check-overflow-2.rs @@ -14,7 +14,7 @@ use std::uint; fn main() { - let x = ~[1u,2u,3u]; + let x = vec!(1u,2u,3u); // This should cause a bounds-check failure, but may not if we do our // bounds checking by comparing a scaled index value to the vector's diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs b/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs index c95d128c08561..30ad9d50c8830 100644 --- a/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs +++ b/src/test/run-fail/bug-2470-bounds-check-overflow-3.rs @@ -15,7 +15,7 @@ use std::u64; #[cfg(target_arch="x86")] fn main() { - let x = ~[1u,2u,3u]; + let x = vec!(1u,2u,3u); // This should cause a bounds-check failure, but may not if we do our // bounds checking by truncating the index value to the size of the @@ -35,6 +35,6 @@ fn main() { #[cfg(target_arch="x86_64")] fn main() { // This version just fails anyways, for symmetry on 64-bit hosts. - let x = ~[1u,2u,3u]; + let x = vec!(1u,2u,3u); error!("ov3 0x%x", x[200]); } diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow.rs b/src/test/run-fail/bug-2470-bounds-check-overflow.rs index 932b9a0d45106..c476863abd3ca 100644 --- a/src/test/run-fail/bug-2470-bounds-check-overflow.rs +++ b/src/test/run-fail/bug-2470-bounds-check-overflow.rs @@ -20,7 +20,7 @@ fn main() { // address of the 0th cell in the array (even though the index is // huge). - let x = ~[1u,2u,3u]; + let x = vec!(1u,2u,3u); let base = x.as_ptr() as uint; let idx = base / mem::size_of::(); @@ -31,5 +31,5 @@ fn main() { idx * mem::size_of::()); // This should fail. - error!("ov1 0x{:x}", x[idx]); + error!("ov1 0x{:x}", *x.get(idx)); } diff --git a/src/test/run-fail/issue-3029.rs b/src/test/run-fail/issue-3029.rs index 44364007c067e..365be5b75275a 100644 --- a/src/test/run-fail/issue-3029.rs +++ b/src/test/run-fail/issue-3029.rs @@ -12,10 +12,12 @@ #[allow(unreachable_code)]; #[allow(unused_variable)]; +use std::vec_ng::Vec; + // error-pattern:so long fn main() { - let mut x = ~[]; - let y = ~[3]; + let mut x = Vec::new(); + let y = vec!(3); fail!("so long"); x.push_all_move(y); ~"good" + ~"bye"; diff --git a/src/test/run-fail/unwind-box-vec.rs b/src/test/run-fail/unwind-box-vec.rs index 4a5cd27011605..3978f49924ba4 100644 --- a/src/test/run-fail/unwind-box-vec.rs +++ b/src/test/run-fail/unwind-box-vec.rs @@ -17,7 +17,7 @@ fn failfn() { } fn main() { - let x = @~[0, 1, 2, 3, 4, 5]; + let x = @vec!(0, 1, 2, 3, 4, 5); failfn(); error!("{:?}", x); } diff --git a/src/test/run-fail/unwind-interleaved.rs b/src/test/run-fail/unwind-interleaved.rs index 365204d5c9e4d..6f2400ec4f0e4 100644 --- a/src/test/run-fail/unwind-interleaved.rs +++ b/src/test/run-fail/unwind-interleaved.rs @@ -15,8 +15,8 @@ fn a() { } fn b() { fail!(); } fn main() { - let _x = ~[0]; + let _x = vec!(0); a(); - let _y = ~[0]; + let _y = vec!(0); b(); } diff --git a/src/test/run-fail/unwind-misc-1.rs b/src/test/run-fail/unwind-misc-1.rs index f9abb1566bb0f..6448926903ff7 100644 --- a/src/test/run-fail/unwind-misc-1.rs +++ b/src/test/run-fail/unwind-misc-1.rs @@ -15,13 +15,17 @@ extern crate collections; +use std::vec_ng::Vec; +use std::vec_ng; + fn main() { let _count = @0u; let mut map = collections::HashMap::new(); - let mut arr = ~[]; + let mut arr = Vec::new(); for _i in range(0u, 10u) { arr.push(@~"key stuff"); - map.insert(arr.clone(), arr + &[@~"value stuff"]); + map.insert(arr.clone(), + vec_ng::append(arr.clone(), &[@~"value stuff"])); if arr.len() == 5 { fail!(); } diff --git a/src/test/run-fail/unwind-partial-box.rs b/src/test/run-fail/unwind-partial-box.rs index 7239cad762d90..80e1b60ee5a9e 100644 --- a/src/test/run-fail/unwind-partial-box.rs +++ b/src/test/run-fail/unwind-partial-box.rs @@ -12,7 +12,9 @@ #[feature(managed_boxes)]; -fn f() -> ~[int] { fail!(); } +use std::vec_ng::Vec; + +fn f() -> Vec { fail!(); } // Voodoo. In unwind-alt we had to do this to trigger the bug. Might // have been to do with memory allocation patterns. diff --git a/src/test/run-fail/unwind-partial-unique.rs b/src/test/run-fail/unwind-partial-unique.rs index 6339e72fe469c..7f163a2a9e43f 100644 --- a/src/test/run-fail/unwind-partial-unique.rs +++ b/src/test/run-fail/unwind-partial-unique.rs @@ -12,7 +12,9 @@ #[feature(managed_boxes)]; -fn f() -> ~[int] { fail!(); } +use std::vec_ng::Vec; + +fn f() -> Vec { fail!(); } // Voodoo. In unwind-alt we had to do this to trigger the bug. Might // have been to do with memory allocation patterns. diff --git a/src/test/run-fail/unwind-partial-vec.rs b/src/test/run-fail/unwind-partial-vec.rs index 9560e0275d490..669edb4544bd3 100644 --- a/src/test/run-fail/unwind-partial-vec.rs +++ b/src/test/run-fail/unwind-partial-vec.rs @@ -12,7 +12,9 @@ #[feature(managed_boxes)]; -fn f() -> ~[int] { fail!(); } +use std::vec_ng::Vec; + +fn f() -> Vec { fail!(); } // Voodoo. In unwind-alt we had to do this to trigger the bug. Might // have been to do with memory allocation patterns. @@ -21,7 +23,7 @@ fn prime() { } fn partial() { - let _x = ~[~[0], f(), ~[0]]; + let _x = vec!(vec!(0), f(), vec!(0)); } fn main() { diff --git a/src/test/run-fail/unwind-rec.rs b/src/test/run-fail/unwind-rec.rs index 016654500b4ac..053bc0cb58c64 100644 --- a/src/test/run-fail/unwind-rec.rs +++ b/src/test/run-fail/unwind-rec.rs @@ -10,11 +10,13 @@ // error-pattern:fail -fn build() -> ~[int] { +use std::vec_ng::Vec; + +fn build() -> Vec { fail!(); } -struct Blk { node: ~[int] } +struct Blk { node: Vec } fn main() { let _blk = Blk { diff --git a/src/test/run-fail/unwind-rec2.rs b/src/test/run-fail/unwind-rec2.rs index 49a35181a8b2e..7b18c678be6f7 100644 --- a/src/test/run-fail/unwind-rec2.rs +++ b/src/test/run-fail/unwind-rec2.rs @@ -10,15 +10,17 @@ // error-pattern:fail -fn build1() -> ~[int] { - ~[0,0,0,0,0,0,0] +use std::vec_ng::Vec; + +fn build1() -> Vec { + vec!(0,0,0,0,0,0,0) } -fn build2() -> ~[int] { +fn build2() -> Vec { fail!(); } -struct Blk { node: ~[int], span: ~[int] } +struct Blk { node: Vec , span: Vec } fn main() { let _blk = Blk { diff --git a/src/test/run-fail/unwind-tup.rs b/src/test/run-fail/unwind-tup.rs index 2dd353f8e215d..fd1c13a5018f6 100644 --- a/src/test/run-fail/unwind-tup.rs +++ b/src/test/run-fail/unwind-tup.rs @@ -10,9 +10,11 @@ #[feature(managed_boxes)]; +use std::vec_ng::Vec; + // error-pattern:fail -fn fold_local() -> @~[int]{ +fn fold_local() -> @Vec { fail!(); } diff --git a/src/test/run-fail/unwind-tup2.rs b/src/test/run-fail/unwind-tup2.rs index b86d7f11e85d9..6735168e83a91 100644 --- a/src/test/run-fail/unwind-tup2.rs +++ b/src/test/run-fail/unwind-tup2.rs @@ -10,13 +10,15 @@ #[feature(managed_boxes)]; +use std::vec_ng::Vec; + // error-pattern:fail -fn fold_local() -> @~[int]{ - @~[0,0,0,0,0,0] +fn fold_local() -> @Vec { + @vec!(0,0,0,0,0,0) } -fn fold_remote() -> @~[int]{ +fn fold_remote() -> @Vec { fail!(); } diff --git a/src/test/run-fail/vec-overrun.rs b/src/test/run-fail/vec-overrun.rs index e7421fe241d7c..169c00182dd39 100644 --- a/src/test/run-fail/vec-overrun.rs +++ b/src/test/run-fail/vec-overrun.rs @@ -8,13 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - // error-pattern:index out of bounds: the len is 1 but the index is 2 + +use std::vec_ng::Vec; + fn main() { - let v: ~[int] = ~[10]; - let x: int = 0; - assert_eq!(v[x], 10); + let v: Vec = vec!(10); + let x: uint = 0; + assert_eq!(*v.get(x), 10); // Bounds-check failure. - assert_eq!(v[x + 2], 20); + assert_eq!(*v.get(x + 2), 20); } diff --git a/src/test/run-pass-fulldeps/qquote.rs b/src/test/run-pass-fulldeps/qquote.rs index 0e31cbd2e955c..650d4ea631e60 100644 --- a/src/test/run-pass-fulldeps/qquote.rs +++ b/src/test/run-pass-fulldeps/qquote.rs @@ -36,7 +36,7 @@ trait fake_ext_ctxt { type fake_session = parse::parse_sess; impl fake_ext_ctxt for fake_session { - fn cfg() -> ast::CrateConfig { ~[] } + fn cfg() -> ast::CrateConfig { Vec::new() } fn parse_sess() -> parse::parse_sess { self } fn call_site() -> span { codemap::span { diff --git a/src/test/run-pass-fulldeps/quote-tokens.rs b/src/test/run-pass-fulldeps/quote-tokens.rs index b11515ac24bd9..1bf601f71b4cf 100644 --- a/src/test/run-pass-fulldeps/quote-tokens.rs +++ b/src/test/run-pass-fulldeps/quote-tokens.rs @@ -18,8 +18,8 @@ extern crate syntax; use syntax::ext::base::ExtCtxt; fn syntax_extension(cx: &ExtCtxt) { - let e_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, 1 + 2); - let p_toks : ~[syntax::ast::token_tree] = quote_tokens!(cx, (x, 1 .. 4, *)); + let e_toks : Vec = quote_tokens!(cx, 1 + 2); + let p_toks : Vec = quote_tokens!(cx, (x, 1 .. 4, *)); let a: @syntax::ast::Expr = quote_expr!(cx, 1 + 2); let _b: Option<@syntax::ast::item> = quote_item!(cx, static foo : int = $e_toks; ); diff --git a/src/test/run-pass/alloca-from-derived-tydesc.rs b/src/test/run-pass/alloca-from-derived-tydesc.rs index ddaa38223ecae..f9320f6b03923 100644 --- a/src/test/run-pass/alloca-from-derived-tydesc.rs +++ b/src/test/run-pass/alloca-from-derived-tydesc.rs @@ -8,10 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + enum option { some(T), none, } -struct R {v: ~[option]} +struct R {v: Vec> } -fn f() -> ~[T] { return ~[]; } +fn f() -> Vec { return Vec::new(); } -pub fn main() { let mut r: R = R {v: ~[]}; r.v = f(); } +pub fn main() { let mut r: R = R {v: Vec::new()}; r.v = f(); } diff --git a/src/test/run-pass/assignability-trait.rs b/src/test/run-pass/assignability-trait.rs index 85c5ae444ebda..60a7101c8201d 100644 --- a/src/test/run-pass/assignability-trait.rs +++ b/src/test/run-pass/assignability-trait.rs @@ -12,6 +12,8 @@ // making method calls, but only if there aren't any matches without // it. +use std::vec_ng::Vec; + trait iterable { fn iterate(&self, blk: |x: &A| -> bool) -> bool; } @@ -22,7 +24,7 @@ impl<'a,A> iterable for &'a [A] { } } -impl iterable for ~[A] { +impl iterable for Vec { fn iterate(&self, f: |x: &A| -> bool) -> bool { self.iter().advance(f) } @@ -38,14 +40,14 @@ fn length>(x: T) -> uint { } pub fn main() { - let x = ~[0,1,2,3]; + let x: Vec = vec!(0,1,2,3); // Call a method - x.iterate(|y| { assert!(x[*y] == *y); true }); + x.iterate(|y| { assert!(*x.get(*y as uint) == *y); true }); // Call a parameterized function assert_eq!(length(x.clone()), x.len()); // Call a parameterized function, with type arguments that require // a borrow - assert_eq!(length::(x), x.len()); + assert_eq!(length::(x.as_slice()), x.len()); // Now try it with a type that *needs* to be borrowed let z = [0,1,2,3]; diff --git a/src/test/run-pass/auto-encode.rs b/src/test/run-pass/auto-encode.rs index 1ce6c1b77dda7..e7ee61179921d 100644 --- a/src/test/run-pass/auto-encode.rs +++ b/src/test/run-pass/auto-encode.rs @@ -119,7 +119,7 @@ struct Spanned { } #[deriving(Decodable, Encodable)] -struct SomeStruct { v: ~[uint] } +struct SomeStruct { v: Vec } #[deriving(Decodable, Encodable)] struct Point {x: uint, y: uint} diff --git a/src/test/run-pass/auto-loop.rs b/src/test/run-pass/auto-loop.rs index 33aee55b8c738..e5f4d07874998 100644 --- a/src/test/run-pass/auto-loop.rs +++ b/src/test/run-pass/auto-loop.rs @@ -10,7 +10,7 @@ pub fn main() { let mut sum = 0; - let xs = ~[1, 2, 3, 4, 5]; + let xs = vec!(1, 2, 3, 4, 5); for x in xs.iter() { sum += *x; } diff --git a/src/test/run-pass/auto-ref-slice-plus-ref.rs b/src/test/run-pass/auto-ref-slice-plus-ref.rs index c22e25e5d95be..86e1b18a57416 100644 --- a/src/test/run-pass/auto-ref-slice-plus-ref.rs +++ b/src/test/run-pass/auto-ref-slice-plus-ref.rs @@ -29,7 +29,7 @@ pub fn main() { // NB: Associativity of ~, etc. in this context is surprising. These must be parenthesized ([1]).test_imm(); - (~[1]).test_imm(); + (vec!(1)).as_slice().test_imm(); (&[1]).test_imm(); ("test").test_imm(); (~"test").test_imm(); diff --git a/src/test/run-pass/auto-ref-sliceable.rs b/src/test/run-pass/auto-ref-sliceable.rs index 8e2b3b56736e2..82d2a58a556e6 100644 --- a/src/test/run-pass/auto-ref-sliceable.rs +++ b/src/test/run-pass/auto-ref-sliceable.rs @@ -8,19 +8,21 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + trait Pushable { fn push_val(&mut self, t: T); } -impl Pushable for ~[T] { +impl Pushable for Vec { fn push_val(&mut self, t: T) { self.push(t); } } pub fn main() { - let mut v = ~[1]; + let mut v = vec!(1); v.push_val(2); v.push_val(3); - assert_eq!(v, ~[1, 2, 3]); + assert_eq!(v, vec!(1, 2, 3)); } diff --git a/src/test/run-pass/autobind.rs b/src/test/run-pass/autobind.rs index c0ceb50a2c4be..db528c4fd0877 100644 --- a/src/test/run-pass/autobind.rs +++ b/src/test/run-pass/autobind.rs @@ -8,12 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(x: ~[T]) -> T { return x[0]; } +use std::vec_ng::Vec; -fn g(act: |~[int]| -> int) -> int { return act(~[1, 2, 3]); } +fn f(x: Vec) -> T { return x.move_iter().next().unwrap(); } + +fn g(act: |Vec | -> int) -> int { return act(vec!(1, 2, 3)); } pub fn main() { assert_eq!(g(f), 1); - let f1: |~[~str]| -> ~str = f; - assert_eq!(f1(~[~"x", ~"y", ~"z"]), ~"x"); + let f1: |Vec<~str> | -> ~str = f; + assert_eq!(f1(vec!(~"x", ~"y", ~"z")), ~"x"); } diff --git a/src/test/run-pass/block-arg.rs b/src/test/run-pass/block-arg.rs index d59804b23954e..fd83f6a9c763b 100644 --- a/src/test/run-pass/block-arg.rs +++ b/src/test/run-pass/block-arg.rs @@ -18,7 +18,7 @@ fn booly(fun: proc(bool) -> bool) -> bool { // Check usage and precedence of block arguments in expressions: pub fn main() { - let v = ~[-1.0f64, 0.0, 1.0, 2.0, 3.0]; + let v = vec!(-1.0f64, 0.0, 1.0, 2.0, 3.0); // Statement form does not require parentheses: for i in v.iter() { diff --git a/src/test/run-pass/block-iter-1.rs b/src/test/run-pass/block-iter-1.rs index 4aebcd6aa24c9..5b065d1774e53 100644 --- a/src/test/run-pass/block-iter-1.rs +++ b/src/test/run-pass/block-iter-1.rs @@ -10,10 +10,12 @@ // ignore-fast -fn iter_vec(v: ~[T], f: |&T|) { for x in v.iter() { f(x); } } +use std::vec_ng::Vec; + +fn iter_vec(v: Vec , f: |&T|) { for x in v.iter() { f(x); } } pub fn main() { - let v = ~[1, 2, 3, 4, 5, 6, 7]; + let v = vec!(1, 2, 3, 4, 5, 6, 7); let mut odds = 0; iter_vec(v, |i| { if *i % 2 == 1 { diff --git a/src/test/run-pass/block-iter-2.rs b/src/test/run-pass/block-iter-2.rs index 2e149f88478c1..2700dcb1051fc 100644 --- a/src/test/run-pass/block-iter-2.rs +++ b/src/test/run-pass/block-iter-2.rs @@ -10,10 +10,12 @@ // ignore-fast -fn iter_vec(v: ~[T], f: |&T|) { for x in v.iter() { f(x); } } +use std::vec_ng::Vec; + +fn iter_vec(v: Vec , f: |&T|) { for x in v.iter() { f(x); } } pub fn main() { - let v = ~[1, 2, 3, 4, 5]; + let v = vec!(1, 2, 3, 4, 5); let mut sum = 0; iter_vec(v.clone(), |i| { iter_vec(v.clone(), |j| { diff --git a/src/test/run-pass/borrow-by-val-method-receiver.rs b/src/test/run-pass/borrow-by-val-method-receiver.rs index 386f5f673d69a..df334a6fcec55 100644 --- a/src/test/run-pass/borrow-by-val-method-receiver.rs +++ b/src/test/run-pass/borrow-by-val-method-receiver.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + trait Foo { fn foo(self); } @@ -17,6 +19,6 @@ impl<'a> Foo for &'a [int] { } pub fn main() { - let items = ~[ 3, 5, 1, 2, 4 ]; - items.foo(); + let items = vec!( 3, 5, 1, 2, 4 ); + items.as_slice().foo(); } diff --git a/src/test/run-pass/borrowck-binding-mutbl.rs b/src/test/run-pass/borrowck-binding-mutbl.rs index 377ed2608e513..67233c29258b1 100644 --- a/src/test/run-pass/borrowck-binding-mutbl.rs +++ b/src/test/run-pass/borrowck-binding-mutbl.rs @@ -8,17 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct F { f: ~[int] } +use std::vec_ng::Vec; + +struct F { f: Vec } fn impure(_v: &[int]) { } pub fn main() { - let mut x = F {f: ~[3]}; + let mut x = F {f: vec!(3)}; match x { F {f: ref mut v} => { - impure(*v); + impure(v.as_slice()); } } } diff --git a/src/test/run-pass/borrowck-mut-uniq.rs b/src/test/run-pass/borrowck-mut-uniq.rs index 10760236e6dc3..abfb6e40f0913 100644 --- a/src/test/run-pass/borrowck-mut-uniq.rs +++ b/src/test/run-pass/borrowck-mut-uniq.rs @@ -9,12 +9,13 @@ // except according to those terms. use std::mem::swap; +use std::vec_ng::Vec; -struct Ints {sum: ~int, values: ~[int]} +struct Ints {sum: ~int, values: Vec } fn add_int(x: &mut Ints, v: int) { *x.sum += v; - let mut values = ~[]; + let mut values = Vec::new(); swap(&mut values, &mut x.values); values.push(v); swap(&mut values, &mut x.values); @@ -22,11 +23,11 @@ fn add_int(x: &mut Ints, v: int) { fn iter_ints(x: &Ints, f: |x: &int| -> bool) -> bool { let l = x.values.len(); - range(0u, l).advance(|i| f(&x.values[i])) + range(0u, l).advance(|i| f(x.values.get(i))) } pub fn main() { - let mut ints = ~Ints {sum: ~0, values: ~[]}; + let mut ints = ~Ints {sum: ~0, values: Vec::new()}; add_int(ints, 22); add_int(ints, 44); diff --git a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs index 1ca94d6a2219e..0b46f49ad9360 100644 --- a/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs +++ b/src/test/run-pass/borrowck-mut-vec-as-imm-slice.rs @@ -8,16 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn want_slice(v: &[int]) -> int { let mut sum = 0; for i in v.iter() { sum += *i; } sum } -fn has_mut_vec(v: ~[int]) -> int { - want_slice(v) +fn has_mut_vec(v: Vec ) -> int { + want_slice(v.as_slice()) } pub fn main() { - assert_eq!(has_mut_vec(~[1, 2, 3]), 6); + assert_eq!(has_mut_vec(vec!(1, 2, 3)), 6); } diff --git a/src/test/run-pass/borrowck-root-while-cond-2.rs b/src/test/run-pass/borrowck-root-while-cond-2.rs index 9511d1b40e60c..bb346bccd5152 100644 --- a/src/test/run-pass/borrowck-root-while-cond-2.rs +++ b/src/test/run-pass/borrowck-root-while-cond-2.rs @@ -10,10 +10,12 @@ #[feature(managed_boxes)]; +use std::vec_ng::Vec; + struct F { f: @G } -struct G { g: ~[int] } +struct G { g: Vec } pub fn main() { - let rec = @F {f: @G {g: ~[1, 2, 3]}}; + let rec = @F {f: @G {g: vec!(1, 2, 3)}}; while rec.f.g.len() == 23 {} } diff --git a/src/test/run-pass/borrowck-root-while-cond.rs b/src/test/run-pass/borrowck-root-while-cond.rs index a2d4991abc018..03ea9178eb90c 100644 --- a/src/test/run-pass/borrowck-root-while-cond.rs +++ b/src/test/run-pass/borrowck-root-while-cond.rs @@ -10,6 +10,8 @@ #[feature(managed_boxes)]; +use std::vec_ng::Vec; + fn borrow<'r,T>(x: &'r T) -> &'r T {x} struct Rec { f: @int } diff --git a/src/test/run-pass/break.rs b/src/test/run-pass/break.rs index 1ae77bc1eca84..bcfb8f6f9141a 100644 --- a/src/test/run-pass/break.rs +++ b/src/test/run-pass/break.rs @@ -25,7 +25,7 @@ pub fn main() { i += 1; if i % 2 == 0 { continue; } assert!((i % 2 != 0)); if i >= 10 { break; } } - let ys = ~[1, 2, 3, 4, 5, 6]; + let ys = vec!(1, 2, 3, 4, 5, 6); for x in ys.iter() { if *x % 2 == 0 { continue; } assert!((*x % 2 != 0)); diff --git a/src/test/run-pass/call-closure-from-overloaded-op.rs b/src/test/run-pass/call-closure-from-overloaded-op.rs index 16728dffd19b1..34f6e5ab8fd83 100644 --- a/src/test/run-pass/call-closure-from-overloaded-op.rs +++ b/src/test/run-pass/call-closure-from-overloaded-op.rs @@ -8,10 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn foo() -> int { 22 } pub fn main() { - let mut x: ~[extern "Rust" fn() -> int] = ~[]; + let mut x: Vec int> = Vec::new(); x.push(foo); - assert_eq!((x[0])(), 22); + assert_eq!((*x.get(0))(), 22); } diff --git a/src/test/run-pass/cci_no_inline_exe.rs b/src/test/run-pass/cci_no_inline_exe.rs index faa2a35011704..c926a571ec363 100644 --- a/src/test/run-pass/cci_no_inline_exe.rs +++ b/src/test/run-pass/cci_no_inline_exe.rs @@ -22,7 +22,7 @@ pub fn main() { // actually working. //let bt0 = sys::frame_address(); //info!("%?", bt0); - iter(~[1u, 2u, 3u], |i| { + iter(vec!(1u, 2u, 3u), |i| { println!("{}", i); //let bt1 = sys::frame_address(); diff --git a/src/test/run-pass/class-poly-methods-cross-crate.rs b/src/test/run-pass/class-poly-methods-cross-crate.rs index 671d7a403531b..f8177bb0ada62 100644 --- a/src/test/run-pass/class-poly-methods-cross-crate.rs +++ b/src/test/run-pass/class-poly-methods-cross-crate.rs @@ -14,12 +14,12 @@ extern crate cci_class_6; use cci_class_6::kitties::cat; pub fn main() { - let mut nyan : cat = cat::(52u, 99, ~['p']); - let mut kitty = cat(1000u, 2, ~[~"tabby"]); + let mut nyan : cat = cat::(52u, 99, vec!('p')); + let mut kitty = cat(1000u, 2, vec!(~"tabby")); assert_eq!(nyan.how_hungry, 99); assert_eq!(kitty.how_hungry, 2); - nyan.speak(~[1u,2u,3u]); + nyan.speak(vec!(1u,2u,3u)); assert_eq!(nyan.meow_count(), 55u); - kitty.speak(~[~"meow", ~"mew", ~"purr", ~"chirp"]); + kitty.speak(vec!(~"meow", ~"mew", ~"purr", ~"chirp")); assert_eq!(kitty.meow_count(), 1004u); } diff --git a/src/test/run-pass/class-poly-methods.rs b/src/test/run-pass/class-poly-methods.rs index f4d3a115ef136..02ba8b900be72 100644 --- a/src/test/run-pass/class-poly-methods.rs +++ b/src/test/run-pass/class-poly-methods.rs @@ -8,21 +8,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + struct cat { - info : ~[U], + info : Vec , meows : uint, how_hungry : int, } impl cat { - pub fn speak(&mut self, stuff: ~[T]) { + pub fn speak(&mut self, stuff: Vec ) { self.meows += stuff.len(); } pub fn meow_count(&mut self) -> uint { self.meows } } -fn cat(in_x : uint, in_y : int, in_info: ~[U]) -> cat { +fn cat(in_x : uint, in_y : int, in_info: Vec ) -> cat { cat { meows: in_x, how_hungry: in_y, @@ -31,12 +33,12 @@ fn cat(in_x : uint, in_y : int, in_info: ~[U]) -> cat { } pub fn main() { - let mut nyan : cat = cat::(52u, 99, ~[9]); - let mut kitty = cat(1000u, 2, ~[~"tabby"]); + let mut nyan : cat = cat::(52u, 99, vec!(9)); + let mut kitty = cat(1000u, 2, vec!(~"tabby")); assert_eq!(nyan.how_hungry, 99); assert_eq!(kitty.how_hungry, 2); - nyan.speak(~[1,2,3]); + nyan.speak(vec!(1,2,3)); assert_eq!(nyan.meow_count(), 55u); - kitty.speak(~[~"meow", ~"mew", ~"purr", ~"chirp"]); + kitty.speak(vec!(~"meow", ~"mew", ~"purr", ~"chirp")); assert_eq!(kitty.meow_count(), 1004u); } diff --git a/src/test/run-pass/cleanup-rvalue-scopes.rs b/src/test/run-pass/cleanup-rvalue-scopes.rs index 7ed59ec74b4d9..2911df412d817 100644 --- a/src/test/run-pass/cleanup-rvalue-scopes.rs +++ b/src/test/run-pass/cleanup-rvalue-scopes.rs @@ -15,6 +15,7 @@ #[feature(macro_rules)]; use std::ops::Drop; +use std::vec_ng::Vec; static mut FLAGS: u64 = 0; @@ -116,7 +117,6 @@ pub fn main() { end_of_block!(_, { { check_flags(0); &AddFlags(1) } }); end_of_block!(_, &((Box { f: AddFlags(1) }).f)); end_of_block!(_, &(([AddFlags(1)])[0])); - end_of_block!(_, &((&~[AddFlags(1)])[0])); // LHS does not create a ref binding, so temporary lives as long // as statement, and we do not move the AddFlags out: diff --git a/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs b/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs index ec422a54b3a7a..7bf7920fe070d 100644 --- a/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs +++ b/src/test/run-pass/cleanup-rvalue-temp-during-incomplete-alloc.rs @@ -25,6 +25,7 @@ // scenario worth testing. use std::task; +use std::vec_ng::Vec; enum Conzabble { Bickwick(Foo) @@ -36,12 +37,12 @@ fn do_it(x: &[uint]) -> Foo { fail!() } -fn get_bar(x: uint) -> ~[uint] { ~[x * 2] } +fn get_bar(x: uint) -> Vec { vec!(x * 2) } pub fn fails() { let x = 2; - let mut y = ~[]; - y.push(~Bickwick(do_it(get_bar(x)))); + let mut y = Vec::new(); + y.push(~Bickwick(do_it(get_bar(x).as_slice()))); } pub fn main() { diff --git a/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs b/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs index dee2b6f2568d7..937cb0f0dac84 100644 --- a/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-imm-vec-rcvr.rs @@ -8,16 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn bar(v: &mut [uint]) -> ~[uint] { - v.to_owned() +use std::vec_ng::Vec; + +fn bar(v: &mut [uint]) -> Vec { + Vec::from_slice(v) } -fn bip(v: &[uint]) -> ~[uint] { - v.to_owned() +fn bip(v: &[uint]) -> Vec { + Vec::from_slice(v) } pub fn main() { - let mut the_vec = ~[1u, 2, 3, 100]; - assert_eq!(the_vec.clone(), bar(the_vec)); - assert_eq!(the_vec.clone(), bip(the_vec)); + let mut the_vec = vec!(1u, 2, 3, 100); + assert_eq!(the_vec.clone(), bar(the_vec.as_mut_slice())); + assert_eq!(the_vec.clone(), bip(the_vec.as_slice())); } diff --git a/src/test/run-pass/coerce-reborrow-mut-vec-arg.rs b/src/test/run-pass/coerce-reborrow-mut-vec-arg.rs index 0e205617173cb..be8bb861345b9 100644 --- a/src/test/run-pass/coerce-reborrow-mut-vec-arg.rs +++ b/src/test/run-pass/coerce-reborrow-mut-vec-arg.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn reverse(v: &mut [uint]) { v.reverse(); } @@ -19,7 +21,7 @@ fn bar(v: &mut [uint]) { } pub fn main() { - let mut the_vec = ~[1, 2, 3, 100]; - bar(the_vec); - assert_eq!(the_vec, ~[100, 3, 2, 1]); + let mut the_vec = vec!(1, 2, 3, 100); + bar(the_vec.as_mut_slice()); + assert_eq!(the_vec, vec!(100, 3, 2, 1)); } diff --git a/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs b/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs index 3deb31efd311d..686b8545b5ef8 100644 --- a/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-mut-vec-rcvr.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn bar(v: &mut [uint]) { v.reverse(); v.reverse(); @@ -15,7 +17,7 @@ fn bar(v: &mut [uint]) { } pub fn main() { - let mut the_vec = ~[1, 2, 3, 100]; - bar(the_vec); - assert_eq!(the_vec, ~[100, 3, 2, 1]); + let mut the_vec = vec!(1, 2, 3, 100); + bar(the_vec.as_mut_slice()); + assert_eq!(the_vec, vec!(100, 3, 2, 1)); } diff --git a/src/test/run-pass/const-enum-vec-repeat.rs b/src/test/run-pass/const-enum-vec-repeat.rs deleted file mode 100644 index 44b91fcee3c71..0000000000000 --- a/src/test/run-pass/const-enum-vec-repeat.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -enum State { ST_NULL, ST_WHITESPACE = 1 } - -pub fn main() { - ~[ST_NULL, ..(ST_WHITESPACE as uint)]; -} diff --git a/src/test/run-pass/deep-vector.rs b/src/test/run-pass/deep-vector.rs index e6ae892093c8f..6a05dafb17cec 100644 --- a/src/test/run-pass/deep-vector.rs +++ b/src/test/run-pass/deep-vector.rs @@ -8,8 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test +// ignore-fast +// +// Too big for our poor macro infrastructure. + pub fn main() { - let _x = ~[ + let _x = vec!( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -2008,5 +2013,5 @@ pub fn main() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - ]; + ); } diff --git a/src/test/run-pass/deep-vector2.rs b/src/test/run-pass/deep-vector2.rs index b644d1a8b1f9d..615e94c3f4e59 100644 --- a/src/test/run-pass/deep-vector2.rs +++ b/src/test/run-pass/deep-vector2.rs @@ -8,8 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test +// ignore-fast +// +// Too big for our poor macro infrastructure. + pub fn main() { - let _x = ~[ + let _x = vec!( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -8008,5 +8013,5 @@ pub fn main() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - ]; + ); } diff --git a/src/test/run-pass/empty-mutable-vec.rs b/src/test/run-pass/empty-mutable-vec.rs index 6c90e011218c4..aafea1ef1ef0e 100644 --- a/src/test/run-pass/empty-mutable-vec.rs +++ b/src/test/run-pass/empty-mutable-vec.rs @@ -10,4 +10,6 @@ #[allow(unused_mut)]; -pub fn main() { let mut _v: ~[int] = ~[]; } +use std::vec_ng::Vec; + +pub fn main() { let mut _v: Vec = Vec::new(); } diff --git a/src/test/run-pass/expr-fn.rs b/src/test/run-pass/expr-fn.rs index cba1bab300468..c8a207cd4bd2d 100644 --- a/src/test/run-pass/expr-fn.rs +++ b/src/test/run-pass/expr-fn.rs @@ -8,14 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn test_int() { fn f() -> int { 10 } assert_eq!(f(), 10); } fn test_vec() { - fn f() -> ~[int] { ~[10, 11] } - assert_eq!(f()[1], 11); + fn f() -> Vec { vec!(10, 11) } + let vect = f(); + assert_eq!(*vect.get(1), 11); } fn test_generic() { diff --git a/src/test/run-pass/expr-match-fail.rs b/src/test/run-pass/expr-match-fail.rs index 3e1b96763e196..46ba63e452d5c 100644 --- a/src/test/run-pass/expr-match-fail.rs +++ b/src/test/run-pass/expr-match-fail.rs @@ -8,14 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn test_simple() { let r = match true { true => { true } false => { fail!() } }; assert_eq!(r, true); } fn test_box() { - let r = match true { true => { ~[10] } false => { fail!() } }; - assert_eq!(r[0], 10); + let r = match true { true => { vec!(10) } false => { fail!() } }; + assert_eq!(*r.get(0), 10); } pub fn main() { test_simple(); test_box(); } diff --git a/src/test/run-pass/expr-repeat-vstore.rs b/src/test/run-pass/expr-repeat-vstore.rs deleted file mode 100644 index c34c902b8147b..0000000000000 --- a/src/test/run-pass/expr-repeat-vstore.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[feature(managed_boxes)]; - -pub fn main() { - let v: ~[int] = ~[ 1, ..5 ]; - println!("{}", v[0]); - println!("{}", v[1]); - println!("{}", v[2]); - println!("{}", v[3]); - println!("{}", v[4]); -} diff --git a/src/test/run-pass/for-destruct.rs b/src/test/run-pass/for-destruct.rs index fae67e9e3d995..7cc8b22e061e4 100644 --- a/src/test/run-pass/for-destruct.rs +++ b/src/test/run-pass/for-destruct.rs @@ -11,7 +11,7 @@ struct Pair { x: int, y: int } pub fn main() { - for elt in (~[Pair {x: 10, y: 20}, Pair {x: 30, y: 0}]).iter() { + for elt in (vec!(Pair {x: 10, y: 20}, Pair {x: 30, y: 0})).iter() { assert_eq!(elt.x + elt.y, 30); } } diff --git a/src/test/run-pass/for-loop-fail.rs b/src/test/run-pass/for-loop-fail.rs index ff718500340c8..bc9f1f642d283 100644 --- a/src/test/run-pass/for-loop-fail.rs +++ b/src/test/run-pass/for-loop-fail.rs @@ -8,4 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub fn main() { let x: ~[int] = ~[]; for _ in x.iter() { fail!("moop"); } } +use std::vec_ng::Vec; + +pub fn main() { let x: Vec = Vec::new(); for _ in x.iter() { fail!("moop"); } } diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs index 9646c6b6eb79d..9aed300c5648c 100644 --- a/src/test/run-pass/foreach-nested.rs +++ b/src/test/run-pass/foreach-nested.rs @@ -8,19 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - +use std::vec_ng::Vec; fn two(it: |int|) { it(0); it(1); } pub fn main() { - let mut a: ~[int] = ~[-1, -1, -1, -1]; + let mut a: Vec = vec!(-1, -1, -1, -1); let mut p: int = 0; two(|i| { - two(|j| { a[p] = 10 * i + j; p += 1; }) + two(|j| { *a.get_mut(p as uint) = 10 * i + j; p += 1; }) }); - assert_eq!(a[0], 0); - assert_eq!(a[1], 1); - assert_eq!(a[2], 10); - assert_eq!(a[3], 11); + assert_eq!(*a.get(0), 0); + assert_eq!(*a.get(1), 1); + assert_eq!(*a.get(2), 10); + assert_eq!(*a.get(3), 11); } diff --git a/src/test/run-pass/generic-ivec-leak.rs b/src/test/run-pass/generic-ivec-leak.rs index 17de964dd868e..f879e195292c8 100644 --- a/src/test/run-pass/generic-ivec-leak.rs +++ b/src/test/run-pass/generic-ivec-leak.rs @@ -10,4 +10,4 @@ enum wrapper { wrapped(T), } -pub fn main() { let _w = wrapped(~[1, 2, 3, 4, 5]); } +pub fn main() { let _w = wrapped(vec!(1, 2, 3, 4, 5)); } diff --git a/src/test/run-pass/generic-ivec.rs b/src/test/run-pass/generic-ivec.rs index e4f545afda638..c2eae06401992 100644 --- a/src/test/run-pass/generic-ivec.rs +++ b/src/test/run-pass/generic-ivec.rs @@ -11,4 +11,4 @@ #[feature(managed_boxes)]; fn f(_v: @T) { } -pub fn main() { f(@~[1, 2, 3, 4, 5]); } +pub fn main() { f(@vec!(1, 2, 3, 4, 5)); } diff --git a/src/test/run-pass/generic-static-methods.rs b/src/test/run-pass/generic-static-methods.rs index 5832c565d7f4c..f0dcc5e2809b0 100644 --- a/src/test/run-pass/generic-static-methods.rs +++ b/src/test/run-pass/generic-static-methods.rs @@ -8,13 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + trait vec_utils { - fn map_(x: &Self, f: |&T| -> U) -> ~[U]; + fn map_(x: &Self, f: |&T| -> U) -> Vec ; } -impl vec_utils for ~[T] { - fn map_(x: &~[T], f: |&T| -> U) -> ~[U] { - let mut r = ~[]; +impl vec_utils for Vec { + fn map_(x: &Vec , f: |&T| -> U) -> Vec { + let mut r = Vec::new(); for elt in x.iter() { r.push(f(elt)); } @@ -23,5 +25,5 @@ impl vec_utils for ~[T] { } pub fn main() { - assert_eq!(vec_utils::map_(&~[1,2,3], |&x| x+1), ~[2,3,4]); + assert_eq!(vec_utils::map_(&vec!(1,2,3), |&x| x+1), vec!(2,3,4)); } diff --git a/src/test/run-pass/getopts_ref.rs b/src/test/run-pass/getopts_ref.rs index 55ecf919b7240..314d045145bb9 100644 --- a/src/test/run-pass/getopts_ref.rs +++ b/src/test/run-pass/getopts_ref.rs @@ -13,12 +13,13 @@ extern crate getopts; use getopts::{optopt, getopts}; +use std::vec_ng::Vec; pub fn main() { - let args = ~[]; - let opts = ~[optopt("b", "", "something", "SMTHNG")]; + let args = Vec::new(); + let opts = vec!(optopt("b", "", "something", "SMTHNG")); - match getopts(args, opts) { + match getopts(args.as_slice(), opts.as_slice()) { Ok(ref m) => assert!(!m.opt_present("b")), Err(ref f) => fail!("{:?}", (*f).clone().to_err_msg()) diff --git a/src/test/run-pass/glob-std.rs b/src/test/run-pass/glob-std.rs index 39261094911c1..f40e92341fe2c 100644 --- a/src/test/run-pass/glob-std.rs +++ b/src/test/run-pass/glob-std.rs @@ -21,6 +21,7 @@ use extra::tempfile::TempDir; use std::unstable::finally::Finally; use std::{os, unstable}; use std::io; +use std::vec_ng::Vec; macro_rules! assert_eq ( ($e1:expr, $e2:expr) => ( if $e1 != $e2 { @@ -41,7 +42,7 @@ pub fn main() { os::getcwd().join(&Path::new(path)) } - fn glob_vec(pattern: &str) -> ~[Path] { + fn glob_vec(pattern: &str) -> Vec { glob(pattern).collect() } @@ -73,133 +74,133 @@ pub fn main() { mk_file("xyz/y", false); mk_file("xyz/z", false); - assert_eq!(glob_vec(""), ~[]); - assert_eq!(glob_vec("."), ~[]); - assert_eq!(glob_vec(".."), ~[]); + assert_eq!(glob_vec(""), Vec::new()); + assert_eq!(glob_vec("."), Vec::new()); + assert_eq!(glob_vec(".."), Vec::new()); - assert_eq!(glob_vec("aaa"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("aaa/"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("a"), ~[]); - assert_eq!(glob_vec("aa"), ~[]); - assert_eq!(glob_vec("aaaa"), ~[]); + assert_eq!(glob_vec("aaa"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("aaa/"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("a"), Vec::new()); + assert_eq!(glob_vec("aa"), Vec::new()); + assert_eq!(glob_vec("aaaa"), Vec::new()); - assert_eq!(glob_vec("aaa/apple"), ~[abs_path("aaa/apple")]); - assert_eq!(glob_vec("aaa/apple/nope"), ~[]); + assert_eq!(glob_vec("aaa/apple"), vec!(abs_path("aaa/apple"))); + assert_eq!(glob_vec("aaa/apple/nope"), Vec::new()); // windows should support both / and \ as directory separators if os::consts::FAMILY == os::consts::windows::FAMILY { - assert_eq!(glob_vec("aaa\\apple"), ~[abs_path("aaa/apple")]); + assert_eq!(glob_vec("aaa\\apple"), vec!(abs_path("aaa/apple"))); } - assert_eq!(glob_vec("???/"), ~[ + assert_eq!(glob_vec("???/"), vec!( abs_path("aaa"), abs_path("bbb"), abs_path("ccc"), - abs_path("xyz")]); + abs_path("xyz"))); - assert_eq!(glob_vec("aaa/tomato/tom?to.txt"), ~[ + assert_eq!(glob_vec("aaa/tomato/tom?to.txt"), vec!( abs_path("aaa/tomato/tomato.txt"), - abs_path("aaa/tomato/tomoto.txt")]); + abs_path("aaa/tomato/tomoto.txt"))); - assert_eq!(glob_vec("xyz/?"), ~[ + assert_eq!(glob_vec("xyz/?"), vec!( abs_path("xyz/x"), abs_path("xyz/y"), - abs_path("xyz/z")]); - - assert_eq!(glob_vec("a*"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("*a*"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("a*a"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("aaa*"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("*aaa"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("*aaa*"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("*a*a*a*"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("aaa*/"), ~[abs_path("aaa")]); - - assert_eq!(glob_vec("aaa/*"), ~[ + abs_path("xyz/z"))); + + assert_eq!(glob_vec("a*"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("*a*"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("a*a"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("aaa*"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("*aaa"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("*aaa*"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("*a*a*a*"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("aaa*/"), vec!(abs_path("aaa"))); + + assert_eq!(glob_vec("aaa/*"), vec!( abs_path("aaa/apple"), abs_path("aaa/orange"), - abs_path("aaa/tomato")]); + abs_path("aaa/tomato"))); - assert_eq!(glob_vec("aaa/*a*"), ~[ + assert_eq!(glob_vec("aaa/*a*"), vec!( abs_path("aaa/apple"), abs_path("aaa/orange"), - abs_path("aaa/tomato")]); + abs_path("aaa/tomato"))); - assert_eq!(glob_vec("*/*/*.txt"), ~[ + assert_eq!(glob_vec("*/*/*.txt"), vec!( abs_path("aaa/tomato/tomato.txt"), - abs_path("aaa/tomato/tomoto.txt")]); + abs_path("aaa/tomato/tomoto.txt"))); - assert_eq!(glob_vec("*/*/t[aob]m?to[.]t[!y]t"), ~[ + assert_eq!(glob_vec("*/*/t[aob]m?to[.]t[!y]t"), vec!( abs_path("aaa/tomato/tomato.txt"), - abs_path("aaa/tomato/tomoto.txt")]); + abs_path("aaa/tomato/tomoto.txt"))); - assert_eq!(glob_vec("aa[a]"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("aa[abc]"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("a[bca]a"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("aa[b]"), ~[]); - assert_eq!(glob_vec("aa[xyz]"), ~[]); - assert_eq!(glob_vec("aa[]]"), ~[]); + assert_eq!(glob_vec("aa[a]"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("aa[abc]"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("a[bca]a"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("aa[b]"), Vec::new()); + assert_eq!(glob_vec("aa[xyz]"), Vec::new()); + assert_eq!(glob_vec("aa[]]"), Vec::new()); - assert_eq!(glob_vec("aa[!b]"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("aa[!bcd]"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("a[!bcd]a"), ~[abs_path("aaa")]); - assert_eq!(glob_vec("aa[!a]"), ~[]); - assert_eq!(glob_vec("aa[!abc]"), ~[]); + assert_eq!(glob_vec("aa[!b]"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("aa[!bcd]"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("a[!bcd]a"), vec!(abs_path("aaa"))); + assert_eq!(glob_vec("aa[!a]"), Vec::new()); + assert_eq!(glob_vec("aa[!abc]"), Vec::new()); - assert_eq!(glob_vec("bbb/specials/[[]"), ~[abs_path("bbb/specials/[")]); - assert_eq!(glob_vec("bbb/specials/!"), ~[abs_path("bbb/specials/!")]); - assert_eq!(glob_vec("bbb/specials/[]]"), ~[abs_path("bbb/specials/]")]); + assert_eq!(glob_vec("bbb/specials/[[]"), vec!(abs_path("bbb/specials/["))); + assert_eq!(glob_vec("bbb/specials/!"), vec!(abs_path("bbb/specials/!"))); + assert_eq!(glob_vec("bbb/specials/[]]"), vec!(abs_path("bbb/specials/]"))); if os::consts::FAMILY != os::consts::windows::FAMILY { - assert_eq!(glob_vec("bbb/specials/[*]"), ~[abs_path("bbb/specials/*")]); - assert_eq!(glob_vec("bbb/specials/[?]"), ~[abs_path("bbb/specials/?")]); + assert_eq!(glob_vec("bbb/specials/[*]"), vec!(abs_path("bbb/specials/*"))); + assert_eq!(glob_vec("bbb/specials/[?]"), vec!(abs_path("bbb/specials/?"))); } if os::consts::FAMILY == os::consts::windows::FAMILY { - assert_eq!(glob_vec("bbb/specials/[![]"), ~[ + assert_eq!(glob_vec("bbb/specials/[![]"), vec!( abs_path("bbb/specials/!"), - abs_path("bbb/specials/]")]); + abs_path("bbb/specials/]"))); - assert_eq!(glob_vec("bbb/specials/[!]]"), ~[ + assert_eq!(glob_vec("bbb/specials/[!]]"), vec!( abs_path("bbb/specials/!"), - abs_path("bbb/specials/[")]); + abs_path("bbb/specials/["))); - assert_eq!(glob_vec("bbb/specials/[!!]"), ~[ + assert_eq!(glob_vec("bbb/specials/[!!]"), vec!( abs_path("bbb/specials/["), - abs_path("bbb/specials/]")]); + abs_path("bbb/specials/]"))); } else { - assert_eq!(glob_vec("bbb/specials/[![]"), ~[ + assert_eq!(glob_vec("bbb/specials/[![]"), vec!( abs_path("bbb/specials/!"), abs_path("bbb/specials/*"), abs_path("bbb/specials/?"), - abs_path("bbb/specials/]")]); + abs_path("bbb/specials/]"))); - assert_eq!(glob_vec("bbb/specials/[!]]"), ~[ + assert_eq!(glob_vec("bbb/specials/[!]]"), vec!( abs_path("bbb/specials/!"), abs_path("bbb/specials/*"), abs_path("bbb/specials/?"), - abs_path("bbb/specials/[")]); + abs_path("bbb/specials/["))); - assert_eq!(glob_vec("bbb/specials/[!!]"), ~[ + assert_eq!(glob_vec("bbb/specials/[!!]"), vec!( abs_path("bbb/specials/*"), abs_path("bbb/specials/?"), abs_path("bbb/specials/["), - abs_path("bbb/specials/]")]); + abs_path("bbb/specials/]"))); - assert_eq!(glob_vec("bbb/specials/[!*]"), ~[ + assert_eq!(glob_vec("bbb/specials/[!*]"), vec!( abs_path("bbb/specials/!"), abs_path("bbb/specials/?"), abs_path("bbb/specials/["), - abs_path("bbb/specials/]")]); + abs_path("bbb/specials/]"))); - assert_eq!(glob_vec("bbb/specials/[!?]"), ~[ + assert_eq!(glob_vec("bbb/specials/[!?]"), vec!( abs_path("bbb/specials/!"), abs_path("bbb/specials/*"), abs_path("bbb/specials/["), - abs_path("bbb/specials/]")]); + abs_path("bbb/specials/]"))); } } diff --git a/src/test/run-pass/hashmap-memory.rs b/src/test/run-pass/hashmap-memory.rs index 3f3687fd33375..c9319ed057eff 100644 --- a/src/test/run-pass/hashmap-memory.rs +++ b/src/test/run-pass/hashmap-memory.rs @@ -14,6 +14,8 @@ extern crate collections; +use std::vec_ng::Vec; + /** A somewhat reduced test case to expose some Valgrind issues. @@ -26,14 +28,15 @@ mod map_reduce { use collections::HashMap; use std::str; use std::task; + use std::vec_ng::Vec; pub type putter<'a> = 'a |~str, ~str|; pub type mapper = extern fn(~str, putter); - enum ctrl_proto { find_reducer(~[u8], Chan), mapper_done, } + enum ctrl_proto { find_reducer(Vec , Chan), mapper_done, } - fn start_mappers(ctrl: Chan, inputs: ~[~str]) { + fn start_mappers(ctrl: Chan, inputs: Vec<~str> ) { for i in inputs.iter() { let ctrl = ctrl.clone(); let i = i.clone(); @@ -52,7 +55,7 @@ mod map_reduce { } let (pp, cc) = Chan::new(); error!("sending find_reducer"); - ctrl.send(find_reducer(key.as_bytes().to_owned(), cc)); + ctrl.send(find_reducer(Vec::from_slice(key.as_bytes()), cc)); error!("receiving"); let c = pp.recv(); error!("{:?}", c); @@ -64,7 +67,7 @@ mod map_reduce { ctrl_clone.send(mapper_done); } - pub fn map_reduce(inputs: ~[~str]) { + pub fn map_reduce(inputs: Vec<~str> ) { let (ctrl_port, ctrl_chan) = Chan::new(); // This task becomes the master control task. It spawns others @@ -83,7 +86,8 @@ mod map_reduce { mapper_done => { num_mappers -= 1; } find_reducer(k, cc) => { let mut c; - match reducers.find(&str::from_utf8(k).unwrap().to_owned()) { + match reducers.find(&str::from_utf8(k.as_slice()).unwrap() + .to_owned()) { Some(&_c) => { c = _c; } None => { c = 0; } } @@ -95,5 +99,5 @@ mod map_reduce { } pub fn main() { - map_reduce::map_reduce(~[~"../src/test/run-pass/hashmap-memory.rs"]); + map_reduce::map_reduce(vec!(~"../src/test/run-pass/hashmap-memory.rs")); } diff --git a/src/test/run-pass/html-literals.rs b/src/test/run-pass/html-literals.rs index 97040716a11ee..aadb372fa12a8 100644 --- a/src/test/run-pass/html-literals.rs +++ b/src/test/run-pass/html-literals.rs @@ -12,6 +12,8 @@ #[feature(macro_rules)]; +use std::vec_ng::Vec; + /* This is an HTML parser written as a macro. It's all CPS, and we have @@ -41,7 +43,7 @@ macro_rules! parse_node ( parse_node!( [$(: $tags ($(:$tag_nodes),*))*]; [$(:$head_nodes,)* :tag(stringify!($head).to_owned(), - ~[$($nodes),*])]; + vec!($($nodes),*))]; $($rest)* ) ); @@ -97,6 +99,6 @@ pub fn main() { } enum HTMLFragment { - tag(~str, ~[HTMLFragment]), + tag(~str, Vec ), text(~str), } diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 564f7b4342639..101878c305e5c 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -181,7 +181,7 @@ fn test_write() { // can do with them just yet (to test the output) fn test_print() { print!("hi"); - print!("{:?}", ~[0u8]); + print!("{:?}", vec!(0u8)); println!("hello"); println!("this is a {}", "test"); println!("{foo}", foo="bar"); diff --git a/src/test/run-pass/import-glob-crate.rs b/src/test/run-pass/import-glob-crate.rs index f2117efb0bbe6..e737d6a7c50a7 100644 --- a/src/test/run-pass/import-glob-crate.rs +++ b/src/test/run-pass/import-glob-crate.rs @@ -14,10 +14,12 @@ #[allow(dead_assignment)]; extern crate extra; -use std::vec::*; + +use std::vec_ng::Vec; +use std::vec_ng; pub fn main() { - let mut v = from_elem(0u, 0); - v = append(v, [4, 2]); - assert_eq!(from_fn(2, |i| 2*(i+1)), ~[2, 4]); + let mut v = Vec::from_elem(0u, 0); + v = vec_ng::append(v, [4, 2]); + assert_eq!(Vec::from_fn(2, |i| 2*(i+1)), vec!(2, 4)); } diff --git a/src/test/run-pass/infer-fn-tail-expr.rs b/src/test/run-pass/infer-fn-tail-expr.rs index eb8601361cdaa..a3d1be5b4f12f 100644 --- a/src/test/run-pass/infer-fn-tail-expr.rs +++ b/src/test/run-pass/infer-fn-tail-expr.rs @@ -10,6 +10,8 @@ // issue #680 -fn f() -> ~[int] { ~[] } +use std::vec_ng::Vec; + +fn f() -> Vec { Vec::new() } pub fn main() { } diff --git a/src/test/run-pass/integral-indexing.rs b/src/test/run-pass/integral-indexing.rs index edc71b524e337..06b3dcdf11baa 100644 --- a/src/test/run-pass/integral-indexing.rs +++ b/src/test/run-pass/integral-indexing.rs @@ -8,19 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - +use std::vec_ng::Vec; // This is a testcase for issue #94. pub fn main() { - let v: ~[int] = ~[0, 1, 2, 3, 4, 5]; + let v: Vec = vec!(0, 1, 2, 3, 4, 5); let s: ~str = ~"abcdef"; - assert_eq!(v[3u], 3); - assert_eq!(v[3u8], 3); - assert_eq!(v[3i8], 3); - assert_eq!(v[3u32], 3); - assert_eq!(v[3i32], 3); - info!("{}", v[3u8]); + assert_eq!(v.as_slice()[3u], 3); + assert_eq!(v.as_slice()[3u8], 3); + assert_eq!(v.as_slice()[3i8], 3); + assert_eq!(v.as_slice()[3u32], 3); + assert_eq!(v.as_slice()[3i32], 3); + info!("{}", v.as_slice()[3u8]); assert_eq!(s[3u], 'd' as u8); assert_eq!(s[3u8], 'd' as u8); assert_eq!(s[3i8], 'd' as u8); diff --git a/src/test/run-pass/issue-1821.rs b/src/test/run-pass/issue-1821.rs index 92f0beaeb9c27..ef66a1e3a67e3 100644 --- a/src/test/run-pass/issue-1821.rs +++ b/src/test/run-pass/issue-1821.rs @@ -9,7 +9,10 @@ // except according to those terms. // Issue #1821 - Don't recurse trying to typecheck this + +use std::vec_ng::Vec; + enum t { - foo(~[t]) + foo(Vec) } pub fn main() {} diff --git a/src/test/run-pass/issue-2502.rs b/src/test/run-pass/issue-2502.rs index 2ee5b2e60de3e..33cac672b3933 100644 --- a/src/test/run-pass/issue-2502.rs +++ b/src/test/run-pass/issue-2502.rs @@ -8,17 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + struct font<'a> { - fontbuf: &'a ~[u8], + fontbuf: &'a Vec , } impl<'a> font<'a> { - pub fn buf(&self) -> &'a ~[u8] { + pub fn buf(&self) -> &'a Vec { self.fontbuf } } -fn font<'r>(fontbuf: &'r ~[u8]) -> font<'r> { +fn font<'r>(fontbuf: &'r Vec ) -> font<'r> { font { fontbuf: fontbuf } diff --git a/src/test/run-pass/issue-2631-b.rs b/src/test/run-pass/issue-2631-b.rs index 592232ca21d97..1ea268eafca84 100644 --- a/src/test/run-pass/issue-2631-b.rs +++ b/src/test/run-pass/issue-2631-b.rs @@ -21,7 +21,7 @@ use std::cell::RefCell; use collections::HashMap; pub fn main() { - let v = ~[@~"hi"]; + let v = vec!(@~"hi"); let mut m: req::header_map = HashMap::new(); m.insert(~"METHOD", @RefCell::new(v)); request::(&m); diff --git a/src/test/run-pass/issue-2723-b.rs b/src/test/run-pass/issue-2723-b.rs index ef20c481eb9c3..4bf5a562cf05b 100644 --- a/src/test/run-pass/issue-2723-b.rs +++ b/src/test/run-pass/issue-2723-b.rs @@ -16,6 +16,6 @@ use issue_2723_a::f; pub fn main() { unsafe { - f(~[2]); + f(vec!(2)); } } diff --git a/src/test/run-pass/issue-2804.rs b/src/test/run-pass/issue-2804.rs index 8370e0f7f9c86..bad1c087ced0d 100644 --- a/src/test/run-pass/issue-2804.rs +++ b/src/test/run-pass/issue-2804.rs @@ -16,6 +16,7 @@ extern crate serialize; use collections::HashMap; use serialize::json; use std::option; +use std::vec_ng::Vec; enum object { bool_value(bool), @@ -55,21 +56,20 @@ fn add_interface(_store: int, managed_ip: ~str, data: json::Json) -> (~str, obje } fn add_interfaces(store: int, managed_ip: ~str, device: HashMap<~str, json::Json>) --> ~[(~str, object)] -{ +-> Vec<(~str, object)> { match device.get(&~"interfaces") { &json::List(ref interfaces) => { - interfaces.map(|interface| { + interfaces.iter().map(|interface| { add_interface(store, managed_ip.clone(), (*interface).clone()) - }) + }).collect() } _ => { error!("Expected list for {} interfaces but found {:?}", managed_ip, device.get(&~"interfaces")); - ~[] + Vec::new() } } } diff --git a/src/test/run-pass/issue-2904.rs b/src/test/run-pass/issue-2904.rs index 45f59fe9cd43d..ba23535fba1ea 100644 --- a/src/test/run-pass/issue-2904.rs +++ b/src/test/run-pass/issue-2904.rs @@ -18,6 +18,7 @@ extern crate extra; use std::io; use std::fmt; +use std::vec_ng::Vec; enum square { bot, @@ -62,17 +63,18 @@ fn square_from_char(c: char) -> square { } } -fn read_board_grid(mut input: rdr) -> ~[~[square]] { +fn read_board_grid(mut input: rdr) + -> Vec> { let mut input: &mut io::Reader = &mut input; - let mut grid = ~[]; + let mut grid = Vec::new(); let mut line = [0, ..10]; input.read(line); - let mut row = ~[]; + let mut row = Vec::new(); for c in line.iter() { row.push(square_from_char(*c as char)) } grid.push(row); - let width = grid[0].len(); + let width = grid.get(0).len(); for row in grid.iter() { assert!(row.len() == width) } grid } diff --git a/src/test/run-pass/issue-2989.rs b/src/test/run-pass/issue-2989.rs index 94e7297f17993..23c242e6b4450 100644 --- a/src/test/run-pass/issue-2989.rs +++ b/src/test/run-pass/issue-2989.rs @@ -10,37 +10,37 @@ extern crate extra; -use std::vec; +use std::vec_ng::Vec; trait methods { - fn to_bytes(&self) -> ~[u8]; + fn to_bytes(&self) -> Vec ; } impl methods for () { - fn to_bytes(&self) -> ~[u8] { - vec::from_elem(0, 0u8) + fn to_bytes(&self) -> Vec { + Vec::from_elem(0, 0u8) } } // the position of this function is significant! - if it comes before methods // then it works, if it comes after it then it doesn't! -fn to_bools(bitv: Storage) -> ~[bool] { - vec::from_fn(8, |i| { +fn to_bools(bitv: Storage) -> Vec { + Vec::from_fn(8, |i| { let w = i / 64; let b = i % 64; - let x = 1u64 & (bitv.storage[w] >> b); + let x = 1u64 & (*bitv.storage.get(w) >> b); x == 1u64 }) } -struct Storage { storage: ~[u64] } +struct Storage { storage: Vec } pub fn main() { - let bools = ~[false, false, true, false, false, true, true, false]; - let bools2 = to_bools(Storage{storage: ~[0b01100100]}); + let bools = vec!(false, false, true, false, false, true, true, false); + let bools2 = to_bools(Storage{storage: vec!(0b01100100)}); for i in range(0u, 8) { - println!("{} => {} vs {}", i, bools[i], bools2[i]); + println!("{} => {} vs {}", i, *bools.get(i), *bools2.get(i)); } assert_eq!(bools, bools2); diff --git a/src/test/run-pass/issue-3052.rs b/src/test/run-pass/issue-3052.rs index 8179d85e601f3..d2acf66003d7d 100644 --- a/src/test/run-pass/issue-3052.rs +++ b/src/test/run-pass/issue-3052.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type Connection = 'static |~[u8]|; +use std::vec_ng::Vec; + +type Connection = 'static |Vec |; fn f() -> Option { let mock_connection: Connection = |_| {}; diff --git a/src/test/run-pass/issue-3389.rs b/src/test/run-pass/issue-3389.rs index 45c0ea4d543ca..fb4d7cedd4b0b 100644 --- a/src/test/run-pass/issue-3389.rs +++ b/src/test/run-pass/issue-3389.rs @@ -8,12 +8,14 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + struct trie_node { - content: ~[~str], - children: ~[trie_node], + content: Vec<~str> , + children: Vec , } -fn print_str_vector(vector: ~[~str]) { +fn print_str_vector(vector: Vec<~str> ) { for string in vector.iter() { println!("{}", *string); } @@ -21,11 +23,11 @@ fn print_str_vector(vector: ~[~str]) { pub fn main() { let mut node: trie_node = trie_node { - content: ~[], - children: ~[] + content: Vec::new(), + children: Vec::new() }; - let v = ~[~"123", ~"abc"]; - node.content = ~[~"123", ~"abc"]; + let v = vec!(~"123", ~"abc"); + node.content = vec!(~"123", ~"abc"); print_str_vector(v); print_str_vector(node.content.clone()); diff --git a/src/test/run-pass/issue-3556.rs b/src/test/run-pass/issue-3556.rs index e7089a6a21e5f..31fe258f420c4 100644 --- a/src/test/run-pass/issue-3556.rs +++ b/src/test/run-pass/issue-3556.rs @@ -12,12 +12,14 @@ extern crate extra; +use std::vec_ng::Vec; + enum Token { Text(@~str), - ETag(@~[~str], @~str), - UTag(@~[~str], @~str), - Section(@~[~str], bool, @~[Token], @~str, @~str, @~str, @~str, @~str), - IncompleteSection(@~[~str], bool, @~str, bool), + ETag(@Vec<~str> , @~str), + UTag(@Vec<~str> , @~str), + Section(@Vec<~str> , bool, @Vec , @~str, @~str, @~str, @~str, @~str), + IncompleteSection(@Vec<~str> , bool, @~str, bool), Partial(@~str, @~str, @~str), } @@ -37,7 +39,7 @@ pub fn main() // assert!(check_strs(fmt!("%?", ETag(@~[~"foo"], @~"bar")), "ETag(@~[ ~\"foo\" ], @~\"bar\")")); let t = Text(@~"foo"); - let u = Section(@~[~"alpha"], true, @~[t], @~"foo", @~"foo", @~"foo", @~"foo", @~"foo"); + let u = Section(@vec!(~"alpha"), true, @vec!(t), @~"foo", @~"foo", @~"foo", @~"foo", @~"foo"); let v = format!("{:?}", u); // this is the line that causes the seg fault assert!(v.len() > 0); } diff --git a/src/test/run-pass/issue-3563-3.rs b/src/test/run-pass/issue-3563-3.rs index ae65c46ce71af..b50952552058e 100644 --- a/src/test/run-pass/issue-3563-3.rs +++ b/src/test/run-pass/issue-3563-3.rs @@ -20,9 +20,11 @@ extern crate extra; // Extern mod controls linkage. Use controls the visibility of names to modules that are // already linked in. Using WriterUtil allows us to use the write_line method. + use std::str; use std::vec; use std::fmt; +use std::vec_ng::Vec; // Represents a position on a canvas. struct Point { @@ -47,7 +49,7 @@ struct AsciiArt { width: uint, height: uint, fill: char, - lines: ~[~[char]], + lines: Vec > , // This struct can be quite large so we'll disable copying: developers need // to either pass these structs around via references or move them. @@ -63,9 +65,10 @@ impl Drop for AsciiArt { fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt { // Use an anonymous function to build a vector of vectors containing // blank characters for each position in our canvas. - let lines = vec::build(Some(height), |push| { - for _ in range(0, height) { push(vec::from_elem(width, '.')); } - }); + let mut lines = Vec::new(); + for _ in range(0, height) { + lines.push(Vec::from_elem(width, '.')); + } // Rust code often returns values by omitting the trailing semi-colon // instead of using an explicit return statement. @@ -86,8 +89,8 @@ impl AsciiArt { // element is: // 1) potentially large // 2) needs to be modified - let row = &mut self.lines[v]; - row[h] = self.fill; + let row = self.lines.get_mut(v); + *row.get_mut(h) = self.fill; } } } @@ -98,7 +101,7 @@ impl AsciiArt { impl fmt::Show for AsciiArt { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { // Convert each line into a string. - let lines = self.lines.map(|line| str::from_chars(*line)); + let lines = self.lines.map(|line| str::from_chars(line.as_slice())); // Concatenate the lines together using a new-line. write!(f.buf, "{}", lines.connect("\n")) diff --git a/src/test/run-pass/issue-3609.rs b/src/test/run-pass/issue-3609.rs index fe9c5d5491fee..6d900c845f6ba 100644 --- a/src/test/run-pass/issue-3609.rs +++ b/src/test/run-pass/issue-3609.rs @@ -12,8 +12,9 @@ extern crate extra; use std::comm::Chan; use std::task; +use std::vec_ng::Vec; -type RingBuffer = ~[f64]; +type RingBuffer = Vec ; type SamplesFn = proc(samples: &RingBuffer); enum Msg @@ -26,7 +27,7 @@ fn foo(name: ~str, samples_chan: Chan) { let mut samples_chan = samples_chan; let callback: SamplesFn = proc(buffer) { for i in range(0u, buffer.len()) { - error!("{}: {}", i, buffer[i]) + error!("{}: {}", i, *buffer.get(i)) } }; samples_chan.send(GetSamples(name.clone(), callback)); diff --git a/src/test/run-pass/issue-3991.rs b/src/test/run-pass/issue-3991.rs index d5dd090009a1c..7fb6b4664794a 100644 --- a/src/test/run-pass/issue-3991.rs +++ b/src/test/run-pass/issue-3991.rs @@ -8,13 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + struct HasNested { - nest: ~[~[int]], + nest: Vec > , } impl HasNested { fn method_push_local(&mut self) { - self.nest[0].push(0); + self.nest.get_mut(0).push(0); } } diff --git a/src/test/run-pass/issue-4036.rs b/src/test/run-pass/issue-4036.rs index 0298a2a324fec..13285179df8ca 100644 --- a/src/test/run-pass/issue-4036.rs +++ b/src/test/run-pass/issue-4036.rs @@ -14,10 +14,12 @@ // byproducts in vtable records. extern crate serialize; + use serialize::{json, Decodable}; +use std::vec_ng::Vec; pub fn main() { let json = json::from_str("[1]").unwrap(); let mut decoder = json::Decoder::new(json); - let _x: ~[int] = Decodable::decode(&mut decoder); + let _x: Vec = Decodable::decode(&mut decoder); } diff --git a/src/test/run-pass/issue-5708.rs b/src/test/run-pass/issue-5708.rs index 871ff89290960..56461b647d87a 100644 --- a/src/test/run-pass/issue-5708.rs +++ b/src/test/run-pass/issue-5708.rs @@ -18,6 +18,8 @@ This does not occur with concrete types, only with references to traits. */ +use std::vec_ng::Vec; + // original trait Inner { fn print(&self); @@ -50,7 +52,7 @@ pub fn main() { trait MyTrait { } pub struct MyContainer<'a, T> { - foos: ~[&'a MyTrait], + foos: Vec<&'a MyTrait> , } impl<'a, T> MyContainer<'a, T> { diff --git a/src/test/run-pass/issue-6153.rs b/src/test/run-pass/issue-6153.rs index 989a8e5f9c2c4..ce87b0adde5f4 100644 --- a/src/test/run-pass/issue-6153.rs +++ b/src/test/run-pass/issue-6153.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn swap(f: |~[int]| -> ~[int]) -> ~[int] { - let x = ~[1, 2, 3]; +use std::vec_ng::Vec; + +fn swap(f: |Vec | -> Vec ) -> Vec { + let x = vec!(1, 2, 3); f(x) } diff --git a/src/test/run-pass/issue-8898.rs b/src/test/run-pass/issue-8898.rs index ecb8e3ca0ed5d..66ddc1118d0dd 100644 --- a/src/test/run-pass/issue-8898.rs +++ b/src/test/run-pass/issue-8898.rs @@ -11,7 +11,6 @@ #[feature(managed_boxes)]; fn assert_repr_eq(obj : T, expected : ~str) { - assert_eq!(expected, format!("{:?}", obj)); } @@ -19,14 +18,12 @@ pub fn main() { let abc = [1, 2, 3]; let tf = [true, false]; let x = [(), ()]; - let y = ~[(), ()]; let slice = x.slice(0,1); let z = @x; assert_repr_eq(abc, ~"[1, 2, 3]"); assert_repr_eq(tf, ~"[true, false]"); assert_repr_eq(x, ~"[(), ()]"); - assert_repr_eq(y, ~"~[(), ()]"); assert_repr_eq(slice, ~"&[()]"); assert_repr_eq(&x, ~"&[(), ()]"); assert_repr_eq(z, ~"@[(), ()]"); diff --git a/src/test/run-pass/issue-9382.rs b/src/test/run-pass/issue-9382.rs index c5123f2311625..32ec1e674db7f 100644 --- a/src/test/run-pass/issue-9382.rs +++ b/src/test/run-pass/issue-9382.rs @@ -16,6 +16,8 @@ // from a vector to a slice. The drop glue was being invoked on // the temporary slice with a wrong type, triggering an LLVM assert. +use std::vec_ng::Vec; + struct Thing1<'a> { baz: &'a [~int], bar: ~u64, @@ -32,7 +34,7 @@ pub fn main() { bar: ~32, }; Thing1 { - baz: ~[], + baz: Vec::new().as_slice(), bar: ~32, }; let _t2_fixed = Thing2 { @@ -40,7 +42,7 @@ pub fn main() { bar: 32, }; Thing2 { - baz: ~[], + baz: Vec::new().as_slice(), bar: 32, }; } diff --git a/src/test/run-pass/ivec-add.rs b/src/test/run-pass/ivec-add.rs deleted file mode 100644 index ecf530f07f309..0000000000000 --- a/src/test/run-pass/ivec-add.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -fn double(a: T) -> ~[T] { return ~[a.clone()] + ~[a]; } - -fn double_int(a: int) -> ~[int] { return ~[a] + ~[a]; } - -pub fn main() { - let mut d = double(1); - assert_eq!(d[0], 1); - assert_eq!(d[1], 1); - - d = double_int(1); - assert_eq!(d[0], 1); - assert_eq!(d[1], 1); -} diff --git a/src/test/run-pass/ivec-pass-by-value.rs b/src/test/run-pass/ivec-pass-by-value.rs index 4a82e6844b979..9c8dd152e25b5 100644 --- a/src/test/run-pass/ivec-pass-by-value.rs +++ b/src/test/run-pass/ivec-pass-by-value.rs @@ -8,5 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn f(_a: ~[int]) { } -pub fn main() { f(~[1, 2, 3, 4, 5]); } +use std::vec_ng::Vec; + +fn f(_a: Vec ) { } +pub fn main() { f(vec!(1, 2, 3, 4, 5)); } diff --git a/src/test/run-pass/ivec-tag.rs b/src/test/run-pass/ivec-tag.rs index 302ea5a4b01ef..407e591895a47 100644 --- a/src/test/run-pass/ivec-tag.rs +++ b/src/test/run-pass/ivec-tag.rs @@ -9,18 +9,19 @@ // except according to those terms. use std::task; +use std::vec_ng::Vec; -fn producer(c: &Chan<~[u8]>) { +fn producer(c: &Chan >) { c.send( - ~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8, - 13u8]); + vec!(1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8, + 13u8)); } pub fn main() { - let (p, ch) = Chan::<~[u8]>::new(); + let (p, ch) = Chan:: >::new(); let _prod = task::spawn(proc() { producer(&ch) }); - let _data: ~[u8] = p.recv(); + let _data: Vec = p.recv(); } diff --git a/src/test/run-pass/lambda-infer-unresolved.rs b/src/test/run-pass/lambda-infer-unresolved.rs index 59baf63d28400..866982dc9c479 100644 --- a/src/test/run-pass/lambda-infer-unresolved.rs +++ b/src/test/run-pass/lambda-infer-unresolved.rs @@ -11,11 +11,13 @@ // This should typecheck even though the type of e is not fully // resolved when we finish typechecking the ||. -struct Refs { refs: ~[int], n: int } +use std::vec_ng::Vec; + +struct Refs { refs: Vec , n: int } pub fn main() { - let mut e = Refs{refs: ~[], n: 0}; + let mut e = Refs{refs: Vec::new(), n: 0}; let _f: || = || error!("{}", e.n); - let x: &[int] = e.refs; + let x: &[int] = e.refs.as_slice(); assert_eq!(x.len(), 0); } diff --git a/src/test/run-pass/linear-for-loop.rs b/src/test/run-pass/linear-for-loop.rs index 67bbd0967206b..5905e3a996c12 100644 --- a/src/test/run-pass/linear-for-loop.rs +++ b/src/test/run-pass/linear-for-loop.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = ~[1, 2, 3]; + let x = vec!(1, 2, 3); let mut y = 0; for i in x.iter() { info!("{:?}", *i); y += *i; } info!("{:?}", y); diff --git a/src/test/run-pass/liveness-move-in-loop.rs b/src/test/run-pass/liveness-move-in-loop.rs index d910ac9a4e77a..22a0c9005bafc 100644 --- a/src/test/run-pass/liveness-move-in-loop.rs +++ b/src/test/run-pass/liveness-move-in-loop.rs @@ -8,10 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn take(x: int) -> int {x} fn the_loop() { - let mut list = ~[]; + let mut list = Vec::new(); loop { let x = 5; if x > 3 { diff --git a/src/test/run-pass/log-poly.rs b/src/test/run-pass/log-poly.rs index c5221cd73d7ef..026138544b7d8 100644 --- a/src/test/run-pass/log-poly.rs +++ b/src/test/run-pass/log-poly.rs @@ -16,5 +16,5 @@ pub fn main() { info!("{}", 1); info!("{}", 2.0); warn!("{:?}", Three); - error!("{:?}", ~[4]); + error!("{:?}", vec!(4)); } diff --git a/src/test/run-pass/log-str.rs b/src/test/run-pass/log-str.rs deleted file mode 100644 index 8859b5336260c..0000000000000 --- a/src/test/run-pass/log-str.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::repr; - -pub fn main() { - let act = repr::repr_to_str(&~[1, 2, 3]); - assert_eq!(~"~[1, 2, 3]", act); - - let act = format!("{:?}/{:6?}", ~[1, 2, 3], ~"hi"); - assert_eq!(act, ~"~[1, 2, 3]/~\"hi\" "); -} diff --git a/src/test/run-pass/loop-scope.rs b/src/test/run-pass/loop-scope.rs index 436bdf256ca42..1dc3700194c51 100644 --- a/src/test/run-pass/loop-scope.rs +++ b/src/test/run-pass/loop-scope.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let x = ~[10, 20, 30]; + let x = vec!(10, 20, 30); let mut sum = 0; for x in x.iter() { sum += *x; } assert_eq!(sum, 60); diff --git a/src/test/run-pass/match-join.rs b/src/test/run-pass/match-join.rs index 90768fdc6c903..3b8073cfd06b3 100644 --- a/src/test/run-pass/match-join.rs +++ b/src/test/run-pass/match-join.rs @@ -8,12 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - extern crate extra; +use std::vec_ng::Vec; + fn foo(y: Option) { let mut x: int; - let mut rs: ~[int] = ~[]; + let mut rs: Vec = Vec::new(); /* tests that x doesn't get put in the precondition for the entire if expression */ diff --git a/src/test/run-pass/match-vec-rvalue.rs b/src/test/run-pass/match-vec-rvalue.rs index 20693897236a7..38952fc4daad2 100644 --- a/src/test/run-pass/match-vec-rvalue.rs +++ b/src/test/run-pass/match-vec-rvalue.rs @@ -10,13 +10,15 @@ // Tests that matching rvalues with drops does not crash. +use std::vec_ng::Vec; + pub fn main() { - match ~[1, 2, 3] { + match vec!(1, 2, 3) { x => { assert_eq!(x.len(), 3); - assert_eq!(x[0], 1); - assert_eq!(x[1], 2); - assert_eq!(x[2], 3); + assert_eq!(*x.get(0), 1); + assert_eq!(*x.get(1), 2); + assert_eq!(*x.get(2), 3); } } } diff --git a/src/test/run-pass/mod-view-items.rs b/src/test/run-pass/mod-view-items.rs index d3f79b9815ef0..84564802dcd63 100644 --- a/src/test/run-pass/mod-view-items.rs +++ b/src/test/run-pass/mod-view-items.rs @@ -18,7 +18,9 @@ mod m { use std::vec; - pub fn f() -> ~[int] { vec::from_elem(1u, 0) } + use std::vec_ng::Vec; + + pub fn f() -> Vec { Vec::from_elem(1u, 0) } } pub fn main() { let _x = m::f(); } diff --git a/src/test/run-pass/monad.rs b/src/test/run-pass/monad.rs index 42e782928b8da..182aa94700658 100644 --- a/src/test/run-pass/monad.rs +++ b/src/test/run-pass/monad.rs @@ -10,13 +10,15 @@ // ignore-fast +use std::vec_ng::Vec; + trait vec_monad { - fn bind(&self, f: |&A| -> ~[B]) -> ~[B]; + fn bind(&self, f: |&A| -> Vec ) -> Vec ; } -impl vec_monad for ~[A] { - fn bind(&self, f: |&A| -> ~[B]) -> ~[B] { - let mut r = ~[]; +impl vec_monad for Vec { + fn bind(&self, f: |&A| -> Vec ) -> Vec { + let mut r = Vec::new(); for elt in self.iter() { r.push_all_move(f(elt)); } @@ -44,8 +46,8 @@ fn transform(x: Option) -> Option<~str> { pub fn main() { assert_eq!(transform(Some(10)), Some(~"11")); assert_eq!(transform(None), None); - assert!((~[~"hi"]) - .bind(|x| ~[x.clone(), *x + "!"] ) - .bind(|x| ~[x.clone(), *x + "?"] ) == - ~[~"hi", ~"hi?", ~"hi!", ~"hi!?"]); + assert!((vec!(~"hi")) + .bind(|x| vec!(x.clone(), *x + "!") ) + .bind(|x| vec!(x.clone(), *x + "?") ) == + vec!(~"hi", ~"hi?", ~"hi!", ~"hi!?")); } diff --git a/src/test/run-pass/morestack6.rs b/src/test/run-pass/morestack6.rs index 1c4ff92907d61..8867c2bed0033 100644 --- a/src/test/run-pass/morestack6.rs +++ b/src/test/run-pass/morestack6.rs @@ -60,12 +60,12 @@ fn runtest2(f: extern fn(), frame_backoff: u32, last_stk: *u8) -> u32 { pub fn main() { use std::rand::Rng; - let fns = ~[ + let fns = vec!( calllink01, calllink02, calllink08, calllink10 - ]; + ); let mut rng = rand::rng(); for f in fns.iter() { let f = *f; diff --git a/src/test/run-pass/move-arg-2-unique.rs b/src/test/run-pass/move-arg-2-unique.rs index ed3cdc81c3179..34e169f3d61a9 100644 --- a/src/test/run-pass/move-arg-2-unique.rs +++ b/src/test/run-pass/move-arg-2-unique.rs @@ -8,13 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn test(foo: ~~[int]) { assert!((foo[0] == 10)); } +use std::vec_ng::Vec; + +fn test(foo: ~Vec ) { assert!((*foo.get(0) == 10)); } pub fn main() { - let x = ~~[10]; + let x = ~vec!(10); // Test forgetting a local by move-in test(x); // Test forgetting a temporary by move-in. - test(~~[10]); + test(~vec!(10)); } diff --git a/src/test/run-pass/move-arg-2.rs b/src/test/run-pass/move-arg-2.rs index 18cee34c25ca6..89316c37a3eda 100644 --- a/src/test/run-pass/move-arg-2.rs +++ b/src/test/run-pass/move-arg-2.rs @@ -10,13 +10,15 @@ #[feature(managed_boxes)]; -fn test(foo: @~[int]) { assert!((foo[0] == 10)); } +use std::vec_ng::Vec; + +fn test(foo: @Vec ) { assert!((*foo.get(0) == 10)); } pub fn main() { - let x = @~[10]; + let x = @vec!(10); // Test forgetting a local by move-in test(x); // Test forgetting a temporary by move-in. - test(@~[10]); + test(@vec!(10)); } diff --git a/src/test/run-pass/mutable-alias-vec.rs b/src/test/run-pass/mutable-alias-vec.rs index f512a4659853a..41c1e30b88aad 100644 --- a/src/test/run-pass/mutable-alias-vec.rs +++ b/src/test/run-pass/mutable-alias-vec.rs @@ -10,12 +10,14 @@ extern crate extra; -fn grow(v: &mut ~[int]) { +use std::vec_ng::Vec; + +fn grow(v: &mut Vec ) { v.push(1); } pub fn main() { - let mut v: ~[int] = ~[]; + let mut v: Vec = Vec::new(); grow(&mut v); grow(&mut v); grow(&mut v); diff --git a/src/test/run-pass/mutable-vec-drop.rs b/src/test/run-pass/mutable-vec-drop.rs index 2a04ca4ccd2ef..1f4196ef06f84 100644 --- a/src/test/run-pass/mutable-vec-drop.rs +++ b/src/test/run-pass/mutable-vec-drop.rs @@ -11,10 +11,12 @@ #[feature(managed_boxes)]; #[allow(unused_mut)]; +use std::vec_ng::Vec; + struct Pair { a: int, b: int} pub fn main() { // This just tests whether the vec leaks its members. - let mut _pvec: ~[@Pair] = - ~[@Pair{a: 1, b: 2}, @Pair{a: 3, b: 4}, @Pair{a: 5, b: 6}]; + let mut _pvec: Vec<@Pair> = + vec!(@Pair{a: 1, b: 2}, @Pair{a: 3, b: 4}, @Pair{a: 5, b: 6}); } diff --git a/src/test/run-pass/newtype-polymorphic.rs b/src/test/run-pass/newtype-polymorphic.rs index 7bc28e6b00ff5..3d4639b2506a0 100644 --- a/src/test/run-pass/newtype-polymorphic.rs +++ b/src/test/run-pass/newtype-polymorphic.rs @@ -8,23 +8,27 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + #[deriving(Clone)] -struct myvec(~[X]); +struct myvec(Vec ); -fn myvec_deref(mv: myvec) -> ~[X] { +fn myvec_deref(mv: myvec) -> Vec { let myvec(v) = mv; return v.clone(); } fn myvec_elt(mv: myvec) -> X { let myvec(v) = mv; - return v[0]; + return v.move_iter().next().unwrap(); } pub fn main() { - let mv = myvec(~[1, 2, 3]); - assert_eq!(myvec_deref(mv.clone())[1], 2); + let mv = myvec(vec!(1, 2, 3)); + let mv_clone = mv.clone(); + let mv_clone = myvec_deref(mv_clone); + assert_eq!(*mv_clone.get(1), 2); assert_eq!(myvec_elt(mv.clone()), 1); let myvec(v) = mv; - assert_eq!(v[2], 3); + assert_eq!(*v.get(2), 3); } diff --git a/src/test/run-pass/nullable-pointer-iotareduction.rs b/src/test/run-pass/nullable-pointer-iotareduction.rs index a922201c41ae4..c071983fdf334 100644 --- a/src/test/run-pass/nullable-pointer-iotareduction.rs +++ b/src/test/run-pass/nullable-pointer-iotareduction.rs @@ -11,6 +11,7 @@ #[feature(macro_rules)]; use std::{option, cast}; +use std::vec_ng::Vec; // Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions, // which "says that a destructor applied to an object built from a constructor @@ -77,7 +78,7 @@ pub fn main() { check_type!(~18: ~int); check_type!(@19: @int); check_type!(~"foo": ~str); - check_type!(~[20, 22]: ~[int]); + check_type!(vec!(20, 22): Vec ); let mint: uint = unsafe { cast::transmute(main) }; check_type!(main: fn(), |pthing| { assert!(mint == unsafe { cast::transmute(*pthing) }) diff --git a/src/test/run-pass/nullable-pointer-size.rs b/src/test/run-pass/nullable-pointer-size.rs index 84a6baa5de8a9..75a98913c971a 100644 --- a/src/test/run-pass/nullable-pointer-size.rs +++ b/src/test/run-pass/nullable-pointer-size.rs @@ -11,6 +11,7 @@ #[feature(macro_rules)]; use std::mem; +use std::vec_ng::Vec; enum E { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) } struct S(int, T); @@ -41,6 +42,5 @@ pub fn main() { check_type!(~int); check_type!(@int); check_type!(~str); - check_type!(~[int]); check_type!(extern fn()); } diff --git a/src/test/run-pass/objects-owned-object-borrowed-method-header.rs b/src/test/run-pass/objects-owned-object-borrowed-method-header.rs index 24c1b9d8fe8e7..ec284b24dbd1a 100644 --- a/src/test/run-pass/objects-owned-object-borrowed-method-header.rs +++ b/src/test/run-pass/objects-owned-object-borrowed-method-header.rs @@ -12,6 +12,8 @@ #[feature(managed_boxes)]; +use std::vec_ng::Vec; + // Test invoked `&self` methods on owned objects where the values // closed over contain managed values. This implies that the ~ boxes // will have headers that must be skipped over. @@ -31,13 +33,13 @@ impl FooTrait for BarStruct { } pub fn main() { - let foos: ~[ ~FooTrait: ] = ~[ + let foos: Vec<~FooTrait:> = vec!( ~BarStruct{ x: @0 } as ~FooTrait:, ~BarStruct{ x: @1 } as ~FooTrait:, ~BarStruct{ x: @2 } as ~FooTrait: - ]; + ); for i in range(0u, foos.len()) { - assert_eq!(i, foos[i].foo()); + assert_eq!(i, foos.get(i).foo()); } } diff --git a/src/test/run-pass/objects-owned-object-borrowed-method-headerless.rs b/src/test/run-pass/objects-owned-object-borrowed-method-headerless.rs index 72ae7cf9bb993..13258bed80f6c 100644 --- a/src/test/run-pass/objects-owned-object-borrowed-method-headerless.rs +++ b/src/test/run-pass/objects-owned-object-borrowed-method-headerless.rs @@ -12,6 +12,8 @@ // closed over do not contain managed values, and thus the ~ boxes do // not have headers. +use std::vec_ng::Vec; + trait FooTrait { fn foo(&self) -> uint; } @@ -27,13 +29,13 @@ impl FooTrait for BarStruct { } pub fn main() { - let foos: ~[ ~FooTrait ] = ~[ + let foos: Vec<~FooTrait> = vec!( ~BarStruct{ x: 0 } as ~FooTrait, ~BarStruct{ x: 1 } as ~FooTrait, ~BarStruct{ x: 2 } as ~FooTrait - ]; + ); for i in range(0u, foos.len()) { - assert_eq!(i, foos[i].foo()); + assert_eq!(i, foos.get(i).foo()); } } diff --git a/src/test/run-pass/overload-index-operator.rs b/src/test/run-pass/overload-index-operator.rs index b475222619d62..c918202b31c1f 100644 --- a/src/test/run-pass/overload-index-operator.rs +++ b/src/test/run-pass/overload-index-operator.rs @@ -12,10 +12,10 @@ // takes its argument *by reference*. use std::ops::Index; +use std::vec_ng::Vec; struct AssociationList { - pairs: ~[AssociationPair] -} + pairs: Vec> } #[deriving(Clone)] struct AssociationPair { @@ -44,7 +44,7 @@ pub fn main() { let foo = ~"foo"; let bar = ~"bar"; - let mut list = AssociationList {pairs: ~[]}; + let mut list = AssociationList {pairs: Vec::new()}; list.push(foo.clone(), 22); list.push(bar.clone(), 44); diff --git a/src/test/run-pass/overloaded-deref.rs b/src/test/run-pass/overloaded-deref.rs index 86046e8e05df6..43f68b4232910 100644 --- a/src/test/run-pass/overloaded-deref.rs +++ b/src/test/run-pass/overloaded-deref.rs @@ -10,6 +10,7 @@ use std::cell::RefCell; use std::rc::Rc; +use std::vec_ng::Vec; #[deriving(Eq, Show)] struct Point { @@ -42,8 +43,10 @@ pub fn main() { (*(*p).borrow_mut()).y += 3; assert_eq!(*(*p).borrow(), Point {x: 3, y: 5}); - let v = Rc::new(RefCell::new(~[1, 2, 3])); - (*(*v).borrow_mut())[0] = 3; - (*(*v).borrow_mut())[1] += 3; - assert_eq!(((*(*v).borrow())[0], (*(*v).borrow())[1], (*(*v).borrow())[2]), (3, 5, 3)); + let v = Rc::new(RefCell::new(vec!(1, 2, 3))); + *(*(*v).borrow_mut()).get_mut(0) = 3; + *(*(*v).borrow_mut()).get_mut(1) += 3; + assert_eq!((*(*(*v).borrow()).get(0), + *(*(*v).borrow()).get(1), + *(*(*v).borrow()).get(2)), (3, 5, 3)); } diff --git a/src/test/run-pass/packed-struct-generic-size.rs b/src/test/run-pass/packed-struct-generic-size.rs index 0b6ab579e6b73..02c030f3845c3 100644 --- a/src/test/run-pass/packed-struct-generic-size.rs +++ b/src/test/run-pass/packed-struct-generic-size.rs @@ -9,6 +9,7 @@ // except according to those terms. use std::mem; +use std::vec_ng::Vec; #[packed] struct S { @@ -22,6 +23,6 @@ pub fn main() { assert_eq!(mem::size_of::>(), 11); - assert_eq!(mem::size_of::>(), - 1 + mem::size_of::<~str>() + mem::size_of::<~[int]>()); + assert_eq!(mem::size_of:: >>(), + 1 + mem::size_of::<~str>() + mem::size_of:: >()); } diff --git a/src/test/run-pass/pure-sum.rs b/src/test/run-pass/pure-sum.rs index 17eab78f82084..cd5ce150bcb0d 100644 --- a/src/test/run-pass/pure-sum.rs +++ b/src/test/run-pass/pure-sum.rs @@ -10,31 +10,33 @@ // Check that functions can modify local state. -fn sums_to(v: ~[int], sum: int) -> bool { +use std::vec_ng::Vec; + +fn sums_to(v: Vec , sum: int) -> bool { let mut i = 0u; let mut sum0 = 0; while i < v.len() { - sum0 += v[i]; + sum0 += *v.get(i); i += 1u; } return sum0 == sum; } -fn sums_to_using_uniq(v: ~[int], sum: int) -> bool { +fn sums_to_using_uniq(v: Vec , sum: int) -> bool { let mut i = 0u; let mut sum0 = ~0; while i < v.len() { - *sum0 += v[i]; + *sum0 += *v.get(i); i += 1u; } return *sum0 == sum; } -fn sums_to_using_rec(v: ~[int], sum: int) -> bool { +fn sums_to_using_rec(v: Vec , sum: int) -> bool { let mut i = 0u; let mut sum0 = F {f: 0}; while i < v.len() { - sum0.f += v[i]; + sum0.f += *v.get(i); i += 1u; } return sum0.f == sum; @@ -42,11 +44,11 @@ fn sums_to_using_rec(v: ~[int], sum: int) -> bool { struct F { f: T } -fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool { +fn sums_to_using_uniq_rec(v: Vec , sum: int) -> bool { let mut i = 0u; let mut sum0 = F {f: ~0}; while i < v.len() { - *sum0.f += v[i]; + *sum0.f += *v.get(i); i += 1u; } return *sum0.f == sum; diff --git a/src/test/run-pass/rcvr-borrowed-to-slice.rs b/src/test/run-pass/rcvr-borrowed-to-slice.rs index 050a51c958d57..d8f47c6447b49 100644 --- a/src/test/run-pass/rcvr-borrowed-to-slice.rs +++ b/src/test/run-pass/rcvr-borrowed-to-slice.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + trait sum { fn sum_(self) -> int; } @@ -22,18 +24,18 @@ impl<'a> sum for &'a [int] { fn call_sum(x: &[int]) -> int { x.sum_() } pub fn main() { - let x = ~[1, 2, 3]; - let y = call_sum(x); + let x = vec!(1, 2, 3); + let y = call_sum(x.as_slice()); info!("y=={}", y); assert_eq!(y, 6); - let x = ~[1, 2, 3]; - let y = x.sum_(); + let x = vec!(1, 2, 3); + let y = x.as_slice().sum_(); info!("y=={}", y); assert_eq!(y, 6); - let x = ~[1, 2, 3]; - let y = x.sum_(); + let x = vec!(1, 2, 3); + let y = x.as_slice().sum_(); info!("y=={}", y); assert_eq!(y, 6); } diff --git a/src/test/run-pass/reflect-visit-type.rs b/src/test/run-pass/reflect-visit-type.rs index f81ddabf77c7f..7bca974c7b77e 100644 --- a/src/test/run-pass/reflect-visit-type.rs +++ b/src/test/run-pass/reflect-visit-type.rs @@ -11,9 +11,10 @@ #[feature(managed_boxes)]; use std::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Disr, Opaque}; +use std::vec_ng::Vec; struct MyVisitor { - types: ~[~str], + types: Vec<~str> , } impl TyVisitor for MyVisitor { @@ -145,16 +146,17 @@ fn visit_ty(v: &mut MyVisitor) { } pub fn main() { - let mut v = MyVisitor {types: ~[]}; + let mut v = MyVisitor {types: Vec::new()}; visit_ty::(&mut v); visit_ty::(&mut v); visit_ty::(&mut v); visit_ty::(&mut v); - visit_ty::<~[int]>(&mut v); for s in v.types.iter() { println!("type: {}", (*s).clone()); } - assert_eq!(v.types.clone(), ~[~"bool", ~"int", ~"i8", ~"i16", ~"[", ~"int", ~"]"]); + + let vec_types: Vec<~str> = v.types.clone().move_iter().collect(); + assert_eq!(vec_types, vec!(~"bool", ~"int", ~"i8", ~"i16")); } diff --git a/src/test/run-pass/regions-borrow-evec-uniq.rs b/src/test/run-pass/regions-borrow-evec-uniq.rs index 914c51eaa7012..f3f0724bd574a 100644 --- a/src/test/run-pass/regions-borrow-evec-uniq.rs +++ b/src/test/run-pass/regions-borrow-evec-uniq.rs @@ -8,16 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn foo(x: &[int]) -> int { x[0] } pub fn main() { - let p = ~[1,2,3,4,5]; - let r = foo(p); + let p = vec!(1,2,3,4,5); + let r = foo(p.as_slice()); assert_eq!(r, 1); - let p = ~[5,4,3,2,1]; - let r = foo(p); + let p = vec!(5,4,3,2,1); + let r = foo(p.as_slice()); assert_eq!(r, 5); } diff --git a/src/test/run-pass/regions-dependent-addr-of.rs b/src/test/run-pass/regions-dependent-addr-of.rs index de619685ca426..3f86f8612ed4c 100644 --- a/src/test/run-pass/regions-dependent-addr-of.rs +++ b/src/test/run-pass/regions-dependent-addr-of.rs @@ -11,6 +11,8 @@ // Test lifetimes are linked properly when we create dependent region pointers. // Issue #3148. +use std::vec_ng::Vec; + struct A { value: B } @@ -18,7 +20,7 @@ struct A { struct B { v1: int, v2: [int, ..3], - v3: ~[int], + v3: Vec , v4: C, v5: ~C, v6: Option @@ -41,7 +43,7 @@ fn get_v2<'v>(a: &'v A, i: uint) -> &'v int { fn get_v3<'v>(a: &'v A, i: uint) -> &'v int { let foo = &a.value; - &foo.v3[i] + foo.v3.get(i) } fn get_v4<'v>(a: &'v A, _i: uint) -> &'v int { @@ -84,7 +86,7 @@ fn get_v5_ref<'v>(a: &'v A, _i: uint) -> &'v int { pub fn main() { let a = A {value: B {v1: 22, v2: [23, 24, 25], - v3: ~[26, 27, 28], + v3: vec!(26, 27, 28), v4: C { f: 29 }, v5: ~C { f: 30 }, v6: Some(C { f: 31 })}}; @@ -96,7 +98,7 @@ pub fn main() { assert_eq!(*p, a.value.v2[1]); let p = get_v3(&a, 1); - assert_eq!(*p, a.value.v3[1]); + assert_eq!(*p, *a.value.v3.get(1)); let p = get_v4(&a, 1); assert_eq!(*p, a.value.v4.f); diff --git a/src/test/run-pass/regions-dependent-autoslice.rs b/src/test/run-pass/regions-dependent-autoslice.rs index dab881549c44c..3a472decc7c28 100644 --- a/src/test/run-pass/regions-dependent-autoslice.rs +++ b/src/test/run-pass/regions-dependent-autoslice.rs @@ -11,6 +11,8 @@ // Test lifetimes are linked properly when we autoslice a vector. // Issue #3148. +use std::vec_ng::Vec; + fn subslice1<'r>(v: &'r [uint]) -> &'r [uint] { v } fn both<'r>(v: &'r [uint]) -> &'r [uint] { @@ -18,6 +20,6 @@ fn both<'r>(v: &'r [uint]) -> &'r [uint] { } pub fn main() { - let v = ~[1,2,3]; - both(v); + let v = vec!(1,2,3); + both(v.as_slice()); } diff --git a/src/test/run-pass/regions-infer-borrow-scope-view.rs b/src/test/run-pass/regions-infer-borrow-scope-view.rs index 8f7452f2d06ed..b031cfea93e06 100644 --- a/src/test/run-pass/regions-infer-borrow-scope-view.rs +++ b/src/test/run-pass/regions-infer-borrow-scope-view.rs @@ -8,11 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + fn view<'r, T>(x: &'r [T]) -> &'r [T] {x} pub fn main() { - let v = ~[1, 2, 3]; - let x = view(v); - let y = view(x); - assert!((v[0] == x[0]) && (v[0] == y[0])); + let v = vec!(1, 2, 3); + let x = view(v.as_slice()); + let y = view(x.as_slice()); + assert!((*v.get(0) == x[0]) && (*v.get(0) == y[0])); } diff --git a/src/test/run-pass/regions-mock-tcx.rs b/src/test/run-pass/regions-mock-tcx.rs index c8e8c045614c3..fa2050c69f234 100644 --- a/src/test/run-pass/regions-mock-tcx.rs +++ b/src/test/run-pass/regions-mock-tcx.rs @@ -24,6 +24,7 @@ use collections::HashMap; use std::cast; use std::libc; use std::mem; +use std::vec_ng::Vec; type Type<'tcx> = &'tcx TypeStructure<'tcx>; @@ -44,7 +45,7 @@ impl<'tcx> Eq for TypeStructure<'tcx> { struct TypeContext<'tcx, 'ast> { ty_arena: &'tcx Arena, - types: ~[Type<'tcx>], + types: Vec> , type_table: HashMap>, ast_arena: &'ast Arena, @@ -55,7 +56,7 @@ impl<'tcx,'ast> TypeContext<'tcx, 'ast> { fn new(ty_arena: &'tcx Arena, ast_arena: &'ast Arena) -> TypeContext<'tcx, 'ast> { TypeContext { ty_arena: ty_arena, - types: ~[], + types: Vec::new(), type_table: HashMap::new(), ast_arena: ast_arena, diff --git a/src/test/run-pass/seq-compare.rs b/src/test/run-pass/seq-compare.rs index 86907bdf2a38f..8694040269c48 100644 --- a/src/test/run-pass/seq-compare.rs +++ b/src/test/run-pass/seq-compare.rs @@ -8,19 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - +use std::vec_ng::Vec; pub fn main() { assert!((~"hello" < ~"hellr")); assert!((~"hello " > ~"hello")); assert!((~"hello" != ~"there")); - assert!((~[1, 2, 3, 4] > ~[1, 2, 3])); - assert!((~[1, 2, 3] < ~[1, 2, 3, 4])); - assert!((~[1, 2, 4, 4] > ~[1, 2, 3, 4])); - assert!((~[1, 2, 3, 4] < ~[1, 2, 4, 4])); - assert!((~[1, 2, 3] <= ~[1, 2, 3])); - assert!((~[1, 2, 3] <= ~[1, 2, 3, 3])); - assert!((~[1, 2, 3, 4] > ~[1, 2, 3])); - assert_eq!(~[1, 2, 3], ~[1, 2, 3]); - assert!((~[1, 2, 3] != ~[1, 1, 3])); + assert!((vec!(1, 2, 3, 4) > vec!(1, 2, 3))); + assert!((vec!(1, 2, 3) < vec!(1, 2, 3, 4))); + assert!((vec!(1, 2, 4, 4) > vec!(1, 2, 3, 4))); + assert!((vec!(1, 2, 3, 4) < vec!(1, 2, 4, 4))); + assert!((vec!(1, 2, 3) <= vec!(1, 2, 3))); + assert!((vec!(1, 2, 3) <= vec!(1, 2, 3, 3))); + assert!((vec!(1, 2, 3, 4) > vec!(1, 2, 3))); + assert_eq!(vec!(1, 2, 3), vec!(1, 2, 3)); + assert!((vec!(1, 2, 3) != vec!(1, 1, 3))); } diff --git a/src/test/run-pass/shadow.rs b/src/test/run-pass/shadow.rs index c5211889f3f0c..73eab87a34d87 100644 --- a/src/test/run-pass/shadow.rs +++ b/src/test/run-pass/shadow.rs @@ -8,9 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(c: ~[int]) { +use std::vec_ng::Vec; + +fn foo(c: Vec ) { let a: int = 5; - let mut b: ~[int] = ~[]; + let mut b: Vec = Vec::new(); match none:: { @@ -27,4 +29,4 @@ fn foo(c: ~[int]) { enum t { none, some(T), } -pub fn main() { let x = 10; let x = x + 20; assert!((x == 30)); foo(~[]); } +pub fn main() { let x = 10; let x = x + 20; assert!((x == 30)); foo(Vec::new()); } diff --git a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs b/src/test/run-pass/shape_intrinsic_tag_then_rec.rs index cb8d73108748b..2f4a51bb6fa84 100644 --- a/src/test/run-pass/shape_intrinsic_tag_then_rec.rs +++ b/src/test/run-pass/shape_intrinsic_tag_then_rec.rs @@ -15,6 +15,8 @@ // interior record which is then itself interior to // something else, shape calculations were off. +use std::vec_ng::Vec; + #[deriving(Clone)] enum opt_span { //hack (as opposed to option), to make `span` compile @@ -40,8 +42,8 @@ type ty_ = uint; #[deriving(Clone)] struct Path_ { global: bool, - idents: ~[~str], - types: ~[@ty], + idents: Vec<~str> , + types: Vec<@ty>, } type path = Spanned; @@ -56,7 +58,11 @@ struct X { pub fn main() { let sp: Span = Span {lo: 57451u, hi: 57542u, expanded_from: os_none}; let t: @ty = @Spanned { data: 3u, span: sp }; - let p_: Path_ = Path_ { global: true, idents: ~[~"hi"], types: ~[t] }; + let p_: Path_ = Path_ { + global: true, + idents: vec!(~"hi"), + types: vec!(t), + }; let p: path = Spanned { data: p_, span: sp }; let x = X { sp: sp, path: p }; error!("{:?}", x.path.clone()); diff --git a/src/test/run-pass/size-and-align.rs b/src/test/run-pass/size-and-align.rs index 2caef2d1b9e13..360a8ae55d10f 100644 --- a/src/test/run-pass/size-and-align.rs +++ b/src/test/run-pass/size-and-align.rs @@ -8,23 +8,22 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - +use std::vec_ng::Vec; enum clam { a(T, int), b, } -fn uhoh(v: ~[clam]) { - match v[1] { - a::(ref _t, ref u) => { +fn uhoh(v: Vec> ) { + match v.get(1) { + &a::(ref _t, ref u) => { info!("incorrect"); info!("{:?}", u); fail!(); } - b:: => { info!("correct"); } + &b:: => { info!("correct"); } } } pub fn main() { - let v: ~[clam] = ~[b::, b::, a::(42, 17)]; + let v: Vec> = vec!(b::, b::, a::(42, 17)); uhoh::(v); } diff --git a/src/test/run-pass/static-impl.rs b/src/test/run-pass/static-impl.rs index bdfd40e860054..5a5e9f7353dc6 100644 --- a/src/test/run-pass/static-impl.rs +++ b/src/test/run-pass/static-impl.rs @@ -10,6 +10,8 @@ // ignore-fast +use std::vec_ng::Vec; + pub trait plus { fn plus(&self) -> int; } @@ -40,14 +42,14 @@ impl uint_utils for uint { trait vec_utils { fn length_(&self, ) -> uint; fn iter_(&self, f: |&T|); - fn map_(&self, f: |&T| -> U) -> ~[U]; + fn map_(&self, f: |&T| -> U) -> Vec ; } -impl vec_utils for ~[T] { +impl vec_utils for Vec { fn length_(&self) -> uint { self.len() } fn iter_(&self, f: |&T|) { for x in self.iter() { f(x); } } - fn map_(&self, f: |&T| -> U) -> ~[U] { - let mut r = ~[]; + fn map_(&self, f: |&T| -> U) -> Vec { + let mut r = Vec::new(); for elt in self.iter() { r.push(f(elt)); } @@ -59,9 +61,11 @@ pub fn main() { assert_eq!(10u.plus(), 30); assert_eq!((~"hi").plus(), 200); - assert_eq!((~[1]).length_().str(), ~"1"); - assert_eq!((~[3, 4]).map_(|a| *a + 4 )[0], 7); - assert_eq!((~[3, 4]).map_::(|a| *a as uint + 4u )[0], 7u); + assert_eq!((vec!(1)).length_().str(), ~"1"); + let vect = vec!(3, 4).map_(|a| *a + 4); + assert_eq!(*vect.get(0), 7); + let vect = (vec!(3, 4)).map_::(|a| *a as uint + 4u); + assert_eq!(*vect.get(0), 7u); let mut x = 0u; 10u.multi(|_n| x += 2u ); assert_eq!(x, 20u); diff --git a/src/test/run-pass/swap-2.rs b/src/test/run-pass/swap-2.rs index 208700fde8a8c..1a84406188828 100644 --- a/src/test/run-pass/swap-2.rs +++ b/src/test/run-pass/swap-2.rs @@ -9,14 +9,15 @@ // except according to those terms. use std::mem::swap; +use std::vec_ng::Vec; pub fn main() { - let mut a: ~[int] = ~[0, 1, 2, 3, 4, 5, 6]; + let mut a: Vec = vec!(0, 1, 2, 3, 4, 5, 6); a.swap(2, 4); - assert_eq!(a[2], 4); - assert_eq!(a[4], 2); + assert_eq!(*a.get(2), 4); + assert_eq!(*a.get(4), 2); let mut n = 42; - swap(&mut n, &mut a[0]); - assert_eq!(a[0], 42); + swap(&mut n, a.get_mut(0)); + assert_eq!(*a.get(0), 42); assert_eq!(n, 0); } diff --git a/src/test/run-pass/task-comm-16.rs b/src/test/run-pass/task-comm-16.rs index 6c0520b5f284c..68a1ff2474204 100644 --- a/src/test/run-pass/task-comm-16.rs +++ b/src/test/run-pass/task-comm-16.rs @@ -9,6 +9,7 @@ // except according to those terms. use std::cmp; +use std::vec_ng::Vec; // Tests of ports and channels on various types fn test_rec() { @@ -26,12 +27,12 @@ fn test_rec() { fn test_vec() { let (po, ch) = Chan::new(); - let v0: ~[int] = ~[0, 1, 2]; + let v0: Vec = vec!(0, 1, 2); ch.send(v0); let v1 = po.recv(); - assert_eq!(v1[0], 0); - assert_eq!(v1[1], 1); - assert_eq!(v1[2], 2); + assert_eq!(*v1.get(0), 0); + assert_eq!(*v1.get(1), 1); + assert_eq!(*v1.get(2), 2); } fn test_str() { diff --git a/src/test/run-pass/task-comm-3.rs b/src/test/run-pass/task-comm-3.rs index 732d72c11fec2..8416da227c78f 100644 --- a/src/test/run-pass/task-comm-3.rs +++ b/src/test/run-pass/task-comm-3.rs @@ -13,6 +13,7 @@ extern crate extra; use std::task; +use std::vec_ng::Vec; pub fn main() { info!("===== WITHOUT THREADS ====="); test00(); } @@ -38,7 +39,7 @@ fn test00() { let mut i: int = 0; // Create and spawn tasks... - let mut results = ~[]; + let mut results = Vec::new(); while i < number_of_tasks { let ch = ch.clone(); let mut builder = task::task(); diff --git a/src/test/run-pass/trait-bounds-in-arc.rs b/src/test/run-pass/trait-bounds-in-arc.rs index fa94f1012d026..3faf2315eb746 100644 --- a/src/test/run-pass/trait-bounds-in-arc.rs +++ b/src/test/run-pass/trait-bounds-in-arc.rs @@ -19,6 +19,7 @@ extern crate sync; use sync::Arc; use std::task; +use std::vec_ng::Vec; trait Pet { fn name(&self, blk: |&str|); @@ -65,10 +66,10 @@ pub fn main() { let dogge1 = Dogge { bark_decibels: 100, tricks_known: 42, name: ~"alan_turing" }; let dogge2 = Dogge { bark_decibels: 55, tricks_known: 11, name: ~"albert_einstein" }; let fishe = Goldfyshe { swim_speed: 998, name: ~"alec_guinness" }; - let arc = Arc::new(~[~catte as ~Pet:Freeze+Send, + let arc = Arc::new(vec!(~catte as ~Pet:Freeze+Send, ~dogge1 as ~Pet:Freeze+Send, ~fishe as ~Pet:Freeze+Send, - ~dogge2 as ~Pet:Freeze+Send]); + ~dogge2 as ~Pet:Freeze+Send)); let (p1,c1) = Chan::new(); let arc1 = arc.clone(); task::spawn(proc() { check_legs(arc1); c1.send(()); }); @@ -83,21 +84,21 @@ pub fn main() { p3.recv(); } -fn check_legs(arc: Arc<~[~Pet:Freeze+Send]>) { +fn check_legs(arc: Arc >) { let mut legs = 0; for pet in arc.get().iter() { legs += pet.num_legs(); } assert!(legs == 12); } -fn check_names(arc: Arc<~[~Pet:Freeze+Send]>) { +fn check_names(arc: Arc >) { for pet in arc.get().iter() { pet.name(|name| { assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8); }) } } -fn check_pedigree(arc: Arc<~[~Pet:Freeze+Send]>) { +fn check_pedigree(arc: Arc >) { for pet in arc.get().iter() { assert!(pet.of_good_pedigree()); } diff --git a/src/test/run-pass/trait-generic.rs b/src/test/run-pass/trait-generic.rs index 12bf4eef44ae4..5cc40f2dd37cb 100644 --- a/src/test/run-pass/trait-generic.rs +++ b/src/test/run-pass/trait-generic.rs @@ -10,6 +10,8 @@ // ignore-fast +use std::vec_ng::Vec; + trait to_str { fn to_string(&self) -> ~str; } @@ -24,29 +26,29 @@ impl to_str for () { } trait map { - fn map(&self, f: |&T| -> U) -> ~[U]; + fn map(&self, f: |&T| -> U) -> Vec ; } -impl map for ~[T] { - fn map(&self, f: |&T| -> U) -> ~[U] { - let mut r = ~[]; +impl map for Vec { + fn map(&self, f: |&T| -> U) -> Vec { + let mut r = Vec::new(); // FIXME: #7355 generates bad code with VecIterator for i in range(0u, self.len()) { - r.push(f(&self[i])); + r.push(f(self.get(i))); } r } } -fn foo>(x: T) -> ~[~str] { +fn foo>(x: T) -> Vec<~str> { x.map(|_e| ~"hi" ) } -fn bar>(x: T) -> ~[~str] { +fn bar>(x: T) -> Vec<~str> { x.map(|_e| _e.to_string() ) } pub fn main() { - assert_eq!(foo(~[1]), ~[~"hi"]); - assert_eq!(bar::(~[4, 5]), ~[~"4", ~"5"]); - assert_eq!(bar::<~str, ~[~str]>(~[~"x", ~"y"]), ~[~"x", ~"y"]); - assert_eq!(bar::<(), ~[()]>(~[()]), ~[~"()"]); + assert_eq!(foo(vec!(1)), vec!(~"hi")); + assert_eq!(bar:: >(vec!(4, 5)), vec!(~"4", ~"5")); + assert_eq!(bar::<~str, Vec<~str> >(vec!(~"x", ~"y")), vec!(~"x", ~"y")); + assert_eq!(bar::<(), Vec<()>>(vec!(())), vec!(~"()")); } diff --git a/src/test/run-pass/trait-to-str.rs b/src/test/run-pass/trait-to-str.rs index b6468b4483ddc..fa320bba98256 100644 --- a/src/test/run-pass/trait-to-str.rs +++ b/src/test/run-pass/trait-to-str.rs @@ -10,6 +10,8 @@ // ignore-fast +use std::vec_ng::Vec; + trait to_str { fn to_string(&self) -> ~str; } @@ -18,7 +20,7 @@ impl to_str for int { fn to_string(&self) -> ~str { self.to_str() } } -impl to_str for ~[T] { +impl to_str for Vec { fn to_string(&self) -> ~str { format!("[{}]", self.iter().map(|e| e.to_string()).to_owned_vec().connect(", ")) } @@ -26,15 +28,15 @@ impl to_str for ~[T] { pub fn main() { assert!(1.to_string() == ~"1"); - assert!((~[2, 3, 4]).to_string() == ~"[2, 3, 4]"); + assert!((vec!(2, 3, 4)).to_string() == ~"[2, 3, 4]"); fn indirect(x: T) -> ~str { x.to_string() + "!" } - assert!(indirect(~[10, 20]) == ~"[10, 20]!"); + assert!(indirect(vec!(10, 20)) == ~"[10, 20]!"); fn indirect2(x: T) -> ~str { indirect(x) } - assert!(indirect2(~[1]) == ~"[1]!"); + assert!(indirect2(vec!(1)) == ~"[1]!"); } diff --git a/src/test/run-pass/tydesc-name.rs b/src/test/run-pass/tydesc-name.rs index b3835ad5cdfad..42ce18dccaff9 100644 --- a/src/test/run-pass/tydesc-name.rs +++ b/src/test/run-pass/tydesc-name.rs @@ -19,7 +19,6 @@ struct Foo { pub fn main() { unsafe { assert_eq!((*get_tydesc::()).name, "int"); - assert_eq!((*get_tydesc::<~[int]>()).name, "~[int]"); assert_eq!((*get_tydesc::>()).name, "Foo"); } } diff --git a/src/test/run-pass/type-params-in-for-each.rs b/src/test/run-pass/type-params-in-for-each.rs index ff7ffb6dc6f00..c0a22bacfd21e 100644 --- a/src/test/run-pass/type-params-in-for-each.rs +++ b/src/test/run-pass/type-params-in-for-each.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + struct S { a: T, b: uint, @@ -18,9 +20,9 @@ fn range_(lo: uint, hi: uint, it: |uint|) { while lo_ < hi { it(lo_); lo_ += 1u; } } -fn create_index(_index: ~[S], _hash_fn: extern fn(T) -> uint) { +fn create_index(_index: Vec> , _hash_fn: extern fn(T) -> uint) { range_(0u, 256u, |_i| { - let _bucket: ~[T] = ~[]; + let _bucket: Vec = Vec::new(); }) } diff --git a/src/test/run-pass/unique-assign-generic.rs b/src/test/run-pass/unique-assign-generic.rs index 8fb2b9b40f4fb..1af120df470f5 100644 --- a/src/test/run-pass/unique-assign-generic.rs +++ b/src/test/run-pass/unique-assign-generic.rs @@ -18,6 +18,6 @@ fn f(t: T) -> T { pub fn main() { let t = f(~100); assert_eq!(t, ~100); - let t = f(~@~[100]); - assert_eq!(t, ~@~[100]); + let t = f(~@vec!(100)); + assert_eq!(t, ~@vec!(100)); } diff --git a/src/test/run-pass/unique-autoderef-index.rs b/src/test/run-pass/unique-autoderef-index.rs index 46f9ca794a9fe..87ce07c596ce5 100644 --- a/src/test/run-pass/unique-autoderef-index.rs +++ b/src/test/run-pass/unique-autoderef-index.rs @@ -8,7 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + pub fn main() { - let i = ~~[100]; - assert_eq!(i[0], 100); + let i = ~vec!(100); + assert_eq!(*i.get(0), 100); } diff --git a/src/test/run-pass/unique-create.rs b/src/test/run-pass/unique-create.rs index 9570c17c8654c..023917ec2e948 100644 --- a/src/test/run-pass/unique-create.rs +++ b/src/test/run-pass/unique-create.rs @@ -13,5 +13,5 @@ pub fn main() { } fn vec() { - ~[0]; + vec!(0); } diff --git a/src/test/run-pass/unique-drop-complex.rs b/src/test/run-pass/unique-drop-complex.rs index 2090352f9ce08..eb8fa640a0fd9 100644 --- a/src/test/run-pass/unique-drop-complex.rs +++ b/src/test/run-pass/unique-drop-complex.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - let _x = ~~[0,0,0,0,0]; + let _x = ~vec!(0,0,0,0,0); } diff --git a/src/test/run-pass/unique-in-vec-copy.rs b/src/test/run-pass/unique-in-vec-copy.rs index 3a27d7844bcad..9e73039a0a765 100644 --- a/src/test/run-pass/unique-in-vec-copy.rs +++ b/src/test/run-pass/unique-in-vec-copy.rs @@ -8,16 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; + pub fn main() { - let mut a = ~[~10]; + let mut a = vec!(~10); let b = a.clone(); - assert_eq!(*a[0], 10); - assert_eq!(*b[0], 10); + assert_eq!(**a.get(0), 10); + assert_eq!(**b.get(0), 10); // This should only modify the value in a, not b - *a[0] = 20; + **a.get_mut(0) = 20; - assert_eq!(*a[0], 20); - assert_eq!(*b[0], 10); + assert_eq!(**a.get(0), 20); + assert_eq!(**b.get(0), 10); } diff --git a/src/test/run-pass/unique-in-vec.rs b/src/test/run-pass/unique-in-vec.rs index 51fceae39b405..82d3a29d901ba 100644 --- a/src/test/run-pass/unique-in-vec.rs +++ b/src/test/run-pass/unique-in-vec.rs @@ -9,5 +9,6 @@ // except according to those terms. pub fn main() { - assert!((~[~100])[0] == ~100); + let vect = vec!(~100); + assert!(*vect.get(0) == ~100); } diff --git a/src/test/run-pass/utf8_chars.rs b/src/test/run-pass/utf8_chars.rs index 3066a247e4e6b..99d1c11d54bf3 100644 --- a/src/test/run-pass/utf8_chars.rs +++ b/src/test/run-pass/utf8_chars.rs @@ -11,17 +11,18 @@ extern crate extra; use std::str; +use std::vec_ng::Vec; pub fn main() { // Chars of 1, 2, 3, and 4 bytes - let chs: ~[char] = ~['e', 'é', '€', '\U00010000']; - let s: ~str = str::from_chars(chs); - let schs: ~[char] = s.chars().collect(); + let chs: Vec = vec!('e', 'é', '€', '\U00010000'); + let s: ~str = str::from_chars(chs.as_slice()); + let schs: Vec = s.chars().collect(); assert!(s.len() == 10u); assert!(s.char_len() == 4u); assert!(schs.len() == 4u); - assert!(str::from_chars(schs) == s); + assert!(str::from_chars(schs.as_slice()) == s); assert!(s.char_at(0u) == 'e'); assert!(s.char_at(1u) == 'é'); diff --git a/src/test/run-pass/vec-concat.rs b/src/test/run-pass/vec-concat.rs index 7014ad5df141d..bbf6960e377bd 100644 --- a/src/test/run-pass/vec-concat.rs +++ b/src/test/run-pass/vec-concat.rs @@ -8,12 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; +use std::vec_ng; + pub fn main() { - let a: ~[int] = ~[1, 2, 3, 4, 5]; - let b: ~[int] = ~[6, 7, 8, 9, 0]; - let v: ~[int] = a + b; - info!("{}", v[9]); - assert_eq!(v[0], 1); - assert_eq!(v[7], 8); - assert_eq!(v[9], 0); + let a: Vec = vec!(1, 2, 3, 4, 5); + let b: Vec = vec!(6, 7, 8, 9, 0); + let v: Vec = vec_ng::append(a, b.as_slice()); + info!("{}", *v.get(9)); + assert_eq!(*v.get(0), 1); + assert_eq!(*v.get(7), 8); + assert_eq!(*v.get(9), 0); } diff --git a/src/test/run-pass/vec-drop.rs b/src/test/run-pass/vec-drop.rs index d34350e969637..675c06c257042 100644 --- a/src/test/run-pass/vec-drop.rs +++ b/src/test/run-pass/vec-drop.rs @@ -10,11 +10,13 @@ #[feature(managed_boxes)]; +use std::vec_ng::Vec; + struct Pair { x: int, y: int } pub fn main() { // This just tests whether the vec leaks its members. - let _pvec: ~[@Pair] = - ~[@Pair{x: 1, y: 2}, @Pair{x: 3, y: 4}, @Pair{x: 5, y: 6}]; + let _pvec: Vec<@Pair> = + vec!(@Pair{x: 1, y: 2}, @Pair{x: 3, y: 4}, @Pair{x: 5, y: 6}); } diff --git a/src/test/run-pass/vec-growth.rs b/src/test/run-pass/vec-growth.rs index c9a4c57cc9d36..4414da91ce765 100644 --- a/src/test/run-pass/vec-growth.rs +++ b/src/test/run-pass/vec-growth.rs @@ -8,17 +8,17 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - +use std::vec_ng::Vec; pub fn main() { - let mut v = ~[1]; + let mut v = vec!(1); v.push(2); v.push(3); v.push(4); v.push(5); - assert_eq!(v[0], 1); - assert_eq!(v[1], 2); - assert_eq!(v[2], 3); - assert_eq!(v[3], 4); - assert_eq!(v[4], 5); + assert_eq!(*v.get(0), 1); + assert_eq!(*v.get(1), 2); + assert_eq!(*v.get(2), 3); + assert_eq!(*v.get(3), 4); + assert_eq!(*v.get(4), 5); } diff --git a/src/test/run-pass/vec-ivec-deadlock.rs b/src/test/run-pass/vec-ivec-deadlock.rs deleted file mode 100644 index ccc7768469dd1..0000000000000 --- a/src/test/run-pass/vec-ivec-deadlock.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#[allow(dead_assignment)]; - -pub fn main() { - let a = ~[1, 2, 3, 4, 5]; - let mut b = ~[a.clone(), a.clone()]; - b = b + b; // FIXME(#3387)---can't write b += b -} diff --git a/src/test/run-pass/vec-late-init.rs b/src/test/run-pass/vec-late-init.rs index 7ffbade05c1cc..2ce0bf228c9a8 100644 --- a/src/test/run-pass/vec-late-init.rs +++ b/src/test/run-pass/vec-late-init.rs @@ -8,10 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - +use std::vec_ng::Vec; pub fn main() { - let mut later: ~[int]; - if true { later = ~[1]; } else { later = ~[2]; } - info!("{}", later[0]); + let mut later: Vec ; + if true { later = vec!(1); } else { later = vec!(2); } + info!("{}", *later.get(0)); } diff --git a/src/test/run-pass/vec-push.rs b/src/test/run-pass/vec-push.rs index 50e76db031441..33f01c5bd41c8 100644 --- a/src/test/run-pass/vec-push.rs +++ b/src/test/run-pass/vec-push.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub fn main() { let mut v = ~[1, 2, 3]; v.push(1); } +pub fn main() { let mut v = vec!(1, 2, 3); v.push(1); } diff --git a/src/test/run-pass/vec-self-append.rs b/src/test/run-pass/vec-self-append.rs deleted file mode 100644 index e9fcfaaf2837f..0000000000000 --- a/src/test/run-pass/vec-self-append.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -extern crate extra; - -fn test_heap_to_heap() { - // a spills onto the heap - let mut a = ~[0, 1, 2, 3, 4]; - a = a + a; // FIXME(#3387)---can't write a += a - assert_eq!(a.len(), 10u); - assert_eq!(a[0], 0); - assert_eq!(a[1], 1); - assert_eq!(a[2], 2); - assert_eq!(a[3], 3); - assert_eq!(a[4], 4); - assert_eq!(a[5], 0); - assert_eq!(a[6], 1); - assert_eq!(a[7], 2); - assert_eq!(a[8], 3); - assert_eq!(a[9], 4); -} - -fn test_stack_to_heap() { - // a is entirely on the stack - let mut a = ~[0, 1, 2]; - // a spills to the heap - a = a + a; // FIXME(#3387)---can't write a += a - assert_eq!(a.len(), 6u); - assert_eq!(a[0], 0); - assert_eq!(a[1], 1); - assert_eq!(a[2], 2); - assert_eq!(a[3], 0); - assert_eq!(a[4], 1); - assert_eq!(a[5], 2); -} - -fn test_loop() { - // Make sure we properly handle repeated self-appends. - let mut a: ~[int] = ~[0]; - let mut i = 20; - let mut expected_len = 1u; - while i > 0 { - error!("{}", a.len()); - assert_eq!(a.len(), expected_len); - a = a + a; // FIXME(#3387)---can't write a += a - i -= 1; - expected_len *= 2u; - } -} - -pub fn main() { test_heap_to_heap(); test_stack_to_heap(); test_loop(); } diff --git a/src/test/run-pass/vec-slice.rs b/src/test/run-pass/vec-slice.rs index e3012b0862145..946b6a469daad 100644 --- a/src/test/run-pass/vec-slice.rs +++ b/src/test/run-pass/vec-slice.rs @@ -9,7 +9,7 @@ // except according to those terms. pub fn main() { - let v = ~[1,2,3,4,5]; + let v = vec!(1,2,3,4,5); let v2 = v.slice(1, 3); assert_eq!(v2[0], 2); assert_eq!(v2[1], 3); diff --git a/src/test/run-pass/vec-to_str.rs b/src/test/run-pass/vec-to_str.rs index e25b4de0a11c9..64072dab3e382 100644 --- a/src/test/run-pass/vec-to_str.rs +++ b/src/test/run-pass/vec-to_str.rs @@ -9,10 +9,10 @@ // except according to those terms. pub fn main() { - assert_eq!((~[0, 1]).to_str(), ~"[0, 1]"); + assert_eq!((vec!(0, 1)).to_str(), ~"[0, 1]"); assert_eq!((&[1, 2]).to_str(), ~"[1, 2]"); - let foo = ~[3, 4]; + let foo = vec!(3, 4); let bar = &[4, 5]; assert_eq!(foo.to_str(), ~"[3, 4]"); diff --git a/src/test/run-pass/vec-trailing-comma.rs b/src/test/run-pass/vec-trailing-comma.rs deleted file mode 100644 index 426416f63d307..0000000000000 --- a/src/test/run-pass/vec-trailing-comma.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// Issue #2482. - -pub fn main() { - let v1: ~[int] = ~[10, 20, 30,]; - let v2: ~[int] = ~[10, 20, 30]; - assert_eq!(v1[2], v2[2]); - let v3: ~[int] = ~[10,]; - let v4: ~[int] = ~[10]; - assert_eq!(v3[0], v4[0]); -} diff --git a/src/test/run-pass/vec.rs b/src/test/run-pass/vec.rs index cb67546dc1b00..7fd3b57b0e524 100644 --- a/src/test/run-pass/vec.rs +++ b/src/test/run-pass/vec.rs @@ -8,17 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - - +use std::vec_ng::Vec; pub fn main() { - let v: ~[int] = ~[10, 20]; - assert_eq!(v[0], 10); - assert_eq!(v[1], 20); - let mut x: int = 0; - assert_eq!(v[x], 10); - assert_eq!(v[x + 1], 20); + let v: Vec = vec!(10, 20); + assert_eq!(*v.get(0), 10); + assert_eq!(*v.get(1), 20); + let mut x: uint = 0; + assert_eq!(*v.get(x), 10); + assert_eq!(*v.get(x + 1), 20); x = x + 1; - assert_eq!(v[x], 20); - assert_eq!(v[x - 1], 10); + assert_eq!(*v.get(x), 20); + assert_eq!(*v.get(x - 1), 10); } diff --git a/src/test/run-pass/vector-no-ann-2.rs b/src/test/run-pass/vector-no-ann-2.rs index a2a8c8d2b34c6..56624cecdca35 100644 --- a/src/test/run-pass/vector-no-ann-2.rs +++ b/src/test/run-pass/vector-no-ann-2.rs @@ -10,4 +10,6 @@ #[feature(managed_boxes)]; -pub fn main() { let _quux: @~[uint] = @~[]; } +use std::vec_ng::Vec; + +pub fn main() { let _quux: @Vec = @Vec::new(); } diff --git a/src/test/run-pass/while-with-break.rs b/src/test/run-pass/while-with-break.rs index 57bc3bda9636a..6296296e3e007 100644 --- a/src/test/run-pass/while-with-break.rs +++ b/src/test/run-pass/while-with-break.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::vec_ng::Vec; pub fn main() { let mut i: int = 90; @@ -15,8 +16,8 @@ pub fn main() { info!("{}", i); i = i + 1; if i == 95 { - let _v: ~[int] = - ~[1, 2, 3, 4, 5]; // we check that it is freed by break + let _v: Vec = + vec!(1, 2, 3, 4, 5); // we check that it is freed by break info!("breaking"); break;