use std::libc;
+use std::vec_ng::Vec;
#[link(name="rustrt")]
extern {
pub fn rust_get_test_int() -> libc::intptr_t;
pub mod kitties {
pub struct cat<U> {
- priv info : ~[U],
+ priv info : Vec<U> ,
priv meows : uint,
how_hungry : int,
}
impl<U> cat<U> {
- pub fn speak<T>(&mut self, stuff: ~[T]) {
+ pub fn speak<T>(&mut self, stuff: Vec<T> ) {
self.meows += stuff.len();
}
pub fn meow_count(&mut self) -> uint { self.meows }
}
- pub fn cat<U>(in_x : uint, in_y : int, in_info: ~[U]) -> cat<U> {
+ pub fn cat<U>(in_x : uint, in_y : int, in_info: Vec<U> ) -> cat<U> {
cat {
meows: in_x,
how_hungry: in_y,
pub struct alist<A,B> {
eq_fn: extern "Rust" fn(A,A) -> bool,
- data: @RefCell<~[Entry<A,B>]>,
+ data: @RefCell<Vec<Entry<A,B>> >,
}
pub fn alist_add<A:'static,B:'static>(lst: &alist<A,B>, k: A, v: B) {
fn eq_int(a: int, b: int) -> bool { a == b }
return alist {
eq_fn: eq_int,
- data: @RefCell::new(~[]),
+ data: @RefCell::new(Vec::new()),
};
}
fn eq_int(a: int, b: int) -> bool { a == b }
return alist {
eq_fn: eq_int,
- data: @RefCell::new(~[]),
+ data: @RefCell::new(Vec::new()),
};
}
#[crate_id="cci_no_inline_lib"];
// same as cci_iter_lib, more-or-less, but not marked inline
-pub fn iter(v: ~[uint], f: |uint|) {
+pub fn iter(v: Vec<uint> , f: |uint|) {
let mut i = 0u;
let n = v.len();
while i < n {
use std::cell::RefCell;
use collections::HashMap;
-pub type header_map = HashMap<~str, @RefCell<~[@~str]>>;
+pub type header_map = HashMap<~str, @RefCell<vec!(@~str)>>;
// the unused ty param is necessary so this gets monomorphized
pub fn request<T>(req: &header_map) {
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub unsafe fn f(xs: ~[int]) {
+pub unsafe fn f(xs: Vec<int> ) {
xs.map(|_x| { unsafe fn q() { fail!(); } });
}
use std::os;
use std::str;
use std::slice;
+use std::vec;
use std::io::File;
macro_rules! bench (
}
fn shift_push() {
- let mut v1 = slice::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());
fn vec_plus() {
let mut r = rand::task_rng();
- let mut v = ~[];
+ let mut v = Vec::new();
let mut i = 0;
while i < 1500 {
let rv = slice::from_elem(r.gen_range(0u, i + 1), i);
fn vec_append() {
let mut r = rand::task_rng();
- let mut v = ~[];
+ let mut v = Vec::new();
let mut i = 0;
while i < 1500 {
let rv = slice::from_elem(r.gen_range(0u, i + 1), i);
if r.gen() {
- v = slice::append(v, rv);
+ v = vec::append(v, rv);
}
else {
- v = slice::append(rv, v);
+ v = vec::append(rv, v);
}
i += 1;
}
fn vec_push_all() {
let mut r = rand::task_rng();
- let mut v = ~[];
+ let mut v = Vec::new();
for i in range(0u, 1500) {
let mut rv = slice::from_elem(r.gen_range(0u, i + 1), i);
if r.gen() {
}
fn is_utf8_ascii() {
- let mut v : ~[u8] = ~[];
+ let mut v : Vec<u8> = Vec::new();
for _ in range(0u, 20000) {
v.push('b' as u8);
if !str::is_utf8(v) {
fn is_utf8_multibyte() {
let s = "b¢€ð¤¢";
- let mut v : ~[u8]= ~[];
+ let mut v : Vec<u8> = Vec::new();
for _ in range(0u, 5000) {
v.push_all(s.as_bytes());
if !str::is_utf8(v) {
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
};
let workers = from_str::<uint>(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();
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()
};
let workers = from_str::<uint>(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 (to_child, from_parent) = channel();
let mut builder = task::task();
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()
};
use std::uint;
// A poor man's pipe.
-type pipe = MutexArc<~[uint]>;
+type pipe = MutexArc<Vec<uint> >;
fn send(p: &pipe, msg: uint) {
unsafe {
}
fn init() -> (pipe,pipe) {
- let m = MutexArc::new(~[]);
+ let m = MutexArc::new(Vec::new());
((&m).clone(), m)
}
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()
};
let start = time::precise_time_s();
// create the ring
- let mut futures = ~[];
+ let mut futures = Vec::new();
for i in range(1u, num_tasks) {
//println!("spawning %?", i);
use std::uint;
// A poor man's pipe.
-type pipe = RWArc<~[uint]>;
+type pipe = RWArc<Vec<uint> >;
fn send(p: &pipe, msg: uint) {
p.write_cond(|state, cond| {
}
fn init() -> (pipe,pipe) {
- let x = RWArc::new(~[]);
+ let x = RWArc::new(Vec::new());
((&x).clone(), x)
}
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()
};
let start = time::precise_time_s();
// create the ring
- let mut futures = ~[];
+ let mut futures = Vec::new();
for i in range(1u, num_tasks) {
//println!("spawning %?", i);
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
};
}
}
-fn show_color_list(set: ~[color]) -> ~str {
+fn show_color_list(set: vec!(color)) -> ~str {
let mut out = ~"";
for col in set.iter() {
out.push_char(' ');
}
}
-fn rendezvous(nn: uint, set: ~[color]) {
+fn rendezvous(nn: uint, set: vec!(color)) {
// these ports will allow us to hear from the creatures
let (to_rendezvous, from_creatures) = channel::<CreatureInfo>();
// 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: ~[Sender<Option<CreatureInfo>>] =
+ let to_creature: Vec<Sender<Option<CreatureInfo>>> =
set.iter().enumerate().map(|(ii, col)| {
// create each creature as a listener with a port, and
// give us a channel to talk to each
}
// 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());
}
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
};
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));
}
];
// FIXME: Use map().
-fn sum_and_scale(a: &'static [AminoAcid]) -> ~[AminoAcid] {
- let mut result = ~[];
+fn sum_and_scale(a: &'static [AminoAcid]) -> Vec<AminoAcid> {
+ let mut result = Vec::new();
let mut p = 0f32;
for a_i in a.iter() {
let mut a_i = *a_i;
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.;
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
};
}
// 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<Vec<u8> , 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<u8> ,f64)> ) -> Vec<(Vec<u8> ,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() {
}
// given a map, search for the frequency of a pattern
-fn find(mm: &HashMap<~[u8], uint>, key: ~str) -> uint {
+fn find(mm: &HashMap<Vec<u8> , uint>, key: ~str) -> uint {
let key = key.into_ascii().to_lower().into_str();
match mm.find_equiv(&key.as_bytes()) {
option::None => { return 0u; }
}
// given a map, increment the counter for a key
-fn update_freq(mm: &mut HashMap<~[u8], uint>, key: &[u8]) {
+fn update_freq(mm: &mut HashMap<Vec<u8> , uint>, key: &[u8]) {
let key = key.to_owned();
let newval = match mm.pop(&key) {
Some(v) => v + 1,
// given a ~[u8], 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<u8> {
let mut ii = 0u;
let len = bb.len();
}
fn make_sequence_processor(sz: uint,
- from_parent: &Receiver<~[u8]>,
+ from_parent: &Receiver<Vec<u8>>,
to_parent: &Sender<~str>) {
- let mut freqs: HashMap<~[u8], uint> = HashMap::new();
- let mut carry: ~[u8] = ~[];
+ let mut freqs: HashMap<Vec<u8>, uint> = HashMap::new();
+ let mut carry = Vec::new();
let mut total: uint = 0u;
- let mut line: ~[u8];
+ let mut line: Vec<u8> ;
loop {
line = from_parent.recv();
- if line == ~[] { break; }
+ if line == Vec::new() { break; }
carry = windows_with_carry(carry + line, sz, |window| {
update_freq(&mut freqs, window);
let mut rdr = BufferedReader::new(rdr);
// initialize each sequence sorter
- let sizes = ~[1u,2,3,4,6,12,18];
- let mut streams = slice::from_fn(sizes.len(), |_| Some(channel::<~str>()));
- let mut from_child = ~[];
+ let sizes = vec!(1u,2,3,4,6,12,18);
+ let mut streams = Vec::from_fn(sizes.len(), |_| Some(channel::<~str>()));
+ 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);
});
to_child
- }).collect::<~[Sender<~[u8]>]>();
+ }).collect::<Vec<Sender<Vec<u8> >> >();
// latch stores true after we've started
// finish...
for (ii, _sz) in sizes.iter().enumerate() {
- to_child[ii].send(~[]);
+ to_child[ii].send(Vec::new());
}
// now fetch and print result messages
// 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;
struct Table {
count: i32,
- items: ~[Option<~Entry>]
-}
+ items: Vec<Option<~Entry>> }
struct Items<'a> {
cur: Option<&'a Entry>,
}
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));
}
// 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)]] {
+fn transform(piece: Vec<(int, int)> , all: bool) -> vec!(Vec<(int, int)> ) {
let mut res =
// rotations
iterate(piece, |rot| rot.iter().map(|&(y, x)| (x + y, -y)).collect())
// 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<Vec<Vec<u64> > > {
+ 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 =
// 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<Vec<u64> > ]) -> 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() {
}
// Filter the masks that we can prove to result to unfeasible board.
-fn filter_masks(masks: &[~[~[u64]]]) -> ~[~[~[u64]]] {
+fn filter_masks(masks: &[Vec<Vec<u64> > ]) -> Vec<Vec<Vec<u64> > > {
masks.iter().map(
|p| p.iter().map(
|p| p.iter()
// Converts a list of mask to a ~str.
fn to_utf8(raw_sol: &List<u64>) -> ~str {
- let mut sol: ~[u8] = std::slice::from_elem(50, '.' as u8);
+ let mut sol: Vec<u8> = Vec::from_elem(50, '.' as u8);
for &m in raw_sol.iter() {
let id = get_id(m);
for i in range(0, 50) {
// Search for every solutions. Returns false if the search was
// stopped before the end.
fn search(
- masks: &[~[~[u64]]],
+ masks: &[Vec<Vec<u64> > ],
board: u64,
mut i: int,
cur: List<u64>,
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
};
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());
}
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());
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
};
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<Vec<f64>>,
+ out: RWArc<Vec<f64>>,
+ f: fn(&Vec<f64>, 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
for () in rx.iter() {}
}
-fn mult_Av_impl(v: &~[f64], i: uint) -> f64 {
+fn mult_Av_impl(v: &Vec<f64> , i: uint) -> f64 {
let mut sum = 0.;
for (j, &v_j) in v.iter().enumerate() {
sum += v_j / A(i, j);
sum
}
-fn mult_Av(v: RWArc<~[f64]>, out: RWArc<~[f64]>) {
+fn mult_Av(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >) {
mult(v, out, mult_Av_impl);
}
-fn mult_Atv_impl(v: &~[f64], i: uint) -> f64 {
+fn mult_Atv_impl(v: &Vec<f64> , i: uint) -> f64 {
let mut sum = 0.;
for (j, &v_j) in v.iter().enumerate() {
sum += v_j / A(j, i);
sum
}
-fn mult_Atv(v: RWArc<~[f64]>, out: RWArc<~[f64]>) {
+fn mult_Atv(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >) {
mult(v, out, mult_Atv_impl);
}
-fn mult_AtAv(v: RWArc<~[f64]>, out: RWArc<~[f64]>, tmp: RWArc<~[f64]>) {
+fn mult_AtAv(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >, tmp: RWArc<Vec<f64> >) {
mult_Av(v, tmp.clone());
mult_Atv(tmp, out);
}
use std::from_str::FromStr;
let args = if os::getenv("RUST_BENCH").is_some() {
- ~[~"", ~"2000000", ~"503"]
+ vec!(~"", ~"2000000", ~"503")
}
else {
os::args()
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
};
//
// internal type of sudoku grids
-type grid = ~[~[u8]];
+type grid = Vec<Vec<u8> > ;
struct Sudoku {
grid: grid
pub fn read(mut reader: BufferedReader<StdReader>) -> Sudoku {
assert!(reader.read_line().unwrap() == ~"9,9"); /* assert first line is exactly "9,9" */
- let mut g = slice::from_fn(10u, { |_i| ~[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] });
+ let mut g = slice::from_fn(10u, { |_i| vec!(0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8) });
for line in reader.lines() {
- let comps: ~[&str] = line.unwrap().trim().split(',').collect();
+ let comps: Vec<&str> = line.trim().split(',').collect();
if comps.len() == 3u {
let row = from_str::<uint>(comps[0]).unwrap() as u8;
// 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];
managed: @nillist,
unique: ~nillist,
tuple: (@nillist, ~nillist),
- vec: ~[@nillist],
+ vec: vec!(@nillist),
res: r
}
managed: @Nil,
unique: ~Nil,
tuple: (@Nil, ~Nil),
- vec: ~[@Nil],
+ vec: vec!(@Nil),
res: r(@Nil)
}
}
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()
};
fn calc(children: uint, parent_wait_chan: &Sender<Sender<Sender<int>>>) {
- let wait_ports: ~[Receiver<Sender<Sender<int>>>] = slice::from_fn(children, |_| {
+ let wait_ports: Vec<Reciever<Sender<Sender<int>>>> = vec::from_fn(children, |_| {
let (wait_port, wait_chan) = stream::<Sender<Sender<int>>>();
task::spawn(proc() {
calc(children / 2, &wait_chan);
wait_port
});
- let child_start_chans: ~[Sender<Sender<int>>] =
+ let child_start_chans: Vec<Sender<Sender<int>>> =
wait_ports.move_iter().map(|port| port.recv()).collect();
let (start_port, start_chan) = stream::<Sender<int>>();
parent_wait_chan.send(start_chan);
let parent_result_chan: Sender<int> = start_port.recv();
- let child_sum_ports: ~[Receiver<int>] =
+ let child_sum_ports: Vec<Reciever<int>> =
child_start_chans.move_iter().map(|child_start_chan| {
let (child_sum_port, child_sum_chan) = stream::<int>();
child_start_chan.send(child_sum_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
};
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
};
// except according to those terms.
-struct sty(~[int]);
+struct sty(Vec<int> );
-fn unpack(_unpack: |v: &sty| -> ~[int]) {}
+fn unpack(_unpack: |v: &sty| -> Vec<int> ) {}
fn main() {
let _foo = unpack(|s| {
fn foo(&self) -> int;
}
-impl foo for ~[uint] {
+impl foo for Vec<uint> {
fn foo(&self) -> int {1} //~ NOTE candidate #1 is `~[uint].foo::foo`
}
-impl foo for ~[int] {
+impl foo for Vec<int> {
fn foo(&self) -> int {2} //~ NOTE candidate #2 is `~[int].foo::foo`
}
fn main() {
- let x = ~[];
+ let x = Vec::new();
x.foo(); //~ ERROR multiple applicable methods in scope
}
// 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`
}
mod m1 {}
-fn main(args: ~[str]) { log(debug, m1::a); }
+fn main(args: vec!(str)) { log(debug, m1::a); }
pub mod a {}
}
-fn main(args: ~[str]) { log(debug, m1::a); }
+fn main(args: vec!(str)) { log(debug, m1::a); }
// error-pattern: unresolved name
-fn main() { let foo = thing::len(~[]); }
+fn main() { let foo = thing::len(Vec::new()); }
}
fn a() {
- let mut p = ~[1];
+ let mut p = vec!(1);
// Create an immutable pointer into p's contents:
let q: &int = &p[0];
// 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,
fn c() {
// Legal because the scope of the borrow does not include the
// modification:
- let mut p = ~[1];
+ let mut p = vec!(1);
borrow(p, ||{});
p[0] = 5;
}
}
fn main() {
- let x = defer(~["Goodbye", "world!"]); //~ ERROR borrowed value does not live long enough
+ let x = defer(vec!("Goodbye", "world!")); //~ ERROR borrowed value does not live long enough
x.x[0];
}
}
fn has_mut_vec_and_does_not_try_to_change_it() {
- let mut v = ~[1, 2, 3];
+ let mut v = vec!(1, 2, 3);
takes_imm_elt(&v[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],
|| { //~ ERROR cannot borrow `v` as mutable
}
pub fn main() {
- let x = ~[
+ let x = vec!(
Foo { string: ~"foo" },
Foo { string: ~"bar" },
Foo { string: ~"baz" }
- ];
+ );
let x: &[Foo] = x;
match x {
[_, ..tail] => {
}
fn main() {
- let v = ~[1, 2, 3];
+ let v = vec!(1, 2, 3);
write(v); //~ ERROR cannot borrow
}
// except according to those terms.
fn a() -> &[int] {
- let vec = ~[1, 2, 3, 4];
+ let vec = vec!(1, 2, 3, 4);
let vec: &[int] = vec; //~ ERROR does not live long enough
let tail = match vec {
[_, ..tail] => tail,
}
fn b() -> &[int] {
- let vec = ~[1, 2, 3, 4];
+ let vec = vec!(1, 2, 3, 4);
let vec: &[int] = vec; //~ ERROR does not live long enough
let init = match vec {
[..init, _] => init,
}
fn c() -> &[int] {
- let vec = ~[1, 2, 3, 4];
+ let vec = vec!(1, 2, 3, 4);
let vec: &[int] = vec; //~ ERROR does not live long enough
let slice = match vec {
[_, ..slice, _] => slice,
// except according to those terms.
fn a() {
- let mut v = ~[1, 2, 3];
+ let mut v = vec!(1, 2, 3);
let vb: &mut [int] = v;
match vb {
[_a, ..tail] => {
}
fn b() {
- let mut vec = ~[~1, ~2, ~3];
+ let mut vec = vec!(~1, ~2, ~3);
let vec: &mut [~int] = vec;
match vec {
[.._b] => {
}
fn c() {
- let mut vec = ~[~1, ~2, ~3];
+ let mut vec = vec!(~1, ~2, ~3);
let vec: &mut [~int] = vec;
match vec {
[_a, .._b] => {
}
fn d() {
- let mut vec = ~[~1, ~2, ~3];
+ let mut vec = vec!(~1, ~2, ~3);
let vec: &mut [~int] = vec;
match vec {
[.._a, _b] => {
}
fn e() {
- let mut vec = ~[~1, ~2, ~3];
+ let mut vec = vec!(~1, ~2, ~3);
let vec: &mut [~int] = vec;
match vec {
[_a, _b, _c] => {} //~ ERROR cannot move out
// except according to those terms.
fn a() -> &int {
- let vec = ~[1, 2, 3, 4];
+ let vec = vec!(1, 2, 3, 4);
let vec: &[int] = vec; //~ ERROR `vec[..]` does not live long enough
let tail = match vec {
[_a, ..tail] => &tail[0],
#[feature(managed_boxes)];
-type Foo = ~[u8];
+type Foo = Vec<u8> ;
impl Drop for Foo { //~ ERROR the Drop trait may only be implemented
//~^ ERROR cannot provide an extension implementation
// except according to those terms.
fn main() {
- let v = ~[,]; //~ ERROR unexpected token: `,`
+ let v = vec!(); //~ ERROR unexpected token: `,`
}
#[feature(managed_boxes)];
-fn wants_uniq(x: ~[uint]) { }
+fn wants_uniq(x: Vec<uint> ) { }
fn wants_three(x: [uint, ..3]) { }
-fn has_uniq(x: ~[uint]) {
+fn has_uniq(x: Vec<uint> ) {
wants_uniq(x);
wants_three(x); //~ ERROR [] storage differs: expected `3` but found `~`
}
mod zed {
pub fn bar() { println!("bar"); }
}
-fn main(args: ~[str]) { bar(); }
+fn main(args: vec!(str)) { bar(); }
mod zed {
pub fn bar() { println!("bar3"); }
}
-fn main(args: ~[str]) { bar(); }
+fn main(args: vec!(str)) { bar(); }
// error-pattern: unresolved
use main::bar;
-fn main(args: ~[str]) { println!("foo"); }
+fn main() { println!("foo"); }
mod a { pub use b::foo; }
mod b { pub use a::foo; }
-fn main(args: ~[str]) { println!("loop"); }
+fn main() { println!("loop"); }
// error-pattern: illegal recursive type
-type x = ~[x];
+type x = vec!(x);
-fn main() { let b: x = ~[]; }
+fn main() { let b: x = Vec::new(); }
trait Serializable<'self, T> { //~ ERROR: no longer a special lifetime
- fn serialize(val : &'self T) -> ~[u8];
+ fn serialize(val : &'self T) -> Vec<u8> ;
fn deserialize(repr : &[u8]) -> &'self T;
}
impl<'self> Serializable<str> for &'self str {
- fn serialize(val : &'self str) -> ~[u8] {
- ~[1]
+ fn serialize(val : &'self str) -> Vec<u8> {
+ vec!(1)
}
fn deserialize(repr: &[u8]) -> &'self str {
"hi"
#[feature(managed_boxes)];
-static x: ~[int] = ~[123, 456]; //~ ERROR: static items are not allowed to have owned pointers
+static x: Vec<int> = vec!(123, 456); //~ ERROR: static items are not allowed to have owned pointers
fn main() {}
// error-pattern:expected `[` but found `~`
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."
- )]
+ ))
}
// except according to those terms.
trait vec_monad<A> {
- fn bind<B>(&self, f: |A| -> ~[B]);
+ fn bind<B>(&self, f: |A| -> Vec<B> );
}
-impl<A> vec_monad<A> for ~[A] {
- fn bind<B>(&self, f: |A| -> ~[B]) {
+impl<A> vec_monad<A> for Vec<A> {
+ fn bind<B>(&self, f: |A| -> Vec<B> ) {
let mut r = fail!();
for elt in self.iter() { r = r + f(*elt); }
//~^ ERROR the type of this value must be known
#[allow(dead_code)];
#[allow(deprecated_owned_vector)];
-fn fail_len(v: ~[int]) -> uint {
+fn fail_len(v: Vec<int> ) -> uint {
let mut i = 3;
fail!();
for x in v.iter() { i += 1u; }
// error-pattern: unresolved name `foobar`.
-fn main(args: ~[str]) { println!("{:?}", foobar); }
+fn main() { println!("{:?}", foobar); }
{
let mut res = foo(x);
- let mut v = ~[];
- v = ~[(res)] + v; //~ failed to find an implementation of trait
+ let mut v = Vec::new();
+ v = vec!((res)) + v; //~ failed to find an implementation of trait
assert_eq!(v.len(), 2);
}
// except according to those terms.
struct parser {
- tokens: ~[int],
+ tokens: Vec<int> ,
}
trait parse {
- fn parse(&self) -> ~[int];
+ fn parse(&self) -> Vec<int> ;
}
impl parse for parser {
- fn parse(&self) -> ~[int] {
+ fn parse(&self) -> Vec<int> {
self.tokens //~ ERROR cannot move out of dereference of `&`-pointer
}
}
// except according to those terms.
fn main() {
- let needlesArr: ~[char] = ~['a', 'f'];
+ let needlesArr: Vec<char> = vec!('a', 'f');
needlesArr.iter().fold(|x, y| {
});
//~^^ ERROR this function takes 2 parameters but 1 parameter was supplied
}
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);
};
struct Data(~Option<Data>);
-fn generic<T>( _ : ~[(Data,T)] ) {
+fn generic<T>( _ : Vec<(Data,T)> ) {
//~^ ERROR reached the recursion limit during monomorphization
- let rec : ~[(Data,(bool,T))] = ~[];
+ let rec : Vec<(Data,(bool,T))> = Vec::new();
generic( rec );
}
fn main () {
// Use generic<T> at least once to trigger instantiation.
- let input : ~[(Data,())] = ~[];
+ let input : Vec<(Data,())> = Vec::new();
generic(input);
}
// ~ pointers are ok
assert_freeze::<~int>();
assert_freeze::<~str>();
- assert_freeze::<~[int]>();
+ assert_freeze::<Vec<int> >();
// but not if they own a bad thing
assert_freeze::<~&'a mut int>(); //~ ERROR does not fulfill `Freeze`
// ~ 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::<Vec<int> >(); //~ ERROR does not fulfill `Pod`
assert_pod::<~&'a mut int>(); //~ ERROR does not fulfill `Pod`
// borrowed object types are generally ok
// ~ pointers are ok
assert_send::<~int>();
assert_send::<~str>();
- assert_send::<~[int]>();
+ assert_send::<Vec<int> >();
// but not if they own a bad thing
assert_send::<~&'a int>(); //~ ERROR does not fulfill `Send`
@2; //~ ERROR type uses managed
~2; //~ ERROR type uses owned
- ~[1]; //~ ERROR type uses owned
+ vec!(1); //~ ERROR type uses owned
//~^ ERROR type uses owned
fn g(_: ~Clone) {} //~ ERROR type uses owned
~""; //~ ERROR type uses owned
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 {
// 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);
});
#[allow(unused_mut)]
fn foo(mut a: int) {
let mut a = 3;
- let mut b = ~[2];
+ let mut b = vec!(2);
}
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();
use std::slice;
fn main() {
- let a: ~[int] = ~[];
+ let a: Vec<int> = Vec::new();
a.iter().advance(|_| -> bool {
//~^ ERROR mismatched types
});
// except according to those terms.
fn main() {
- let a = ~[];
+ let a = Vec::new();
match a {
[1, ..tail, ..tail] => {}, //~ ERROR: unexpected token: `..`
_ => ()
// except according to those terms.
fn main() {
- let x: ~[(int, int)] = ~[];
+ let x: Vec<(int, int)> = Vec::new();
let x: &[(int, int)] = x;
match x {
[a, (2, 3), _] => (),
_ => ()
}
- let x: ~[~str] = ~[~"foo", ~"bar", ~"baz"];
+ let x: Vec<~str> = vec!(~"foo", ~"bar", ~"baz");
let x: &[~str] = x;
match x {
[a, _, _, ..] => { println!("{}", a); }
_ => { }
}
- let x: ~[char] = ~['a', 'b', 'c'];
+ let x: Vec<char> = vec!('a', 'b', 'c');
let x: &[char] = x;
match x {
['a', 'b', 'c', .._tail] => {}
}
fn f20() {
- let x = ~[~"hi"];
+ let x = vec!(~"hi");
consume(x[0]);
touch(&x[0]); //~ ERROR use of partially moved value: `x`
}
}
fn f21() {
- let x = ~[1, 2, 3];
+ let x = vec!(1, 2, 3);
let _y = (x[0], 3);
touch(&x);
}
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 x = vec!(~"hi");
let _y = x[0];
touch(&x); //~ ERROR use of partially moved value: `x`
}
fn f110() {
- let x = ~[~"hi"];
+ let x = vec!(~"hi");
let _y = [x[0], ..1];
touch(&x); //~ ERROR use of partially 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]);
// except according to those terms.
// error-pattern:attempt to use a type argument out of scope
-fn hd<U>(v: ~[U]) -> U {
+fn hd<U>(v: Vec<U> ) -> U {
fn hd1(w: [U]) -> U { return w[0]; }
return hd1(v);
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() {
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() {
enum State { ST_NULL, ST_WHITESPACE }
fn main() {
- ~[ST_NULL, ..(ST_WHITESPACE as uint)];
+ vec!(ST_NULL, ..(ST_WHITESPACE as uint));
//~^ ERROR expected constant integer for repeat count but found variable
}
use std::libc;
fn main() {
- let x : *~[int] = &~[1,2,3];
+ let x : *Vec<int> = &vec!(1,2,3);
let y : *libc::c_void = x as *libc::c_void;
unsafe {
let _z = (*y).clone();
(_, a) => {}
(b, b) => {}
}
- let vec = ~[Some(42), None, Some(21)];
+ let vec = vec!(Some(42), None, Some(21));
let vec: &[Option<int>] = vec;
match vec {
//~^ ERROR non-exhaustive patterns: vectors of length 0 not covered
[Some(..), Some(..), ..tail] => {}
[None] => {}
}
- let vec = ~[1];
+ let vec = vec!(1);
let vec: &[int] = vec;
match vec {
[_, ..tail] => (),
[] => ()
}
- let vec = ~[0.5];
+ let vec = vec!(0.5);
let vec: &[f32] = vec;
match vec { //~ ERROR non-exhaustive patterns: vectors of length 4 not covered
[0.1, 0.2, 0.3] => (),
[0.1] => (),
[] => ()
}
- let vec = ~[Some(42), None, Some(21)];
+ let vec = vec!(Some(42), None, Some(21));
let vec: &[Option<int>] = vec;
match vec {
[Some(..), None, ..tail] => {}
// except according to those terms.
-enum bar { t1((), Option<~[int]>), t2, }
+enum bar { t1((), Option<Vec<int>>), 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!(); } } }
// error-pattern: mismatched types
-enum bar { t1((), Option<~[int]>), t2, }
+enum bar { t1((), Option<Vec<int> >), t2, }
fn foo(t: bar) {
match t {
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 {
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 {
// 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
fn main() {
let n = 1;
- let a = ~[0, ..n]; //~ ERROR expected constant integer for repeat count but found variable
+ let a = vec!(0, ..n); //~ ERROR expected constant integer for repeat count but found variable
}
fn main() {
trait seq { }
-impl<T> seq<T> for ~[T] { //~ ERROR wrong number of type arguments
+impl<T> seq<T> for Vec<T> { //~ ERROR wrong number of type arguments
/* ... */
}
impl seq<bool> for u32 {
#[no_implicit_prelude];
-fn last<T>(v: ~[&T]) -> std::option::Option<T> {
+fn last<T>(v: Vec<&T> ) -> std::option::Option<T> {
fail!();
}
// ~ to avoid infinite size.
struct Uninstantiable { //~ ERROR cannot be instantiated without an instance of itself
- p: ~[Uninstantiable, .. 1]
+ p: vec!(Uninstantiable, .. 1)
}
-struct Instantiable { p: ~[Instantiable, .. 0] }
+struct Instantiable { p: vec!(Instantiable, .. 0) }
fn main() {
}
}
-fn f<T>(_i: ~[T], _j: ~[T]) {
+fn f<T>(_i: Vec<T> , _j: Vec<T> ) {
}
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
println!("{:?}", (r2, i1.get()));
}
struct List {
- list: ~[~ToStr]
-}
+ list: Vec<~ToStr> }
impl List {
fn push(&mut self, n: ~ToStr) {
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`
+++ /dev/null
-// 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// 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]`
-// issue #367
-
-fn f() {
- let v = ~[1i];
- println!("{}", v.some_field_name); //type error
-}
-
-fn main() { }
// 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`
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;
println!("{}", j);
}
// except according to those terms.
fn main() {
- let _foo = ~[]; //~ ERROR unconstrained type
+ let _foo = Vec::new(); //~ ERROR unconstrained type
}
// except according to those terms.
fn main() {
- let v: ~[int] = ~[1, 2, 3];
+ let v: Vec<int> = vec!(1, 2, 3);
v[1] = 4; //~ ERROR cannot assign
}
fn main() {
- let unique: ~[i64] = ~[10, 11, 12, 13];
+ let unique: Vec<i64> = vec!(10, 11, 12, 13);
zzz();
}
// 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]);
}
fn main() {
- let unique: ~[@i64] = ~[@10, @11, @12, @13];
+ let unique: Vec<@i64> = vec!(@10, @11, @12, @13);
zzz();
}
}
fn test10() -> int {
- let regs = @~[0];
+ let regs = @vec!(0);
match true { true => { } _ => { } }
(*regs)[0]
}
-fn test11() -> ~[int] { if true { } ~[1, 2] }
+fn test11() -> Vec<int> { if true { } vec!(1, 2) }
let x = Some(3);
let _y =
match x {
- Some(_) => ~[~"some(_)", ~"not", ~"SO", ~"long", ~"string"],
- None => ~[~"none"]
+ Some(_) => vec!(~"some(_)", ~"not", ~"SO", ~"long", ~"string"),
+ None => vec!(~"none")
};
}
// pp-exact:vec-comments.pp
fn main() {
let _v1 =
- ~[
+ vec!(
// Comment
0,
// Comment
1,
// Comment
- 2];
+ 2);
let _v2 =
- ~[0, // Comment
+ vec!(0, // Comment
1, // Comment
- 2]; // Comment
+ 2); // Comment
let _v3 =
- ~[
+ vec!(
/* Comment */
0,
/* Comment */
1,
/* Comment */
- 2];
+ 2);
let _v4 =
- ~[0, /* Comment */
+ vec!(0, /* Comment */
1, /* Comment */
- 2]; /* Comment */
+ 2); /* Comment */
}
// pp-exact:vec-type.pp
-fn f1(_x: ~[int]) { }
+fn f1(_x: Vec<int> ) { }
-fn g1() { f1(~[1, 2, 3]); }
+fn g1() { f1(vec!(1, 2, 3)); }
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
#[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
idx as uint);
// This should fail.
- println!("ov3 0x%x", x[idx]);
+ println!("ov3 0x%x", x.as_slice()[idx]);
}
#[cfg(target_arch="x86_64")]
fn main() {
// This version just fails anyways, for symmetry on 64-bit hosts.
- let x = ~[1u,2u,3u];
- println!("ov3 0x%x", x[200]);
+ let x = vec!(1u,2u,3u);
+ error!("ov3 0x%x", x.as_slice()[200]);
}
// 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::<uint>();
// 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";
}
fn main() {
- let x = @~[0, 1, 2, 3, 4, 5];
+ let x = @vec!(0, 1, 2, 3, 4, 5);
failfn();
println!("{:?}", x);
}
fn b() { fail!(); }
fn main() {
- let _x = ~[0];
+ let _x = vec!(0);
a();
- let _y = ~[0];
+ let _y = vec!(0);
b();
}
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"]);
#[feature(managed_boxes)];
-fn f() -> ~[int] { fail!(); }
+fn f() -> Vec<int> { fail!(); }
// Voodoo. In unwind-alt we had to do this to trigger the bug. Might
// have been to do with memory allocation patterns.
#[feature(managed_boxes)];
-fn f() -> ~[int] { fail!(); }
+fn f() -> Vec<int> { fail!(); }
// Voodoo. In unwind-alt we had to do this to trigger the bug. Might
// have been to do with memory allocation patterns.
#[feature(managed_boxes)];
-fn f() -> ~[int] { fail!(); }
+fn f() -> Vec<int> { fail!(); }
// Voodoo. In unwind-alt we had to do this to trigger the bug. Might
// have been to do with memory allocation patterns.
}
fn partial() {
- let _x = ~[~[0], f(), ~[0]];
+ let _x = vec!(vec!(0), f(), vec!(0));
}
fn main() {
// error-pattern:fail
-fn build() -> ~[int] {
+fn build() -> Vec<int> {
fail!();
}
-struct Blk { node: ~[int] }
+struct Blk { node: Vec<int> }
fn main() {
let _blk = Blk {
// error-pattern:fail
-fn build1() -> ~[int] {
- ~[0,0,0,0,0,0,0]
+fn build1() -> Vec<int> {
+ vec!(0,0,0,0,0,0,0)
}
-fn build2() -> ~[int] {
+fn build2() -> Vec<int> {
fail!();
}
-struct Blk { node: ~[int], span: ~[int] }
+struct Blk { node: Vec<int> , span: Vec<int> }
fn main() {
let _blk = Blk {
// error-pattern:fail
-fn fold_local() -> @~[int]{
+fn fold_local() -> @Vec<int> {
fail!();
}
// error-pattern:fail
-fn fold_local() -> @~[int]{
- @~[0,0,0,0,0,0]
+fn fold_local() -> @Vec<int> {
+ @vec!(0,0,0,0,0,0)
}
-fn fold_remote() -> @~[int]{
+fn fold_remote() -> @Vec<int> {
fail!();
}
// error-pattern:index out of bounds: the len is 1 but the index is 2
fn main() {
- let v: ~[int] = ~[10];
+ let v: Vec<int> = vec!(10);
let x: int = 0;
assert_eq!(v[x], 10);
// Bounds-check failure.
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 {
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<syntax::ast::token_tree> = quote_tokens!(cx, 1 + 2);
+ let p_toks : Vec<syntax::ast::token_tree> = 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; );
enum option<T> { some(T), none, }
-struct R<T> {v: ~[option<T>]}
+struct R<T> {v: Vec<option<T>> }
-fn f<T>() -> ~[T] { return ~[]; }
+fn f<T>() -> Vec<T> { return Vec::new(); }
-pub fn main() { let mut r: R<int> = R {v: ~[]}; r.v = f(); }
+pub fn main() { let mut r: R<int> = R {v: Vec::new()}; r.v = f(); }
}
}
-impl<A> iterable<A> for ~[A] {
+impl<A> iterable<A> for Vec<A> {
fn iterate(&self, f: |x: &A| -> bool) -> bool {
self.iter().advance(f)
}
}
pub fn main() {
- let x = ~[0,1,2,3];
+ let x = vec!(0,1,2,3);
// Call a method
x.iterate(|y| { assert!(x[*y] == *y); true });
// Call a parameterized function
}
#[deriving(Decodable, Encodable)]
-struct SomeStruct { v: ~[uint] }
+struct SomeStruct { v: Vec<uint> }
#[deriving(Decodable, Encodable)]
struct Point {x: uint, y: uint}
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;
}
// NB: Associativity of ~, etc. in this context is surprising. These must be parenthesized
([1]).test_imm();
- (~[1]).test_imm();
+ (vec!(1)).test_imm();
(&[1]).test_imm();
("test").test_imm();
(~"test").test_imm();
fn push_val(&mut self, t: T);
}
-impl<T> Pushable<T> for ~[T] {
+impl<T> Pushable<T> for Vec<T> {
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));
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn f<T>(x: ~[T]) -> T { return x[0]; }
+fn f<T>(x: Vec<T> ) -> T { return x[0]; }
-fn g(act: |~[int]| -> int) -> int { return act(~[1, 2, 3]); }
+fn g(act: |Vec<int> | -> 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");
}
// 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() {
// ignore-fast
-fn iter_vec<T>(v: ~[T], f: |&T|) { for x in v.iter() { f(x); } }
+fn iter_vec<T>(v: Vec<T> , 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 {
// ignore-fast
-fn iter_vec<T>(v: ~[T], f: |&T|) { for x in v.iter() { f(x); } }
+fn iter_vec<T>(v: Vec<T> , 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| {
}
pub fn main() {
- let items = ~[ 3, 5, 1, 2, 4 ];
+ let items = vec!( 3, 5, 1, 2, 4 );
items.foo();
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-struct F { f: ~[int] }
+struct F { f: Vec<int> }
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} => {
use std::mem::swap;
-struct Ints {sum: ~int, values: ~[int]}
+struct Ints {sum: ~int, values: Vec<int> }
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);
}
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);
sum
}
-fn has_mut_vec(v: ~[int]) -> int {
+fn has_mut_vec(v: Vec<int> ) -> int {
want_slice(v)
}
pub fn main() {
- assert_eq!(has_mut_vec(~[1, 2, 3]), 6);
+ assert_eq!(has_mut_vec(vec!(1, 2, 3)), 6);
}
#[feature(managed_boxes)];
struct F { f: @G }
-struct G { g: ~[int] }
+struct G { g: Vec<int> }
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 {}
}
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));
fn foo() -> int { 22 }
pub fn main() {
- let mut x: ~[extern "Rust" fn() -> int] = ~[];
+ let mut x: vec!(extern "Rust" fn() -> int) = Vec::new();
x.push(foo);
assert_eq!((x[0])(), 22);
}
// actually working.
//let bt0 = sys::frame_address();
//println!("%?", bt0);
- iter(~[1u, 2u, 3u], |i| {
+ iter(vec!(1u, 2u, 3u), |i| {
println!("{}", i);
//let bt1 = sys::frame_address();
use cci_class_6::kitties::cat;
pub fn main() {
- let mut nyan : cat<char> = cat::<char>(52u, 99, ~['p']);
- let mut kitty = cat(1000u, 2, ~[~"tabby"]);
+ let mut nyan : cat<char> = cat::<char>(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);
}
// except according to those terms.
struct cat<U> {
- info : ~[U],
+ info : Vec<U> ,
meows : uint,
how_hungry : int,
}
impl<U> cat<U> {
- pub fn speak<T>(&mut self, stuff: ~[T]) {
+ pub fn speak<T>(&mut self, stuff: Vec<T> ) {
self.meows += stuff.len();
}
pub fn meow_count(&mut self) -> uint { self.meows }
}
-fn cat<U>(in_x : uint, in_y : int, in_info: ~[U]) -> cat<U> {
+fn cat<U>(in_x : uint, in_y : int, in_info: Vec<U> ) -> cat<U> {
cat {
meows: in_x,
how_hungry: in_y,
}
pub fn main() {
- let mut nyan : cat<int> = cat::<int>(52u, 99, ~[9]);
- let mut kitty = cat(1000u, 2, ~[~"tabby"]);
+ let mut nyan : cat<int> = cat::<int>(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);
}
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]));
+ end_of_block!(_, &((&vec!(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:
fail!()
}
-fn get_bar(x: uint) -> ~[uint] { ~[x * 2] }
+fn get_bar(x: uint) -> Vec<uint> { vec!(x * 2) }
pub fn fails() {
let x = 2;
- let mut y = ~[];
+ let mut y = Vec::new();
y.push(~Bickwick(do_it(get_bar(x))));
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn bar(v: &mut [uint]) -> ~[uint] {
+fn bar(v: &mut [uint]) -> Vec<uint> {
v.to_owned()
}
-fn bip(v: &[uint]) -> ~[uint] {
+fn bip(v: &[uint]) -> Vec<uint> {
v.to_owned()
}
pub fn main() {
- let mut the_vec = ~[1u, 2, 3, 100];
+ let mut the_vec = vec!(1u, 2, 3, 100);
assert_eq!(the_vec.clone(), bar(the_vec));
assert_eq!(the_vec.clone(), bip(the_vec));
}
}
pub fn main() {
- let mut the_vec = ~[1, 2, 3, 100];
+ let mut the_vec = vec!(1, 2, 3, 100);
bar(the_vec);
- assert_eq!(the_vec, ~[100, 3, 2, 1]);
+ assert_eq!(the_vec, vec!(100, 3, 2, 1));
}
}
pub fn main() {
- let mut the_vec = ~[1, 2, 3, 100];
+ let mut the_vec = vec!(1, 2, 3, 100);
bar(the_vec);
- assert_eq!(the_vec, ~[100, 3, 2, 1]);
+ assert_eq!(the_vec, vec!(100, 3, 2, 1));
}
enum State { ST_NULL, ST_WHITESPACE = 1 }
pub fn main() {
- ~[ST_NULL, ..(ST_WHITESPACE as uint)];
+ vec!(ST_NULL, ..(ST_WHITESPACE as uint));
}
#[allow(unused_mut)];
-pub fn main() { let mut _v: ~[int] = ~[]; }
+pub fn main() { let mut _v: Vec<int> = Vec::new(); }
}
fn test_vec() {
- fn f() -> ~[int] { ~[10, 11] }
+ fn f() -> Vec<int> { vec!(10, 11) }
assert_eq!(f()[1], 11);
}
}
fn test_box() {
- let r = match true { true => { ~[10] } false => { fail!() } };
+ let r = match true { true => { vec!(10) } false => { fail!() } };
assert_eq!(r[0], 10);
}
#[feature(managed_boxes)];
pub fn main() {
- let v: ~[int] = ~[ 1, ..5 ];
+ let v: Vec<int> = vec!( 1, ..5 );
println!("{}", v[0]);
println!("{}", v[1]);
println!("{}", v[2]);
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);
}
}
// 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"); } }
+pub fn main() { let x: Vec<int> = Vec::new(); for _ in x.iter() { fail!("moop"); } }
fn two(it: |int|) { it(0); it(1); }
pub fn main() {
- let mut a: ~[int] = ~[-1, -1, -1, -1];
+ let mut a: Vec<int> = vec!(-1, -1, -1, -1);
let mut p: int = 0;
two(|i| {
two(|j| { a[p] = 10 * i + j; p += 1; })
enum wrapper<T> { 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)); }
#[feature(managed_boxes)];
fn f<T>(_v: @T) { }
-pub fn main() { f(@~[1, 2, 3, 4, 5]); }
+pub fn main() { f(@vec!(1, 2, 3, 4, 5)); }
// except according to those terms.
trait vec_utils<T> {
- fn map_<U>(x: &Self, f: |&T| -> U) -> ~[U];
+ fn map_<U>(x: &Self, f: |&T| -> U) -> Vec<U> ;
}
-impl<T> vec_utils<T> for ~[T] {
- fn map_<U>(x: &~[T], f: |&T| -> U) -> ~[U] {
- let mut r = ~[];
+impl<T> vec_utils<T> for Vec<T> {
+ fn map_<U>(x: &Vec<T> , f: |&T| -> U) -> Vec<U> {
+ let mut r = Vec::new();
for elt in x.iter() {
r.push(f(elt));
}
}
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));
}
use getopts::{optopt, getopts};
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) {
Ok(ref m) =>
os::getcwd().join(&Path::new(path))
}
- fn glob_vec(pattern: &str) -> ~[Path] {
+ fn glob_vec(pattern: &str) -> Vec<Path> {
glob(pattern).collect()
}
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/]")));
}
}
pub type mapper = extern fn(~str, putter);
- enum ctrl_proto { find_reducer(~[u8], Sender<int>), mapper_done, }
+ enum ctrl_proto { find_reducer(Vec<u8>, Sender<int>), mapper_done, }
- fn start_mappers(ctrl: Sender<ctrl_proto>, inputs: ~[~str]) {
+ fn start_mappers(ctrl: Sender<ctrl_proto>, inputs: Vec<~str>) {
for i in inputs.iter() {
let ctrl = ctrl.clone();
let i = i.clone();
ctrl_clone.send(mapper_done);
}
- pub fn map_reduce(inputs: ~[~str]) {
+ pub fn map_reduce(inputs: Vec<~str>) {
let (tx, rx) = channel();
// This task becomes the master control task. It spawns others
}
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"));
}
parse_node!(
[$(: $tags ($(:$tag_nodes),*))*];
[$(:$head_nodes,)* :tag(stringify!($head).to_owned(),
- ~[$($nodes),*])];
+ vec!($($nodes),*))];
$($rest)*
)
);
}
enum HTMLFragment {
- tag(~str, ~[HTMLFragment]),
+ tag(~str, Vec<HTMLFragment> ),
text(~str),
}
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]);
+ assert_eq!(from_fn(2, |i| 2*(i+1)), vec!(2, 4));
}
// issue #680
-fn f() -> ~[int] { ~[] }
+fn f() -> Vec<int> { Vec::new() }
pub fn main() { }
// This is a testcase for issue #94.
pub fn main() {
- let v: ~[int] = ~[0, 1, 2, 3, 4, 5];
+ let v: Vec<int> = vec!(0, 1, 2, 3, 4, 5);
let s: ~str = ~"abcdef";
assert_eq!(v[3u], 3);
assert_eq!(v[3u8], 3);
// Issue #1821 - Don't recurse trying to typecheck this
enum t {
- foo(~[t])
+ foo(vec!(t))
}
pub fn main() {}
// except according to those terms.
struct font<'a> {
- fontbuf: &'a ~[u8],
+ fontbuf: &'a Vec<u8> ,
}
impl<'a> font<'a> {
- pub fn buf(&self) -> &'a ~[u8] {
+ pub fn buf(&self) -> &'a Vec<u8> {
self.fontbuf
}
}
-fn font<'r>(fontbuf: &'r ~[u8]) -> font<'r> {
+fn font<'r>(fontbuf: &'r Vec<u8> ) -> font<'r> {
font {
fontbuf: fontbuf
}
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::<int>(&m);
pub fn main() {
unsafe {
- f(~[2]);
+ f(vec!(2));
}
}
}
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) =>
{
println!("Expected list for {} interfaces but found {:?}", managed_ip,
device.get(&~"interfaces"));
- ~[]
+ Vec::new()
}
}
}
}
}
-fn read_board_grid<rdr:'static + io::Reader>(mut input: rdr) -> ~[~[square]] {
+fn read_board_grid<rdr:'static + io::Reader>(mut input: rdr) -> vec!(vec!(square)) {
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))
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use std::slice;
-
trait methods {
- fn to_bytes(&self) -> ~[u8];
+ fn to_bytes(&self) -> Vec<u8> ;
}
impl methods for () {
- fn to_bytes(&self) -> ~[u8] {
- slice::from_elem(0, 0u8)
+ fn to_bytes(&self) -> Vec<u8> {
+ 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] {
- slice::from_fn(8, |i| {
+fn to_bools(bitv: Storage) -> Vec<bool> {
+ Vec::from_fn(8, |i| {
let w = i / 64;
let b = i % 64;
let x = 1u64 & (bitv.storage[w] >> b);
})
}
-struct Storage { storage: ~[u64] }
+struct Storage { storage: Vec<u64> }
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]);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-type Connection = 'static |~[u8]|;
+type Connection = 'static |Vec<u8> |;
fn f() -> Option<Connection> {
let mock_connection: Connection = |_| {};
// except according to those terms.
struct trie_node {
- content: ~[~str],
- children: ~[trie_node],
+ content: Vec<~str> ,
+ children: Vec<trie_node> ,
}
-fn print_str_vector(vector: ~[~str]) {
+fn print_str_vector(vector: Vec<~str> ) {
for string in vector.iter() {
println!("{}", *string);
}
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());
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<Token> , @~str, @~str, @~str, @~str, @~str),
+ IncompleteSection(@Vec<~str> , bool, @~str, bool),
Partial(@~str, @~str, @~str),
}
// 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);
}
width: uint,
height: uint,
fill: char,
- lines: ~[~[char]],
+ lines: Vec<Vec<char> > ,
// This struct can be quite large so we'll disable copying: developers need
// to either pass these structs around via references or move them.
use std::task;
-type RingBuffer = ~[f64];
+type RingBuffer = Vec<f64> ;
type SamplesFn = proc(samples: &RingBuffer);
enum Msg
// except according to those terms.
struct HasNested {
- nest: ~[~[int]],
+ nest: Vec<Vec<int> > ,
}
impl HasNested {
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<int> = Decodable::decode(&mut decoder);
}
trait MyTrait<T> { }
pub struct MyContainer<'a, T> {
- foos: ~[&'a MyTrait<T>],
+ foos: Vec<&'a MyTrait<T>> ,
}
impl<'a, T> MyContainer<'a, T> {
// 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];
+fn swap(f: |Vec<int> | -> Vec<int> ) -> Vec<int> {
+ let x = vec!(1, 2, 3);
f(x)
}
let abc = [1, 2, 3];
let tf = [true, false];
let x = [(), ()];
- let y = ~[(), ()];
+ let y = vec!((), ());
let slice = x.slice(0,1);
let z = @x;
bar: ~32,
};
Thing1 {
- baz: ~[],
+ baz: Vec::new(),
bar: ~32,
};
let _t2_fixed = Thing2 {
bar: 32,
};
Thing2 {
- baz: ~[],
+ baz: Vec::new(),
bar: 32,
};
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn double<T:Clone>(a: T) -> ~[T] { return ~[a.clone()] + ~[a]; }
+fn double<T:Clone>(a: T) -> Vec<T> { return vec!(a.clone()) + vec!(a); }
-fn double_int(a: int) -> ~[int] { return ~[a] + ~[a]; }
+fn double_int(a: int) -> Vec<int> { return vec!(a) + vec!(a); }
pub fn main() {
let mut d = double(1);
// 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]); }
+fn f(_a: Vec<int> ) { }
+pub fn main() { f(vec!(1, 2, 3, 4, 5)); }
use std::task;
-fn producer(tx: &Sender<~[u8]>) {
+fn producer(tx: &Sender<Vec<u8>>) {
tx.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 (tx, rx) = channel::<~[u8]>();
+ let (tx, rx) = channel::<Vec<u8>>();
let _prod = task::spawn(proc() {
producer(&tx)
});
- let _data: ~[u8] = rx.recv();
+ let _data: Vec<u8> = rx.recv();
}
// This should typecheck even though the type of e is not fully
// resolved when we finish typechecking the ||.
-struct Refs { refs: ~[int], n: int }
+struct Refs { refs: Vec<int> , n: int }
pub fn main() {
- let mut e = Refs{refs: ~[], n: 0};
+ let mut e = Refs{refs: vec!(), n: 0};
let _f: || = || println!("{}", e.n);
- let x: &[int] = e.refs;
+ let x: &[int] = e.refs.as_slice();
assert_eq!(x.len(), 0);
}
// 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() { println!("{:?}", *i); y += *i; }
println!("{:?}", y);
fn take(x: int) -> int {x}
fn the_loop() {
- let mut list = ~[];
+ let mut list = Vec::new();
loop {
let x = 5;
if x > 3 {
println!("{}", 1);
println!("{}", 2.0);
println!("{:?}", Three);
- println!("{:?}", ~[4]);
+ println!("{:?}", vec!(4));
}
use std::repr;
pub fn main() {
- let act = repr::repr_to_str(&~[1, 2, 3]);
+ let act = repr::repr_to_str(&vec!(1, 2, 3));
assert_eq!(~"~[1, 2, 3]", act);
- let act = format!("{:?}/{:6?}", ~[1, 2, 3], ~"hi");
+ let act = format!("{:?}/{:6?}", vec!(1, 2, 3), ~"hi");
assert_eq!(act, ~"~[1, 2, 3]/~\"hi\" ");
}
// 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);
fn foo<T>(y: Option<T>) {
let mut x: int;
- let mut rs: ~[int] = ~[];
+ let mut rs: Vec<int> = Vec::new();
/* tests that x doesn't get put in the precondition for the
entire if expression */
// Tests that matching rvalues with drops does not crash.
pub fn main() {
- match ~[1, 2, 3] {
+ match vec!(1, 2, 3) {
x => {
assert_eq!(x.len(), 3);
assert_eq!(x[0], 1);
// begin failing.
mod m {
- use std::slice;
- pub fn f() -> ~[int] { slice::from_elem(1u, 0) }
+ pub fn f() -> Vec<int> { Vec::from_elem(1u, 0) }
}
pub fn main() { let _x = m::f(); }
// ignore-fast
trait vec_monad<A> {
- fn bind<B>(&self, f: |&A| -> ~[B]) -> ~[B];
+ fn bind<B>(&self, f: |&A| -> Vec<B> ) -> Vec<B> ;
}
-impl<A> vec_monad<A> for ~[A] {
- fn bind<B>(&self, f: |&A| -> ~[B]) -> ~[B] {
- let mut r = ~[];
+impl<A> vec_monad<A> for Vec<A> {
+ fn bind<B>(&self, f: |&A| -> Vec<B> ) -> Vec<B> {
+ let mut r = Vec::new();
for elt in self.iter() {
r.push_all_move(f(elt));
}
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!?"));
}
pub fn main() {
use rand::Rng;
- let fns = ~[
+ let fns = vec!(
calllink01,
calllink02,
calllink08,
calllink10
- ];
+ );
let mut rng = rand::task_rng();
+
for f in fns.iter() {
let f = *f;
let sz = rng.gen::<u32>() % 256u32 + 256u32;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn test(foo: ~~[int]) { assert!((foo[0] == 10)); }
+fn test(foo: ~Vec<int> ) { assert!((foo[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));
}
#[feature(managed_boxes)];
-fn test(foo: @~[int]) { assert!((foo[0] == 10)); }
+fn test(foo: @Vec<int> ) { assert!((foo[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));
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn grow(v: &mut ~[int]) {
+fn grow(v: &mut Vec<int>) {
v.push(1);
}
pub fn main() {
- let mut v: ~[int] = ~[];
+ let mut v: Vec<int> = Vec::new();
grow(&mut v);
grow(&mut v);
grow(&mut v);
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});
}
// except according to those terms.
#[deriving(Clone)]
-struct myvec<X>(~[X]);
+struct myvec<X>(Vec<X> );
-fn myvec_deref<X:Clone>(mv: myvec<X>) -> ~[X] {
+fn myvec_deref<X:Clone>(mv: myvec<X>) -> Vec<X> {
let myvec(v) = mv;
return v.clone();
}
}
pub fn main() {
- let mv = myvec(~[1, 2, 3]);
+ let mv = myvec(vec!(1, 2, 3));
assert_eq!(myvec_deref(mv.clone())[1], 2);
assert_eq!(myvec_elt(mv.clone()), 1);
let myvec(v) = mv;
check_type!(~18: ~int);
check_type!(@19: @int);
check_type!(~"foo": ~str);
- check_type!(~[20, 22]: ~[int]);
+ check_type!(vec!(20, 22): Vec<int> );
let mint: uint = unsafe { cast::transmute(main) };
check_type!(main: fn(), |pthing| {
assert!(mint == unsafe { cast::transmute(*pthing) })
check_type!(~int);
check_type!(@int);
check_type!(~str);
- check_type!(~[int]);
+ check_type!(Vec<int> );
check_type!(extern fn());
}
}
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());
}
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());
use std::ops::Index;
struct AssociationList<K,V> {
- pairs: ~[AssociationPair<K,V>]
-}
+ pairs: Vec<AssociationPair<K,V>> }
#[deriving(Clone)]
struct AssociationPair<K,V> {
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);
(*(*p).borrow_mut()).y += 3;
assert_eq!(*(*p).borrow(), Point {x: 3, y: 5});
- let v = Rc::new(RefCell::new(~[1, 2, 3]));
+ let v = Rc::new(RefCell::new(vec!(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));
assert_eq!(mem::size_of::<S<u64, u16>>(), 11);
- assert_eq!(mem::size_of::<S<~str, ~[int]>>(),
- 1 + mem::size_of::<~str>() + mem::size_of::<~[int]>());
+ assert_eq!(mem::size_of::<S<~str, Vec<int> >>(),
+ 1 + mem::size_of::<~str>() + mem::size_of::<Vec<int> >());
}
// Check that functions can modify local state.
-fn sums_to(v: ~[int], sum: int) -> bool {
+fn sums_to(v: Vec<int> , sum: int) -> bool {
let mut i = 0u;
let mut sum0 = 0;
while i < v.len() {
return sum0 == sum;
}
-fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
+fn sums_to_using_uniq(v: Vec<int> , sum: int) -> bool {
let mut i = 0u;
let mut sum0 = ~0;
while i < v.len() {
return *sum0 == sum;
}
-fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
+fn sums_to_using_rec(v: Vec<int> , sum: int) -> bool {
let mut i = 0u;
let mut sum0 = F {f: 0};
while i < v.len() {
struct F<T> { f: T }
-fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool {
+fn sums_to_using_uniq_rec(v: Vec<int> , sum: int) -> bool {
let mut i = 0u;
let mut sum0 = F {f: ~0};
while i < v.len() {
fn call_sum(x: &[int]) -> int { x.sum_() }
pub fn main() {
- let x = ~[1, 2, 3];
+ let x = vec!(1, 2, 3);
let y = call_sum(x);
println!("y=={}", y);
assert_eq!(y, 6);
- let x = ~[1, 2, 3];
+ let x = vec!(1, 2, 3);
let y = x.sum_();
println!("y=={}", y);
assert_eq!(y, 6);
- let x = ~[1, 2, 3];
+ let x = vec!(1, 2, 3);
let y = x.sum_();
println!("y=={}", y);
assert_eq!(y, 6);
use std::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Disr, Opaque};
struct MyVisitor {
- types: ~[~str],
+ types: Vec<~str> ,
}
impl TyVisitor for MyVisitor {
}
pub fn main() {
- let mut v = MyVisitor {types: ~[]};
+ let mut v = MyVisitor {types: Vec::new()};
visit_ty::<bool>(&mut v);
visit_ty::<int>(&mut v);
visit_ty::<i8>(&mut v);
visit_ty::<i16>(&mut v);
- visit_ty::<~[int]>(&mut v);
+ visit_ty::<Vec<int> >(&mut v);
for s in v.types.iter() {
println!("type: {}", (*s).clone());
}
- assert_eq!(v.types.clone(), ~[~"bool", ~"int", ~"i8", ~"i16", ~"[", ~"int", ~"]"]);
+ assert_eq!(v.types.clone(), vec!(~"bool", ~"int", ~"i8", ~"i16", ~"[", ~"int", ~"]"));
}
}
pub fn main() {
- let p = ~[1,2,3,4,5];
+ let p = vec!(1,2,3,4,5);
let r = foo(p);
assert_eq!(r, 1);
- let p = ~[5,4,3,2,1];
+ let p = vec!(5,4,3,2,1);
let r = foo(p);
assert_eq!(r, 5);
}
struct B {
v1: int,
v2: [int, ..3],
- v3: ~[int],
+ v3: Vec<int> ,
v4: C,
v5: ~C,
v6: Option<C>
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 })}};
}
pub fn main() {
- let v = ~[1,2,3];
+ let v = vec!(1,2,3);
both(v);
}
fn view<'r, T>(x: &'r [T]) -> &'r [T] {x}
pub fn main() {
- let v = ~[1, 2, 3];
+ let v = vec!(1, 2, 3);
let x = view(v);
let y = view(x);
assert!((v[0] == x[0]) && (v[0] == y[0]));
struct TypeContext<'tcx, 'ast> {
ty_arena: &'tcx Arena,
- types: ~[Type<'tcx>],
+ types: Vec<Type<'tcx>> ,
type_table: HashMap<NodeId, Type<'tcx>>,
ast_arena: &'ast Arena,
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,
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)));
}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-fn foo(c: ~[int]) {
+fn foo(c: Vec<int> ) {
let a: int = 5;
- let mut b: ~[int] = ~[];
+ let mut b: Vec<int> = Vec::new();
match none::<int> {
enum t<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()); }
#[deriving(Clone)]
struct Path_ {
global: bool,
- idents: ~[~str],
- types: ~[@ty],
+ idents: Vec<~str> ,
+ types: vec!(@ty),
}
type path = Spanned<Path_>;
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 };
println!("{:?}", x.path.clone());
enum clam<T> { a(T, int), b, }
-fn uhoh<T>(v: ~[clam<T>]) {
+fn uhoh<T>(v: Vec<clam<T>> ) {
match v[1] {
a::<T>(ref _t, ref u) => {
println!("incorrect");
}
pub fn main() {
- let v: ~[clam<int>] = ~[b::<int>, b::<int>, a::<int>(42, 17)];
+ let v: Vec<clam<int>> = vec!(b::<int>, b::<int>, a::<int>(42, 17));
uhoh::<int>(v);
}
trait vec_utils<T> {
fn length_(&self, ) -> uint;
fn iter_(&self, f: |&T|);
- fn map_<U>(&self, f: |&T| -> U) -> ~[U];
+ fn map_<U>(&self, f: |&T| -> U) -> Vec<U> ;
}
-impl<T> vec_utils<T> for ~[T] {
+impl<T> vec_utils<T> for Vec<T> {
fn length_(&self) -> uint { self.len() }
fn iter_(&self, f: |&T|) { for x in self.iter() { f(x); } }
- fn map_<U>(&self, f: |&T| -> U) -> ~[U] {
- let mut r = ~[];
+ fn map_<U>(&self, f: |&T| -> U) -> Vec<U> {
+ let mut r = Vec::new();
for elt in self.iter() {
r.push(f(elt));
}
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_::<uint>(|a| *a as uint + 4u )[0], 7u);
+ assert_eq!((vec!(1)).length_().str(), ~"1");
+ assert_eq!((vec!(3, 4)).map_(|a| *a + 4 )[0], 7);
+ assert_eq!((vec!(3, 4)).map_::<uint>(|a| *a as uint + 4u )[0], 7u);
let mut x = 0u;
10u.multi(|_n| x += 2u );
assert_eq!(x, 20u);
use std::mem::swap;
pub fn main() {
- let mut a: ~[int] = ~[0, 1, 2, 3, 4, 5, 6];
+ let mut a: Vec<int> = vec!(0, 1, 2, 3, 4, 5, 6);
a.swap(2, 4);
assert_eq!(a[2], 4);
assert_eq!(a[4], 2);
fn test_vec() {
let (tx, rx) = channel();
- let v0: ~[int] = ~[0, 1, 2];
+ let v0: Vec<int> = vec!(0, 1, 2);
tx.send(v0);
let v1 = rx.recv();
assert_eq!(v1[0], 0);
let mut i: int = 0;
// Create and spawn tasks...
- let mut results = ~[];
+ let mut results = Vec::new();
while i < number_of_tasks {
let tx = tx.clone();
let mut builder = task::task();
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:Share+Send,
+ let arc = Arc::new(vec!(~catte as ~Pet:Share+Send,
~dogge1 as ~Pet:Share+Send,
~fishe as ~Pet:Share+Send,
- ~dogge2 as ~Pet:Share+Send]);
+ ~dogge2 as ~Pet:Share+Send));
let (tx1, rx1) = channel();
let arc1 = arc.clone();
task::spawn(proc() { check_legs(arc1); tx1.send(()); });
rx3.recv();
}
-fn check_legs(arc: Arc<~[~Pet:Share+Send]>) {
+fn check_legs(arc: Arc<Vec<~Pet:Share+Send>>) {
let mut legs = 0;
for pet in arc.get().iter() {
legs += pet.num_legs();
}
assert!(legs == 12);
}
+<<<<<<< HEAD
fn check_names(arc: Arc<~[~Pet:Share+Send]>) {
+=======
+fn check_names(arc: Arc<Vec<~Pet:Freeze+Send> >) {
+>>>>>>> test: Automatically remove all `~[T]` from tests.
for pet in arc.get().iter() {
pet.name(|name| {
assert!(name[0] == 'a' as u8 && name[1] == 'l' as u8);
})
}
}
+<<<<<<< HEAD
fn check_pedigree(arc: Arc<~[~Pet:Share+Send]>) {
+=======
+fn check_pedigree(arc: Arc<Vec<~Pet:Freeze+Send> >) {
+>>>>>>> test: Automatically remove all `~[T]` from tests.
for pet in arc.get().iter() {
assert!(pet.of_good_pedigree());
}
}
trait map<T> {
- fn map<U>(&self, f: |&T| -> U) -> ~[U];
+ fn map<U>(&self, f: |&T| -> U) -> Vec<U> ;
}
-impl<T> map<T> for ~[T] {
- fn map<U>(&self, f: |&T| -> U) -> ~[U] {
- let mut r = ~[];
+impl<T> map<T> for Vec<T> {
+ fn map<U>(&self, f: |&T| -> U) -> Vec<U> {
+ let mut r = Vec::new();
// FIXME: #7355 generates bad code with VecIterator
for i in range(0u, self.len()) {
r.push(f(&self[i]));
}
}
-fn foo<U, T: map<U>>(x: T) -> ~[~str] {
+fn foo<U, T: map<U>>(x: T) -> Vec<~str> {
x.map(|_e| ~"hi" )
}
-fn bar<U:to_str,T:map<U>>(x: T) -> ~[~str] {
+fn bar<U:to_str,T:map<U>>(x: T) -> Vec<~str> {
x.map(|_e| _e.to_string() )
}
pub fn main() {
- assert_eq!(foo(~[1]), ~[~"hi"]);
- assert_eq!(bar::<int, ~[int]>(~[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::<int, Vec<int> >(vec!(4, 5)), vec!(~"4", ~"5"));
+ assert_eq!(bar::<~str, Vec<~str> >(vec!(~"x", ~"y")), vec!(~"x", ~"y"));
+ assert_eq!(bar::<(), vec!(())>(vec!(())), vec!(~"()"));
}
fn to_string(&self) -> ~str { self.to_str() }
}
-impl<T:to_str> to_str for ~[T] {
+impl<T:to_str> to_str for Vec<T> {
fn to_string(&self) -> ~str {
format!("[{}]", self.iter().map(|e| e.to_string()).to_owned_vec().connect(", "))
}
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<T:to_str>(x: T) -> ~str {
x.to_string() + "!"
}
- assert!(indirect(~[10, 20]) == ~"[10, 20]!");
+ assert!(indirect(vec!(10, 20)) == ~"[10, 20]!");
fn indirect2<T:to_str>(x: T) -> ~str {
indirect(x)
}
- assert!(indirect2(~[1]) == ~"[1]!");
+ assert!(indirect2(vec!(1)) == ~"[1]!");
}
pub fn main() {
unsafe {
assert_eq!((*get_tydesc::<int>()).name, "int");
- assert_eq!((*get_tydesc::<~[int]>()).name, "~[int]");
+ assert_eq!((*get_tydesc::<Vec<int> >()).name, "~[int]");
assert_eq!((*get_tydesc::<Foo<uint>>()).name, "Foo<uint>");
}
}
while lo_ < hi { it(lo_); lo_ += 1u; }
}
-fn create_index<T>(_index: ~[S<T>], _hash_fn: extern fn(T) -> uint) {
+fn create_index<T>(_index: Vec<S<T>> , _hash_fn: extern fn(T) -> uint) {
range_(0u, 256u, |_i| {
- let _bucket: ~[T] = ~[];
+ let _bucket: Vec<T> = Vec::new();
})
}
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));
}
// except according to those terms.
pub fn main() {
- let i = ~~[100];
+ let i = ~vec!(100);
assert_eq!(i[0], 100);
}
}
fn vec() {
- ~[0];
+ vec!(0);
}
// except according to those terms.
pub fn main() {
- let _x = ~~[0,0,0,0,0];
+ let _x = ~vec!(0,0,0,0,0);
}
// except according to those terms.
pub fn main() {
- let mut a = ~[~10];
+ let mut a = vec!(~10);
let b = a.clone();
assert_eq!(*a[0], 10);
// except according to those terms.
pub fn main() {
- assert!((~[~100])[0] == ~100);
+ assert!((vec!(~100))[0] == ~100);
}
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});
}
pub fn main() {
- let mut v = ~[1];
+ let mut v = vec!(1);
v.push(2);
v.push(3);
v.push(4);
#[allow(dead_assignment)];
pub fn main() {
- let a = ~[1, 2, 3, 4, 5];
- let mut b = ~[a.clone(), a.clone()];
+ let a = vec!(1, 2, 3, 4, 5);
+ let mut b = vec!(a.clone(), a.clone());
b = b + b; // FIXME(#3387)---can't write b += b
}
pub fn main() {
- let mut later: ~[int];
- if true { later = ~[1]; } else { later = ~[2]; }
+ let mut later: Vec<int> ;
+ if true { later = vec!(1); } else { later = vec!(2); }
println!("{}", later[0]);
}
// 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); }
fn test_heap_to_heap() {
// a spills onto the heap
- let mut a = ~[0, 1, 2, 3, 4];
+ let mut a = vec!(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);
fn test_stack_to_heap() {
// a is entirely on the stack
- let mut a = ~[0, 1, 2];
+ let mut a = vec!(0, 1, 2);
// a spills to the heap
a = a + a; // FIXME(#3387)---can't write a += a
assert_eq!(a.len(), 6u);
fn test_loop() {
// Make sure we properly handle repeated self-appends.
- let mut a: ~[int] = ~[0];
+ let mut a: Vec<int> = vec!(0);
let mut i = 20;
let mut expected_len = 1u;
while i > 0 {
// 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);
// 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]");
// Issue #2482.
pub fn main() {
- let v1: ~[int] = ~[10, 20, 30,];
- let v2: ~[int] = ~[10, 20, 30];
+ let v1: Vec<int> = vec!(10, 20, 30);
+ let v2: Vec<int> = vec!(10, 20, 30);
assert_eq!(v1[2], v2[2]);
- let v3: ~[int] = ~[10,];
- let v4: ~[int] = ~[10];
+ let v3: Vec<int> = vec!(10);
+ let v4: Vec<int> = vec!(10);
assert_eq!(v3[0], v4[0]);
}
pub fn main() {
- let v: ~[int] = ~[10, 20];
+ let v: Vec<int> = vec!(10, 20);
assert_eq!(v[0], 10);
assert_eq!(v[1], 20);
let mut x: int = 0;
#[feature(managed_boxes)];
-pub fn main() { let _quux: @~[uint] = @~[]; }
+pub fn main() { let _quux: @Vec<uint> = @Vec::new(); }
println!("{}", 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<int> =
+ vec!(1, 2, 3, 4, 5); // we check that it is freed by break
println!("breaking");
break;