Remove deprecated functionality

This removes a large array of deprecated functionality, regardless of how
recently it was deprecated. The purpose of this commit is to clean out the
standard libraries and compiler for the upcoming alpha release.

Some notable compiler changes were to enable warnings for all now-deprecated
command line arguments (previously the deprecated versions were silently
accepted) as well as removing deriving(Zero) entirely (the trait was removed).

The distribution no longer contains the libtime or libregex_macros crates. Both
of these have been deprecated for some time and are available externally.
This commit is contained in:
Alex Crichton 2015-01-01 23:53:35 -08:00
parent 470118f3e9
commit 7d8d06f86b
239 changed files with 1104 additions and 7460 deletions

View file

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
use std::sync::mpsc::{Receiver, channel};
pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
let (tx, rx) = channel();
task::spawn(move|| {
Thread::spawn(move|| {
tx.send(x.clone());
});
}).detach();
rx
}

View file

@ -12,7 +12,6 @@
#![crate_type = "lib"]
use std::int;
use std::str::from_str;
pub trait read {
fn readMaybe(s: String) -> Option<Self>;
@ -20,7 +19,7 @@ pub trait read {
impl read for int {
fn readMaybe(s: String) -> Option<int> {
from_str::<int>(s.as_slice())
s.parse()
}
}

View file

@ -13,7 +13,6 @@
use std::collections::{BTreeMap, HashMap, HashSet};
use std::os;
use std::rand::{Rng, IsaacRng, SeedableRng};
use std::str::from_str;
use std::time::Duration;
use std::uint;
@ -107,7 +106,7 @@ fn main() {
let args = args.as_slice();
let n_keys = {
if args.len() == 2 {
from_str::<uint>(args[1].as_slice()).unwrap()
args[1].parse::<uint>().unwrap()
} else {
1000000
}

View file

@ -20,7 +20,6 @@ use std::collections::BitvSet;
use std::collections::HashSet;
use std::hash::Hash;
use std::os;
use std::str::from_str;
use std::time::Duration;
use std::uint;
@ -181,7 +180,7 @@ fn main() {
let args = args.as_slice();
let num_keys = {
if args.len() == 2 {
from_str::<uint>(args[1].as_slice()).unwrap()
args[1].parse::<uint>().unwrap()
} else {
100 // woefully inadequate for any real measurement
}

View file

@ -15,6 +15,7 @@
#![feature(unboxed_closures)]
use std::io::File;
use std::iter::repeat;
use std::mem::swap;
use std::os;
use std::rand::Rng;
@ -61,7 +62,7 @@ fn maybe_run_test<F>(argv: &[String], name: String, test: F) where F: FnOnce() {
}
fn shift_push() {
let mut v1 = Vec::from_elem(30000, 1i);
let mut v1 = repeat(1i).take(30000).collect::<Vec<_>>();
let mut v2 = Vec::new();
while v1.len() > 0 {
@ -88,7 +89,7 @@ fn vec_plus() {
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 = repeat(i).take(r.gen_range(0u, i + 1)).collect::<Vec<_>>();
if r.gen() {
v.extend(rv.into_iter());
} else {
@ -106,7 +107,7 @@ fn vec_append() {
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 = repeat(i).take(r.gen_range(0u, i + 1)).collect::<Vec<_>>();
if r.gen() {
let mut t = v.clone();
t.push_all(rv.as_slice());
@ -126,7 +127,7 @@ fn vec_push_all() {
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 = repeat(i).take(r.gen_range(0u, i + 1)).collect::<Vec<_>>();
if r.gen() {
v.push_all(rv.as_slice());
}
@ -141,8 +142,8 @@ fn is_utf8_ascii() {
let mut v : Vec<u8> = Vec::new();
for _ in range(0u, 20000) {
v.push('b' as u8);
if !str::is_utf8(v.as_slice()) {
panic!("is_utf8 panicked");
if str::from_utf8(v.as_slice()).is_err() {
panic!("from_utf8 panicked");
}
}
}
@ -152,8 +153,8 @@ fn is_utf8_multibyte() {
let mut v : Vec<u8> = Vec::new();
for _ in range(0u, 5000) {
v.push_all(s.as_bytes());
if !str::is_utf8(v.as_slice()) {
panic!("is_utf8 panicked");
if str::from_utf8(v.as_slice()).is_err() {
panic!("from_utf8 panicked");
}
}
}

View file

@ -9,7 +9,6 @@
// except according to those terms.
use std::os;
use std::str::from_str;
use std::uint;
fn main() {
@ -22,7 +21,7 @@ fn main() {
args.into_iter().collect()
};
let n = from_str::<uint>(args[1].as_slice()).unwrap();
let n = args[1].parse().unwrap();
for i in range(0u, n) {
let x = i.to_string();

View file

@ -20,7 +20,6 @@
use std::sync::mpsc::{channel, Sender, Receiver};
use std::os;
use std::str::from_str;
use std::thread::Thread;
use std::time::Duration;
use std::uint;
@ -55,8 +54,8 @@ fn run(args: &[String]) {
let (to_parent, from_child) = channel();
let (to_child, from_parent) = channel();
let size = from_str::<uint>(args[1].as_slice()).unwrap();
let workers = from_str::<uint>(args[2].as_slice()).unwrap();
let size = args[1].parse::<uint>().unwrap();
let workers = args[2].parse::<uint>().unwrap();
let num_bytes = 100;
let mut result = None;
let mut p = Some((to_child, to_parent, from_parent));

View file

@ -19,7 +19,6 @@
// ignore-lexer-test FIXME #15679
use std::os;
use std::str::from_str;
use std::sync::{Arc, Future, Mutex, Condvar};
use std::time::Duration;
use std::uint;
@ -74,8 +73,8 @@ fn main() {
args.clone().into_iter().collect()
};
let num_tasks = from_str::<uint>(args[1].as_slice()).unwrap();
let msg_per_task = from_str::<uint>(args[2].as_slice()).unwrap();
let num_tasks = args[1].parse::<uint>().unwrap();
let msg_per_task = args[2].parse::<uint>().unwrap();
let (mut num_chan, num_port) = init();

View file

@ -19,7 +19,6 @@
use std::sync::mpsc::channel;
use std::os;
use std::str::from_str;
use std::thread::Thread;
use std::uint;
@ -66,13 +65,13 @@ fn main() {
let args = os::args();
let args = args.as_slice();
let n = if args.len() == 3 {
from_str::<uint>(args[1].as_slice()).unwrap()
args[1].parse::<uint>().unwrap()
} else {
10000
};
let m = if args.len() == 3 {
from_str::<uint>(args[2].as_slice()).unwrap()
args[2].parse::<uint>().unwrap()
} else {
4
};

View file

@ -9,7 +9,6 @@
// except according to those terms.
use std::os;
use std::str::from_str;
fn ack(m: int, n: int) -> int {
if m == 0 {
@ -32,6 +31,6 @@ fn main() {
} else {
args.into_iter().collect()
};
let n = from_str::<int>(args[1].as_slice()).unwrap();
let n = args[1].parse().unwrap();
println!("Ack(3,{}): {}\n", n, ack(3, n));
}

View file

@ -43,7 +43,6 @@
use self::Color::{Red, Yellow, Blue};
use std::sync::mpsc::{channel, Sender, Receiver};
use std::fmt;
use std::str::from_str;
use std::thread::Thread;
fn print_complements() {
@ -235,8 +234,8 @@ fn main() {
} else {
std::os::args().as_slice()
.get(1)
.and_then(|arg| from_str(arg.as_slice()))
.unwrap_or(600)
.and_then(|arg| arg.parse())
.unwrap_or(600u)
};
print_complements();

View file

@ -42,9 +42,9 @@
use std::cmp::min;
use std::io::{stdout, IoResult};
use std::iter::repeat;
use std::os;
use std::slice::bytes::copy_memory;
use std::str::from_str;
const LINE_LEN: uint = 60;
const LOOKUP_SIZE: uint = 4 * 1024;
@ -124,7 +124,7 @@ impl<'a, W: Writer> RepeatFasta<'a, W> {
fn make(&mut self, n: uint) -> IoResult<()> {
let alu_len = self.alu.len();
let mut buf = Vec::from_elem(alu_len + LINE_LEN, 0u8);
let mut buf = repeat(0u8).take(alu_len + LINE_LEN).collect::<Vec<_>>();
let alu: &[u8] = self.alu.as_bytes();
copy_memory(buf.as_mut_slice(), alu);
@ -214,7 +214,7 @@ fn main() {
let args = os::args();
let args = args.as_slice();
let n = if args.len() > 1 {
from_str::<uint>(args[1].as_slice()).unwrap()
args[1].parse::<uint>().unwrap()
} else {
5
};

View file

@ -45,7 +45,6 @@ use std::io::{BufferedWriter, File};
use std::io;
use std::num::Float;
use std::os;
use std::str::from_str;
const LINE_LENGTH: uint = 60;
const IM: u32 = 139968;
@ -113,7 +112,7 @@ fn run<W: Writer>(writer: &mut W) -> std::io::IoResult<()> {
} else if args.len() <= 1u {
1000
} else {
from_str(args[1].as_slice()).unwrap()
args[1].parse().unwrap()
};
let rng = &mut MyRandom::new();

View file

@ -9,7 +9,6 @@
// except according to those terms.
use std::os;
use std::str::from_str;
fn fib(n: int) -> int {
if n < 2 {
@ -28,6 +27,6 @@ fn main() {
} else {
args.into_iter().collect()
};
let n = from_str::<int>(args[1].as_slice()).unwrap();
let n = args[1].parse().unwrap();
println!("{}\n", fib(n));
}

View file

@ -15,17 +15,14 @@
#![feature(slicing_syntax)]
extern crate collections;
use std::ascii::{AsciiExt, OwnedAsciiExt};
use std::cmp::Ordering::{self, Less, Greater, Equal};
use std::collections::HashMap;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::mem::replace;
use std::num::Float;
use std::option;
use std::os;
use std::string::IntoString;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::thread::Thread;
fn f64_cmp(x: f64, y: f64) -> Ordering {
@ -87,7 +84,7 @@ fn find(mm: &HashMap<Vec<u8> , uint>, key: String) -> uint {
// given a map, increment the counter for a key
fn update_freq(mm: &mut HashMap<Vec<u8> , uint>, key: &[u8]) {
let key = key.to_vec();
let newval = match mm.pop(&key) {
let newval = match mm.remove(&key) {
Some(v) => v + 1,
None => 1
};
@ -142,7 +139,7 @@ fn make_sequence_processor(sz: uint,
_ => { "".to_string() }
};
to_parent.send(buffer);
to_parent.send(buffer).unwrap();
}
// given a FASTA file on stdin, process sequence THREE
@ -159,7 +156,9 @@ fn main() {
// initialize each sequence sorter
let sizes = vec!(1u,2,3,4,6,12,18);
let mut streams = Vec::from_fn(sizes.len(), |_| Some(channel::<String>()));
let mut streams = range(0, sizes.len()).map(|_| {
Some(channel::<String>())
}).collect::<Vec<_>>();
let mut from_child = Vec::new();
let to_child = sizes.iter().zip(streams.iter_mut()).map(|(sz, stream_ref)| {
let sz = *sz;
@ -206,7 +205,7 @@ fn main() {
for (ii, _sz) in sizes.iter().enumerate() {
let lb = line_bytes.to_vec();
to_child[ii].send(lb);
to_child[ii].send(lb).unwrap();
}
}
@ -217,7 +216,7 @@ fn main() {
// finish...
for (ii, _sz) in sizes.iter().enumerate() {
to_child[ii].send(Vec::new());
to_child[ii].send(Vec::new()).unwrap();
}
// now fetch and print result messages

View file

@ -43,8 +43,10 @@
#![feature(associated_types, slicing_syntax)]
use std::ascii::OwnedAsciiExt;
use std::iter::repeat;
use std::slice;
use std::sync::{Arc, Future};
use std::sync::Arc;
use std::thread::Thread;
static TABLE: [u8;4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ];
static TABLE_SIZE: uint = 2 << 16;
@ -136,7 +138,7 @@ struct Items<'a> {
impl Table {
fn new() -> Table {
Table {
items: Vec::from_fn(TABLE_SIZE, |_| None),
items: range(0, TABLE_SIZE).map(|_| None).collect()
}
}
@ -300,19 +302,19 @@ fn main() {
};
let input = Arc::new(input);
let nb_freqs: Vec<(uint, Future<Table>)> = range(1u, 3).map(|i| {
let nb_freqs: Vec<_> = range(1u, 3).map(|i| {
let input = input.clone();
(i, Future::spawn(move|| generate_frequencies(input.as_slice(), i)))
(i, Thread::spawn(move|| generate_frequencies(input.as_slice(), i)))
}).collect();
let occ_freqs: Vec<Future<Table>> = OCCURRENCES.iter().map(|&occ| {
let occ_freqs: Vec<_> = OCCURRENCES.iter().map(|&occ| {
let input = input.clone();
Future::spawn(move|| generate_frequencies(input.as_slice(), occ.len()))
Thread::spawn(move|| generate_frequencies(input.as_slice(), occ.len()))
}).collect();
for (i, freq) in nb_freqs.into_iter() {
print_frequencies(&freq.unwrap(), i);
print_frequencies(&freq.join().ok().unwrap(), i);
}
for (&occ, freq) in OCCURRENCES.iter().zip(occ_freqs.into_iter()) {
print_occurrences(&mut freq.unwrap(), occ);
print_occurrences(&mut freq.join().ok().unwrap(), occ);
}
}

View file

@ -47,8 +47,8 @@
use std::io;
use std::os;
use std::simd::f64x2;
use std::str::from_str;
use std::sync::{Arc, Future};
use std::sync::Arc;
use std::thread::Thread;
const ITER: int = 50;
const LIMIT: f64 = 2.0;
@ -82,8 +82,8 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
let mut precalc_r = Vec::with_capacity(w);
let mut precalc_i = Vec::with_capacity(h);
let precalc_futures = Vec::from_fn(WORKERS, |i| {
Future::spawn(move|| {
let precalc_futures = range(0, WORKERS).map(|i| {
Thread::spawn(move|| {
let mut rs = Vec::with_capacity(w / WORKERS);
let mut is = Vec::with_capacity(w / WORKERS);
@ -106,10 +106,10 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
(rs, is)
})
});
}).collect::<Vec<_>>();
for res in precalc_futures.into_iter() {
let (rs, is) = res.unwrap();
let (rs, is) = res.join().ok().unwrap();
precalc_r.extend(rs.into_iter());
precalc_i.extend(is.into_iter());
}
@ -120,11 +120,11 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
let arc_init_r = Arc::new(precalc_r);
let arc_init_i = Arc::new(precalc_i);
let data = Vec::from_fn(WORKERS, |i| {
let data = range(0, WORKERS).map(|i| {
let vec_init_r = arc_init_r.clone();
let vec_init_i = arc_init_i.clone();
Future::spawn(move|| {
Thread::spawn(move|| {
let mut res: Vec<u8> = Vec::with_capacity((chunk_size * w) / 8);
let init_r_slice = vec_init_r.as_slice();
@ -141,11 +141,11 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
res
})
});
}).collect::<Vec<_>>();
try!(writeln!(&mut out as &mut Writer, "P4\n{} {}", w, h));
for res in data.into_iter() {
try!(out.write(res.unwrap().as_slice()));
try!(out.write(res.join().ok().unwrap().as_slice()));
}
out.flush()
}
@ -206,7 +206,7 @@ fn main() {
which interferes with the test runner.");
mandelbrot(1000, io::util::NullWriter)
} else {
mandelbrot(from_str(args[1].as_slice()).unwrap(), io::stdout())
mandelbrot(args[1].parse().unwrap(), io::stdout())
};
res.unwrap();
}

View file

@ -42,8 +42,9 @@
#![feature(associated_types)]
use std::sync::mpsc::channel;
use std::iter::repeat;
use std::sync::Arc;
use std::sync::mpsc::channel;
use std::thread::Thread;
//
@ -220,7 +221,7 @@ fn get_id(m: u64) -> u8 {
// Converts a list of mask to a Vec<u8>.
fn to_vec(raw_sol: &List<u64>) -> Vec<u8> {
let mut sol = Vec::from_elem(50, '.' as u8);
let mut sol = repeat('.' as u8).take(50).collect::<Vec<_>>();
for &m in raw_sol.iter() {
let id = '0' as u8 + get_id(m);
for i in range(0u, 50) {

View file

@ -39,7 +39,6 @@
// OF THE POSSIBILITY OF SUCH DAMAGE.
use std::num::Float;
use std::str::from_str;
const PI: f64 = 3.141592653589793;
const SOLAR_MASS: f64 = 4.0 * PI * PI;
@ -176,7 +175,7 @@ fn main() {
5000000
} else {
std::os::args().as_slice().get(1)
.and_then(|arg| from_str(arg.as_slice()))
.and_then(|arg| arg.parse())
.unwrap_or(1000)
};
let mut bodies = BODIES;

View file

@ -23,7 +23,6 @@ extern crate getopts;
use std::sync::mpsc::{channel, Sender};
use std::os;
use std::result::Result::{Ok, Err};
use std::str::from_str;
use std::thread::Thread;
use std::time::Duration;
@ -103,7 +102,7 @@ fn main() {
if opts.stress {
stress(2);
} else {
let max = from_str::<uint>(args[1].as_slice()).unwrap() as int;
let max = args[1].parse::<int>().unwrap();
let num_trials = 10;

View file

@ -44,12 +44,15 @@
#![feature(macro_rules, phase, slicing_syntax)]
extern crate regex;
#[phase(plugin)]extern crate regex_macros;
use std::io;
use regex::{NoExpand, Regex};
use std::sync::{Arc, Future};
macro_rules! regex {
($e:expr) => (Regex::new($e).unwrap())
}
fn count_matches(seq: &str, variant: &Regex) -> int {
let mut n = 0;
for _ in variant.find_iter(seq) {

View file

@ -46,7 +46,6 @@ extern crate libc;
use std::io::stdio::{stdin_raw, stdout_raw};
use std::io::{IoResult, EndOfFile};
use std::num::{div_rem};
use std::ptr::{copy_memory, Unique};
use std::thread::Thread;
@ -189,7 +188,8 @@ fn reverse_complement(seq: &mut [u8], tables: &Tables) {
i += LINE_LEN + 1;
}
let (div, rem) = div_rem(len, 4);
let div = len / 4;
let rem = len % 4;
unsafe {
let mut left = seq.as_mut_ptr() as *mut u16;
// This is slow if len % 2 != 0 but still faster than bytewise operations.

View file

@ -43,14 +43,13 @@
#![allow(non_snake_case)]
#![feature(unboxed_closures)]
use std::iter::AdditiveIterator;
use std::iter::{repeat, AdditiveIterator};
use std::thread::Thread;
use std::mem;
use std::num::Float;
use std::os;
use std::raw::Repr;
use std::simd::f64x2;
use std::str::from_str;
fn main() {
let args = os::args();
@ -59,16 +58,16 @@ fn main() {
} else if args.len() < 2 {
2000
} else {
from_str(args[1].as_slice()).unwrap()
args[1].parse().unwrap()
});
println!("{:.9}", answer);
}
fn spectralnorm(n: uint) -> f64 {
assert!(n % 2 == 0, "only even lengths are accepted");
let mut u = Vec::from_elem(n, 1.0);
let mut v = Vec::from_elem(n, 1.0);
let mut tmp = Vec::from_elem(n, 1.0);
let mut u = repeat(1.0).take(n).collect::<Vec<_>>();
let mut v = u.clone();
let mut tmp = v.clone();
for _ in range(0u, 10) {
mult_AtAv(u.as_slice(), v.as_mut_slice(), tmp.as_mut_slice());
mult_AtAv(v.as_slice(), u.as_mut_slice(), tmp.as_mut_slice());

View file

@ -39,7 +39,6 @@
// OF THE POSSIBILITY OF SUCH DAMAGE.
use std::sync::mpsc::{channel, Sender, Receiver};
use std::str::from_str;
use std::thread::Thread;
fn start(n_tasks: int, token: int) {
@ -69,10 +68,10 @@ fn main() {
let token = if std::os::getenv("RUST_BENCH").is_some() {
2000000
} else {
args.get(1).and_then(|arg| from_str(arg.as_slice())).unwrap_or(1000)
args.get(1).and_then(|arg| arg.parse()).unwrap_or(1000)
};
let n_tasks = args.get(2)
.and_then(|arg| from_str(arg.as_slice()))
.and_then(|arg| arg.parse())
.unwrap_or(503);
start(n_tasks, token);

View file

@ -12,7 +12,6 @@
use std::collections::VecMap;
use std::os;
use std::str::from_str;
use std::time::Duration;
use std::uint;
@ -37,8 +36,8 @@ fn main() {
} else {
args.into_iter().collect()
};
let max = from_str::<uint>(args[1].as_slice()).unwrap();
let rep = from_str::<uint>(args[2].as_slice()).unwrap();
let max = args[1].parse::<uint>().unwrap();
let rep = args[2].parse::<uint>().unwrap();
let mut checkf = Duration::seconds(0);
let mut appendf = Duration::seconds(0);

View file

@ -15,9 +15,9 @@
use std::io::BufferedReader;
use std::io::stdio::StdReader;
use std::io;
use std::iter::repeat;
use std::num::Int;
use std::os;
use std::str::from_str;
// Computes a single solution to a given 9x9 sudoku
//
@ -48,9 +48,9 @@ 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 = range(0, 9u).map(|i| {
range(0, 9u).map(|j| { vec[i][j] }).collect()
}).collect();
return Sudoku::new(g)
}
@ -70,7 +70,8 @@ impl Sudoku {
/* assert first line is exactly "9,9" */
assert!(reader.read_line().unwrap() == "9,9".to_string());
let mut g = Vec::from_fn(10u, { |_i| vec!(0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8) });
let mut g = repeat(vec![0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8])
.take(10).collect::<Vec<_>>();
for line in reader.lines() {
let line = line.unwrap();
let comps: Vec<&str> = line.as_slice()
@ -79,10 +80,9 @@ impl Sudoku {
.collect();
if comps.len() == 3u {
let row = from_str::<uint>(comps[0]).unwrap() as u8;
let col = from_str::<uint>(comps[1]).unwrap() as u8;
g[row as uint][col as uint] =
from_str::<uint>(comps[2]).unwrap() as u8;
let row = comps[0].parse::<u8>().unwrap();
let col = comps[1].parse::<u8>().unwrap();
g[row as uint][col as uint] = comps[2].parse().unwrap();
}
else {
panic!("Invalid sudoku file");

View file

@ -11,7 +11,7 @@
#![feature(unsafe_destructor)]
use std::os;
use std::task;
use std::thread::Thread;
use std::time::Duration;
#[derive(Clone)]
@ -36,9 +36,9 @@ fn main() {
fn run(repeat: int, depth: int) {
for _ in range(0, repeat) {
let dur = Duration::span(|| {
task::try(move|| {
let _ = Thread::spawn(move|| {
recurse_or_panic(depth, None)
});
}).join();
});
println!("iter: {}", dur);
}

View file

@ -19,8 +19,6 @@
use std::sync::mpsc::{channel, Sender};
use std::os;
use std::str::from_str;
use std::task;
use std::thread::Thread;
use std::uint;
@ -30,7 +28,7 @@ fn child_generation(gens_left: uint, tx: Sender<()>) {
// alive at a time,
Thread::spawn(move|| {
if gens_left & 1 == 1 {
task::deschedule(); // shake things up a bit
Thread::yield_now(); // shake things up a bit
}
if gens_left > 0 {
child_generation(gens_left - 1, tx); // recurse
@ -51,7 +49,7 @@ fn main() {
};
let (tx, rx) = channel();
child_generation(from_str::<uint>(args[1].as_slice()).unwrap(), tx);
child_generation(args[1].parse().unwrap(), tx);
if rx.recv().is_err() {
panic!("it happened when we slumbered");
}

View file

@ -9,14 +9,13 @@
// except according to those terms.
use std::os;
use std::task;
use std::uint;
use std::str::from_str;
use std::thread::Thread;
fn f(n: uint) {
let mut i = 0u;
while i < n {
task::try(move|| g());
let _ = Thread::spawn(move|| g()).join();
i += 1u;
}
}
@ -32,7 +31,7 @@ fn main() {
} else {
args.into_iter().collect()
};
let n = from_str::<uint>(args[1].as_slice()).unwrap();
let n = args[1].parse().unwrap();
let mut i = 0u;
while i < n { task::spawn(move|| f(n) ); i += 1u; }
while i < n { Thread::spawn(move|| f(n) ).detach(); i += 1u; }
}

View file

@ -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 <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.
// ignore-stage1
#![feature(phase)]
extern crate regex;
#[phase(plugin)] extern crate regex_macros;
// Tests to make sure that `regex!` will produce a compile error when given
// an invalid regular expression.
// More exhaustive failure tests for the parser are done with the traditional
// unit testing infrastructure, since both dynamic and native regexes use the
// same parser.
fn main() {
let _ = regex!("("); //~ ERROR Regex syntax error
}

View file

@ -1,31 +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 <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.
// ignore-stage1
#![feature(phase)]
extern crate regex;
#[phase(plugin)] extern crate regex_macros;
#[deny(unused_variables)]
#[deny(dead_code)]
#[allow(non_upper_case_globals)]
// Tests to make sure that extraneous dead code warnings aren't emitted from
// the code generated by regex!.
//
// The warning used for `static` items seems to be dead_code, which is why this
// is a distinct test from using a normal let binding (which generates an
// unused variable warning).
fn main() {
static fubar: regex::Regex = regex!("abc"); //~ ERROR static item is never used: `fubar`
}

View file

@ -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 <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.
// ignore-stage1
#![feature(phase)]
extern crate regex;
#[phase(plugin)] extern crate regex_macros;
#[deny(unused_variables)]
#[deny(dead_code)]
// Tests to make sure that extraneous dead code warnings aren't emitted from
// the code generated by regex!.
fn main() {
let fubar = regex!("abc"); //~ ERROR unused variable: `fubar`
}

View file

@ -1,16 +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 <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.
use std::sync::atomic::AtomicOption;
fn main() {
let x = 0u;
AtomicOption::new(box &x); //~ ERROR `x` does not live long enough
}

View file

@ -1,16 +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 <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.
use std::kinds::marker;
use std::sync::atomic::AtomicOption;
fn main() {
AtomicOption::new(box marker::NoSend); //~ ERROR `core::kinds::Send` is not implemented
}

View file

@ -8,11 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::iter::repeat;
fn main() {
let mut vector = vec![1u, 2];
for &x in vector.iter() {
let cap = vector.capacity();
vector.grow(cap, 0u); //~ ERROR cannot borrow
vector.extend(repeat(0)); //~ ERROR cannot borrow
vector[1u] = 5u; //~ ERROR cannot borrow
}
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
fn borrow(v: &int, f: |x: &int|) {
f(v);
@ -17,7 +17,7 @@ fn borrow(v: &int, f: |x: &int|) {
fn box_imm() {
let v = box 3i;
let _w = &v;
task::spawn(move|| {
Thread::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move `v` into closure
});
@ -26,7 +26,7 @@ fn box_imm() {
fn box_imm_explicit() {
let v = box 3i;
let _w = &v;
task::spawn(move|| {
Thread::spawn(move|| {
println!("v={}", *v);
//~^ ERROR cannot move
});

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
fn borrow<T>(_: &T) { }
@ -17,7 +17,7 @@ fn different_vars_after_borrows() {
let p1 = &x1;
let x2 = box 2i;
let p2 = &x2;
task::spawn(move|| {
Thread::spawn(move|| {
drop(x1); //~ ERROR cannot move `x1` into closure because it is borrowed
drop(x2); //~ ERROR cannot move `x2` into closure because it is borrowed
});
@ -30,7 +30,7 @@ fn different_vars_after_moves() {
drop(x1);
let x2 = box 2i;
drop(x2);
task::spawn(move|| {
Thread::spawn(move|| {
drop(x1); //~ ERROR capture of moved value: `x1`
drop(x2); //~ ERROR capture of moved value: `x2`
});
@ -39,7 +39,7 @@ fn different_vars_after_moves() {
fn same_var_after_borrow() {
let x = box 1i;
let p = &x;
task::spawn(move|| {
Thread::spawn(move|| {
drop(x); //~ ERROR cannot move `x` into closure because it is borrowed
drop(x); //~ ERROR use of moved value: `x`
});
@ -49,7 +49,7 @@ fn same_var_after_borrow() {
fn same_var_after_move() {
let x = box 1i;
drop(x);
task::spawn(move|| {
Thread::spawn(move|| {
drop(x); //~ ERROR capture of moved value: `x`
drop(x); //~ ERROR use of moved value: `x`
});

View file

@ -1,23 +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 <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.
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
extern crate rand;
struct Error;
#[derive(Zero)] //~ ERROR not implemented
struct Struct {
x: Error
}
fn main() {}

View file

@ -1,23 +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 <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.
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
extern crate rand;
struct Error;
#[derive(Zero)] //~ ERROR not implemented
struct Struct(
Error
);
fn main() {}

View file

@ -13,5 +13,5 @@ use std::sync::Future;
fn main() {
let f = Future::from_value(());
let g = f;
f.unwrap(); //~ ERROR use of moved value
f.into_inner(); //~ ERROR use of moved value
}

View file

@ -13,5 +13,5 @@ fn main() {
my_stuff.insert(0i, 42i);
let mut it = my_stuff.iter();
my_stuff.swap(1, 43); //~ ERROR cannot borrow
my_stuff.insert(1, 43); //~ ERROR cannot borrow
}

View file

@ -32,6 +32,6 @@ pub fn for_stdin<'a>() -> Container<'a> {
fn main() {
let mut c = for_stdin();
let mut v = vec::Vec::from_elem(10, 0u8);
let mut v = Vec::new();
c.read_to(v.as_mut_slice());
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
pub fn foo(params: Option<&[&str]>) -> uint {
params.unwrap().head().unwrap().len()
params.unwrap().first().unwrap().len()
}
fn main() {

View file

@ -20,7 +20,7 @@ trait HasInventory {
trait TraversesWorld {
fn attemptTraverse(&self, room: &Room, directionStr: &str) -> Result<&Room, &str> {
let direction = str_to_direction(directionStr);
let maybe_room = room.direction_to_room.find(&direction);
let maybe_room = room.direction_to_room.get(&direction);
//~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
match maybe_room {
Some(entry) => Ok(entry),

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
fn main() {
let x = "Hello world!".to_string();
task::spawn(move|| {
Thread::spawn(move|| {
println!("{}", x);
});
println!("{}", x); //~ ERROR use of moved value

View file

@ -11,13 +11,13 @@
// error-pattern: use of moved value
use std::sync::Arc;
use std::task;
use std::thread::Thread;
fn main() {
let v = vec!(1i, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let arc_v = Arc::new(v);
task::spawn(move|| {
Thread::spawn(move|| {
assert_eq!((*arc_v)[3], 4);
});

View file

@ -9,13 +9,13 @@
// except according to those terms.
use std::sync::Arc;
use std::task;
use std::thread::Thread;
fn main() {
let v = vec!(1i, 2, 3, 4, 5, 6, 7, 8, 9, 10);
let arc_v = Arc::new(v);
task::spawn(move|| {
Thread::spawn(move|| {
assert_eq!((*arc_v)[3], 4);
});

View file

@ -10,7 +10,7 @@
#![feature(unsafe_destructor)]
use std::task;
use std::thread::Thread;
use std::rc::Rc;
#[derive(Show)]
@ -35,7 +35,7 @@ fn main() {
let x = foo(Port(Rc::new(())));
task::spawn(move|| {
Thread::spawn(move|| {
//~^ ERROR `core::kinds::Send` is not implemented
//~^^ ERROR `core::kinds::Send` is not implemented
let y = x;

View file

@ -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 <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.
use std::task;
fn main() {
// We get an error because return type is `->int` and not `->()`.
task::spawn(|| -> int { 10 });
//~^ ERROR type mismatch
}

View file

@ -24,6 +24,4 @@ fn main() {
let x = *&x; //~ ERROR: cannot move out of dereference
let x: AtomicPtr<uint> = AtomicPtr::new(ptr::null_mut());
let x = *&x; //~ ERROR: cannot move out of dereference
let x: AtomicOption<uint> = AtomicOption::empty();
let x = *&x; //~ ERROR: cannot move out of dereference
}

View file

@ -13,7 +13,7 @@
#![feature(phase)]
#[phase(plugin, link)] extern crate log;
use std::os;
use std::task;
use std::thread::Thread;
struct r {
x:int,
@ -36,7 +36,7 @@ fn r(x:int) -> r {
fn main() {
error!("whatever");
task::spawn(move|| {
let _t = Thread::spawn(move|| {
let _i = r(5);
});
panic!();

View file

@ -10,12 +10,12 @@
// error-pattern:Ensure that the child task runs by panicking
use std::task;
use std::thread::Thread;
fn main() {
// the purpose of this test is to make sure that task::spawn()
// works when provided with a bare function:
let r = task::try(startfn);
let r = Thread::spawn(startfn).join();
if r.is_err() {
panic!()
}

View file

@ -11,9 +11,6 @@
#![feature(phase)]
extern crate lib;
extern crate regex;
#[phase(plugin)] extern crate regex_macros;
#[phase(plugin, link)] extern crate log;
fn main() {
regex!("1234");
}
fn main() {}

View file

@ -10,7 +10,7 @@
extern crate lib;
use std::task;
use std::thread::Thread;
static mut statik: int = 0;
@ -22,11 +22,11 @@ impl Drop for A {
}
fn main() {
task::try(move|| {
Thread::spawn(move|| {
let _a = A;
lib::callback(|| panic!());
1i
});
}).join().err().unwrap();
unsafe {
assert!(lib::statik == 1);

View file

@ -8,9 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::{char, os};
use std::io::{File, Command};
use std::iter::repeat;
use std::rand::{thread_rng, Rng};
use std::{char, os};
// creates a file with `fn main() { <random ident> }` and checks the
// compiler emits a span of the appropriate length (for the
@ -60,7 +61,8 @@ fn main() {
let err = String::from_utf8_lossy(result.error.as_slice());
// the span should end the line (e.g no extra ~'s)
let expected_span = format!("^{}\n", "~".repeat(n - 1));
let expected_span = format!("^{}\n", repeat("~").take(n - 1)
.collect::<String>());
assert!(err.as_slice().contains(expected_span.as_slice()));
}
}

View file

@ -10,10 +10,10 @@
// Reported as issue #126, child leaks the string.
use std::task;
use std::thread::Thread;
fn child2(_s: String) { }
pub fn main() {
let _x = task::spawn(move|| child2("hi".to_string()));
let _x = Thread::spawn(move|| child2("hi".to_string()));
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task::spawn;
use std::thread::Thread;
struct Pair {
a: int,
@ -18,7 +18,7 @@ struct Pair {
pub fn main() {
let z = box Pair { a : 10, b : 12};
spawn(move|| {
let _t = Thread::spawn(move|| {
assert_eq!(z.a, 10);
assert_eq!(z.b, 12);
});

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
use std::sync::mpsc::{channel, Sender};
pub fn main() {
let (tx, rx) = channel();
let _t = task::spawn(move|| { child(&tx) });
let _t = Thread::spawn(move|| { child(&tx) });
let y = rx.recv().unwrap();
println!("received");
println!("{}", y);

View file

@ -18,13 +18,13 @@ const C: *const u8 = B as *const u8;
pub fn main() {
unsafe {
let foo = &A as *const u8;
assert_eq!(str::raw::from_utf8(&A), "hi");
assert_eq!(string::raw::from_buf_len(foo, A.len()), "hi".to_string());
assert_eq!(string::raw::from_buf_len(C, B.len()), "hi".to_string());
assert_eq!(str::from_utf8_unchecked(&A), "hi");
assert_eq!(String::from_raw_buf_len(foo, A.len()), "hi".to_string());
assert_eq!(String::from_raw_buf_len(C, B.len()), "hi".to_string());
assert!(*C == A[0]);
assert!(*(&B[0] as *const u8) == A[0]);
let bar = str::raw::from_utf8(&A).to_c_str();
let bar = str::from_utf8_unchecked(&A).to_c_str();
assert_eq!(bar.as_str(), "hi".to_c_str().as_str());
}
}

View file

@ -1,71 +0,0 @@
// Copyright 2012-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 <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.
#![feature(associated_types)]
use std::num::Zero;
use std::ops::Add;
#[derive(Zero)]
struct Vector2<T>(T, T);
impl<T: Add<Output=T>> Add for Vector2<T> {
type Output = Vector2<T>;
fn add(self, other: Vector2<T>) -> Vector2<T> {
match (self, other) {
(Vector2(x0, y0), Vector2(x1, y1)) => {
Vector2(x0 + x1, y0 + y1)
}
}
}
}
#[derive(Zero)]
struct Vector3<T> {
x: T, y: T, z: T,
}
impl<T: Add<Output=T>> Add for Vector3<T> {
type Output = Vector3<T>;
fn add(self, other: Vector3<T>) -> Vector3<T> {
Vector3 {
x: self.x + other.x,
y: self.y + other.y,
z: self.z + other.z,
}
}
}
#[derive(Zero)]
struct Matrix3x2<T> {
x: Vector2<T>,
y: Vector2<T>,
z: Vector2<T>,
}
impl<T: Add<Output=T>> Add for Matrix3x2<T> {
type Output = Matrix3x2<T>;
fn add(self, other: Matrix3x2<T>) -> Matrix3x2<T> {
Matrix3x2 {
x: self.x + other.x,
y: self.y + other.y,
z: self.z + other.z,
}
}
}
pub fn main() {
let _: Vector2<int> = Zero::zero();
let _: Vector3<f64> = Zero::zero();
let _: Matrix3x2<u8> = Zero::zero();
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
use std::sync::mpsc::{channel, Sender};
#[derive(PartialEq, Show)]
@ -66,23 +66,23 @@ pub fn main() {
assert_eq!(receiver.recv().ok(), None);
let (sender, receiver) = channel();
task::spawn(move|| {
let _t = Thread::spawn(move|| {
let v = Foo::FailingVariant { on_drop: SendOnDrop { sender: sender } };
});
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
assert_eq!(receiver.recv().ok(), None);
let (sender, receiver) = channel();
{
task::spawn(move|| {
let _t = {
Thread::spawn(move|| {
let mut v = Foo::NestedVariant(box 42u, SendOnDrop {
sender: sender.clone()
}, sender.clone());
v = Foo::NestedVariant(box 42u, SendOnDrop { sender: sender.clone() }, sender.clone());
v = Foo::SimpleVariant(sender.clone());
v = Foo::FailingVariant { on_drop: SendOnDrop { sender: sender } };
});
}
})
};
assert_eq!(receiver.recv().unwrap(), Message::DestructorRan);
assert_eq!(receiver.recv().unwrap(), Message::Dropped);
assert_eq!(receiver.recv().unwrap(), Message::DestructorRan);

View file

@ -9,7 +9,7 @@
// except according to those terms.
extern crate libc;
use std::task;
use std::thread::Thread;
mod rustrt {
extern crate libc;
@ -40,7 +40,7 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
pub fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
task::spawn(move|| {
let _t = Thread::spawn(move|| {
let result = count(1000);
println!("result = {}", result);
assert_eq!(result, 1000);

View file

@ -13,7 +13,7 @@
// directions
extern crate libc;
use std::task;
use std::thread::Thread;
mod rustrt {
extern crate libc;
@ -44,7 +44,7 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
pub fn main() {
// Make sure we're on a task with small Rust stacks (main currently
// has a large stack)
task::spawn(move|| {
let _t = Thread::spawn(move|| {
let result = count(12);
println!("result = {}", result);
assert_eq!(result, 2048);

View file

@ -12,7 +12,7 @@
// while holding onto C stacks
extern crate libc;
use std::task;
use std::thread::Thread;
mod rustrt {
extern crate libc;
@ -29,7 +29,7 @@ extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
if data == 1 {
data
} else {
task::deschedule();
Thread::yield_now();
count(data - 1) + count(data - 1)
}
}
@ -41,9 +41,9 @@ fn count(n: libc::uintptr_t) -> libc::uintptr_t {
}
pub fn main() {
for _ in range(0u, 100) {
task::spawn(move|| {
range(0u, 100).map(|_| {
Thread::spawn(move|| {
assert_eq!(count(5), 16);
});
}
})
}).collect::<Vec<_>>();
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
extern crate libc;
use std::task;
use std::thread::Thread;
mod rustrt {
extern crate libc;
@ -32,17 +32,17 @@ extern fn cb(data: libc::uintptr_t) -> libc::uintptr_t {
fn count(n: libc::uintptr_t) -> libc::uintptr_t {
unsafe {
task::deschedule();
Thread::yield_now();
rustrt::rust_dbg_call(cb, n)
}
}
pub fn main() {
for _ in range(0, 10u) {
task::spawn(move|| {
range(0, 10u).map(|i| {
Thread::spawn(move|| {
let result = count(5);
println!("result = {}", result);
assert_eq!(result, 16);
});
}
})
}).collect::<Vec<_>>();
}

View file

@ -23,7 +23,7 @@ mod map_reduce {
use std::collections::HashMap;
use std::sync::mpsc::{channel, Sender};
use std::str;
use std::task;
use std::thread::Thread;
pub type putter<'a> = |String, String|: 'a;
@ -35,7 +35,7 @@ mod map_reduce {
for i in inputs.iter() {
let ctrl = ctrl.clone();
let i = i.clone();
task::spawn(move|| map_task(ctrl.clone(), i.clone()) );
Thread::spawn(move|| map_task(ctrl.clone(), i.clone()) ).detach();
}
}

View file

@ -14,7 +14,7 @@ struct StrWrap {
impl StrWrap {
fn new(s: &str) -> StrWrap {
StrWrap { s: s.into_string() }
StrWrap { s: s.to_string() }
}
fn get_s<'a>(&'a self) -> &'a str {

View file

@ -10,7 +10,6 @@
use std::io::{TempDir, Command, fs};
use std::os;
use std::task::TaskBuilder;
fn main() {
// If we're the child, make sure we were invoked correctly

View file

@ -12,10 +12,10 @@
extern crate "issue-17718" as other;
use std::sync::atomic;
use std::sync::atomic::{AtomicUint, ATOMIC_UINT_INIT, Ordering};
const C1: uint = 1;
const C2: atomic::AtomicUint = atomic::ATOMIC_UINT_INIT;
const C2: AtomicUint = ATOMIC_UINT_INIT;
const C3: fn() = foo;
const C4: uint = C1 * C1 + C1 / C1;
const C5: &'static uint = &C4;
@ -25,7 +25,7 @@ const C6: uint = {
};
static S1: uint = 3;
static S2: atomic::AtomicUint = atomic::ATOMIC_UINT_INIT;
static S2: AtomicUint = ATOMIC_UINT_INIT;
mod test {
static A: uint = 4;
@ -38,14 +38,14 @@ fn foo() {}
fn main() {
assert_eq!(C1, 1);
assert_eq!(C3(), ());
assert_eq!(C2.fetch_add(1, atomic::SeqCst), 0);
assert_eq!(C2.fetch_add(1, atomic::SeqCst), 0);
assert_eq!(C2.fetch_add(1, Ordering::SeqCst), 0);
assert_eq!(C2.fetch_add(1, Ordering::SeqCst), 0);
assert_eq!(C4, 2);
assert_eq!(*C5, 2);
assert_eq!(C6, 3);
assert_eq!(S1, 3);
assert_eq!(S2.fetch_add(1, atomic::SeqCst), 0);
assert_eq!(S2.fetch_add(1, atomic::SeqCst), 1);
assert_eq!(S2.fetch_add(1, Ordering::SeqCst), 0);
assert_eq!(S2.fetch_add(1, Ordering::SeqCst), 1);
match 1 {
C1 => {}
@ -62,13 +62,13 @@ fn main() {
assert_eq!(other::C1, 1);
assert_eq!(other::C3(), ());
assert_eq!(other::C2.fetch_add(1, atomic::SeqCst), 0);
assert_eq!(other::C2.fetch_add(1, atomic::SeqCst), 0);
assert_eq!(other::C2.fetch_add(1, Ordering::SeqCst), 0);
assert_eq!(other::C2.fetch_add(1, Ordering::SeqCst), 0);
assert_eq!(other::C4, 2);
assert_eq!(*other::C5, 2);
assert_eq!(other::S1, 3);
assert_eq!(other::S2.fetch_add(1, atomic::SeqCst), 0);
assert_eq!(other::S2.fetch_add(1, atomic::SeqCst), 1);
assert_eq!(other::S2.fetch_add(1, Ordering::SeqCst), 0);
assert_eq!(other::S2.fetch_add(1, Ordering::SeqCst), 1);
let _a = other::C1;
let _a = other::C2;

View file

@ -14,5 +14,5 @@ use std::collections::RingBuf;
pub fn main() {
let mut q = RingBuf::new();
q.push(10i);
q.push_front(10i);
}

View file

@ -22,7 +22,7 @@ pub mod pipes {
use std::mem::{forget, transmute};
use std::mem::{replace, swap};
use std::mem;
use std::task;
use std::thread::Thread;
use std::kinds::Send;
pub struct Stuff<T> {
@ -116,7 +116,7 @@ pub mod pipes {
let old_state = swap_state_acq(&mut (*p).state,
blocked);
match old_state {
empty | blocked => { task::deschedule(); }
empty | blocked => { Thread::yield_now(); }
full => {
let payload = replace(&mut p.payload, None);
return Some(payload.unwrap())

View file

@ -23,7 +23,7 @@ enum object {
fn lookup(table: json::Object, key: String, default: String) -> String
{
match table.find(&key.to_string()) {
match table.get(&key) {
option::Option::Some(&Json::String(ref s)) => {
s.to_string()
}

View file

@ -14,19 +14,19 @@ trait methods {
impl methods for () {
fn to_bytes(&self) -> Vec<u8> {
Vec::from_elem(0, 0u8)
Vec::new()
}
}
// 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) -> Vec<bool> {
Vec::from_fn(8, |i| {
range(0, 8).map(|i| {
let w = i / 64;
let b = i % 64;
let x = 1u64 & (bitv.storage[w] >> b);
x == 1u64
})
}).collect()
}
struct Storage { storage: Vec<u64> }

View file

@ -8,20 +8,23 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ASCII art shape renderer.
// Demonstrates traits, impls, operator overloading, non-copyable struct, unit testing.
// To run execute: rustc --test shapes.rs && ./shapes
// ASCII art shape renderer. Demonstrates traits, impls, operator overloading,
// non-copyable struct, unit testing. To run execute: rustc --test shapes.rs &&
// ./shapes
// Rust's std library is tightly bound to the language itself so it is automatically linked in.
// However the extra library is designed to be optional (for code that must run on constrained
// environments like embedded devices or special environments like kernel code) so it must
// be explicitly linked in.
// Rust's std library is tightly bound to the language itself so it is
// automatically linked in. However the extra library is designed to be
// optional (for code that must run on constrained environments like embedded
// devices or special environments like kernel code) so it must be explicitly
// linked in.
// 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.
// 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::slice;
use std::fmt;
use std::iter::repeat;
use std::slice;
// Represents a position on a canvas.
struct Point {
@ -70,7 +73,7 @@ fn AsciiArt(width: uint, height: uint, fill: char) -> AsciiArt {
// blank characters for each position in our canvas.
let mut lines = Vec::new();
for _ in range(0, height) {
lines.push(Vec::from_elem(width, '.'));
lines.push(repeat('.').take(width).collect::<Vec<_>>());
}
// Rust code often returns values by omitting the trailing semi-colon
@ -105,7 +108,7 @@ impl fmt::Show for AsciiArt {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Convert each line into a string.
let lines = self.lines.iter()
.map(|line| String::from_chars(line.as_slice()))
.map(|line| line.iter().cloned().collect())
.collect::<Vec<String>>();
// Concatenate the lines together using a new-line.

View file

@ -10,7 +10,7 @@
#![feature(default_type_params)]
use std::task;
use std::thread::Thread;
use std::sync::mpsc::Sender;
use std::thunk::Invoke;
@ -23,7 +23,7 @@ enum Msg
}
fn foo(name: String, samples_chan: Sender<Msg>) {
task::spawn(move|| {
let _t = Thread::spawn(move|| {
let mut samples_chan = samples_chan;
// `box() (...)` syntax is needed to make pretty printer converge in one try:

View file

@ -9,27 +9,27 @@
// except according to those terms.
use std::{int, i8, i16, i32, i64};
use std::task;
use std::thread::Thread;
fn main() {
assert!(task::try(move|| int::MIN / -1).is_err());
assert!(task::try(move|| i8::MIN / -1).is_err());
assert!(task::try(move|| i16::MIN / -1).is_err());
assert!(task::try(move|| i32::MIN / -1).is_err());
assert!(task::try(move|| i64::MIN / -1).is_err());
assert!(task::try(move|| 1i / 0).is_err());
assert!(task::try(move|| 1i8 / 0).is_err());
assert!(task::try(move|| 1i16 / 0).is_err());
assert!(task::try(move|| 1i32 / 0).is_err());
assert!(task::try(move|| 1i64 / 0).is_err());
assert!(task::try(move|| int::MIN % -1).is_err());
assert!(task::try(move|| i8::MIN % -1).is_err());
assert!(task::try(move|| i16::MIN % -1).is_err());
assert!(task::try(move|| i32::MIN % -1).is_err());
assert!(task::try(move|| i64::MIN % -1).is_err());
assert!(task::try(move|| 1i % 0).is_err());
assert!(task::try(move|| 1i8 % 0).is_err());
assert!(task::try(move|| 1i16 % 0).is_err());
assert!(task::try(move|| 1i32 % 0).is_err());
assert!(task::try(move|| 1i64 % 0).is_err());
assert!(Thread::spawn(move|| int::MIN / -1).join().is_err());
assert!(Thread::spawn(move|| i8::MIN / -1).join().is_err());
assert!(Thread::spawn(move|| i16::MIN / -1).join().is_err());
assert!(Thread::spawn(move|| i32::MIN / -1).join().is_err());
assert!(Thread::spawn(move|| i64::MIN / -1).join().is_err());
assert!(Thread::spawn(move|| 1i / 0).join().is_err());
assert!(Thread::spawn(move|| 1i8 / 0).join().is_err());
assert!(Thread::spawn(move|| 1i16 / 0).join().is_err());
assert!(Thread::spawn(move|| 1i32 / 0).join().is_err());
assert!(Thread::spawn(move|| 1i64 / 0).join().is_err());
assert!(Thread::spawn(move|| int::MIN % -1).join().is_err());
assert!(Thread::spawn(move|| i8::MIN % -1).join().is_err());
assert!(Thread::spawn(move|| i16::MIN % -1).join().is_err());
assert!(Thread::spawn(move|| i32::MIN % -1).join().is_err());
assert!(Thread::spawn(move|| i64::MIN % -1).join().is_err());
assert!(Thread::spawn(move|| 1i % 0).join().is_err());
assert!(Thread::spawn(move|| 1i8 % 0).join().is_err());
assert!(Thread::spawn(move|| 1i16 % 0).join().is_err());
assert!(Thread::spawn(move|| 1i32 % 0).join().is_err());
assert!(Thread::spawn(move|| 1i64 % 0).join().is_err());
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
use std::sync::mpsc::{channel, Sender};
fn producer(tx: &Sender<Vec<u8>>) {
@ -19,7 +19,7 @@ fn producer(tx: &Sender<Vec<u8>>) {
pub fn main() {
let (tx, rx) = channel::<Vec<u8>>();
let _prod = task::spawn(move|| {
let _prod = Thread::spawn(move|| {
producer(&tx)
});

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
fn user(_i: int) {}
@ -16,7 +16,7 @@ fn foo() {
// Here, i is *copied* into the proc (heap closure).
// Requires allocation. The proc's copy is not mutable.
let mut i = 0;
task::spawn(move|| {
let _t = Thread::spawn(move|| {
user(i);
println!("spawned {}", i)
});
@ -29,7 +29,7 @@ fn bar() {
// mutable outside of the proc.
let mut i = 0;
while i < 10 {
task::spawn(move|| {
let _t = Thread::spawn(move|| {
user(i);
});
i += 1;
@ -40,7 +40,7 @@ fn car() {
// Here, i must be shadowed in the proc to be mutable.
let mut i = 0;
while i < 10 {
task::spawn(move|| {
let _t = Thread::spawn(move|| {
let mut i = i;
i += 1;
user(i);

View file

@ -9,13 +9,12 @@
// except according to those terms.
use std::uint;
use std::str::from_str;
pub fn main() {
// sometimes we have had trouble finding
// the right type for f, as we unified
// bot and u32 here
let f = match from_str::<uint>("1234") {
let f = match "1234".parse::<uint>() {
None => return (),
Some(num) => num as u32
};

View file

@ -16,7 +16,7 @@
// begin failing.
mod m {
pub fn f() -> Vec<int> { Vec::from_elem(1u, 0i) }
pub fn f() -> Vec<int> { Vec::new() }
}
pub fn main() { let _x = m::f(); }

View file

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
pub fn main() {
let x = "Hello world!".to_string();
task::spawn(move|| {
let _t = Thread::spawn(move|| {
println!("{}", x);
});
}

View file

@ -10,7 +10,7 @@
// compile-flags: -Z no-landing-pads
use std::task;
use std::thread::Thread;
static mut HIT: bool = false;
@ -23,9 +23,9 @@ impl Drop for A {
}
fn main() {
task::try(move|| -> () {
Thread::spawn(move|| -> () {
let _a = A;
panic!();
});
}).join().unwrap_err();
assert!(unsafe { !HIT });
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
static mut dropped: bool = false;
@ -33,9 +33,9 @@ impl Drop for B {
}
pub fn main() {
let ret = task::try(move|| {
let ret = Thread::spawn(move|| {
let _a = A { b: B { foo: 3 } };
});
}).join();
assert!(ret.is_err());
unsafe { assert!(dropped); }
}

View file

@ -17,6 +17,7 @@ extern crate alloc;
use alloc::heap;
use std::ptr;
use std::iter::repeat;
fn main() {
unsafe {
@ -26,7 +27,7 @@ fn main() {
unsafe fn test_triangle() -> bool {
static COUNT : uint = 16;
let mut ascend = Vec::from_elem(COUNT, ptr::null_mut());
let mut ascend = repeat(ptr::null_mut()).take(COUNT).collect::<Vec<_>>();
let ascend = ascend.as_mut_slice();
static ALIGN : uint = 1;

View file

@ -33,9 +33,9 @@ fn start(argc: int, argv: *const *const u8) -> int {
}
let args = unsafe {
Vec::from_fn(argc as uint, |i| {
range(0, argc as uint).map(|i| {
String::from_raw_buf(*argv.offset(i as int)).into_bytes()
})
}).collect::<Vec<_>>()
};
let me = args[0].as_slice();

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
use std::sync::mpsc::channel;
struct test {
@ -28,7 +28,7 @@ fn test(f: int) -> test {
pub fn main() {
let (tx, rx) = channel();
task::spawn(move|| {
let _t = Thread::spawn(move|| {
let (tx2, rx2) = channel();
tx.send(tx2).unwrap();

View file

@ -11,8 +11,9 @@
extern crate collections;
use std::collections::HashMap;
use std::str::SendStr;
use std::borrow::IntoCow;
use std::borrow::{Cow, IntoCow};
type SendStr = Cow<'static, String, str>;
pub fn main() {
let mut map: HashMap<SendStr, uint> = HashMap::new();

View file

@ -11,8 +11,9 @@
extern crate collections;
use self::collections::BTreeMap;
use std::str::SendStr;
use std::borrow::IntoCow;
use std::borrow::{Cow, IntoCow};
type SendStr = Cow<'static, String, str>;
pub fn main() {
let mut map: BTreeMap<SendStr, uint> = BTreeMap::new();

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
pub fn main() { test05(); }
@ -22,7 +22,7 @@ fn test05() {
println!("{}", *three + n); // will copy x into the closure
assert_eq!(*three, 3);
};
task::spawn(move|| {
Thread::spawn(move|| {
test05_start(fn_to_send);
});
}).join().ok().unwrap();
}

View file

@ -19,6 +19,8 @@
// In any case, this test should let us know if enabling parallel codegen ever
// breaks unwinding.
use std::thread::Thread;
fn pad() -> uint { 0 }
mod a {
@ -34,5 +36,5 @@ mod b {
}
fn main() {
std::task::try(move|| { ::b::g() }).unwrap_err();
Thread::spawn(move|| { ::b::g() }).join().unwrap_err();
}

View file

@ -12,7 +12,7 @@
#![feature(slicing_syntax)]
use std::task;
use std::thread::Thread;
struct Foo;
@ -28,6 +28,6 @@ fn foo() {
}
fn main() {
let _ = task::try(move|| foo());
let _ = Thread::spawn(move|| foo()).join();
unsafe { assert!(DTOR_COUNT == 2); }
}

View file

@ -12,7 +12,7 @@
#![feature(slicing_syntax)]
use std::task;
use std::thread::Thread;
struct Foo;
@ -32,6 +32,6 @@ fn foo() {
}
fn main() {
let _ = task::try(move|| foo());
let _ = Thread::spawn(move|| foo()).join();
unsafe { assert!(DTOR_COUNT == 2); }
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
fn x(s: String, n: int) {
println!("{}", s);
@ -16,13 +16,13 @@ fn x(s: String, n: int) {
}
pub fn main() {
task::spawn(move|| x("hello from first spawned fn".to_string(), 65) );
task::spawn(move|| x("hello from second spawned fn".to_string(), 66) );
task::spawn(move|| x("hello from third spawned fn".to_string(), 67) );
let _t = Thread::spawn(|| x("hello from first spawned fn".to_string(), 65) );
let _t = Thread::spawn(|| x("hello from second spawned fn".to_string(), 66) );
let _t = Thread::spawn(|| x("hello from third spawned fn".to_string(), 67) );
let mut i: int = 30;
while i > 0 {
i = i - 1;
println!("parent sleeping");
task::deschedule();
Thread::yield_now();
}
}

View file

@ -14,7 +14,7 @@
Arnold.
*/
use std::task;
use std::thread::Thread;
use std::sync::mpsc::{channel, Sender};
type ctx = Sender<int>;
@ -25,5 +25,6 @@ fn iotask(_tx: &ctx, ip: String) {
pub fn main() {
let (tx, _rx) = channel::<int>();
task::spawn(move|| iotask(&tx, "localhost".to_string()) );
let t = Thread::spawn(move|| iotask(&tx, "localhost".to_string()) );
t.join().ok().unwrap();
}

View file

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
pub fn main() {
task::spawn(move|| child(10) );
Thread::spawn(move|| child(10)).join().ok().unwrap();
}
fn child(i: int) { println!("{}", i); assert!((i == 10)); }

View file

@ -8,9 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
pub fn main() { task::spawn(move|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) ); }
pub fn main() {
let t = Thread::spawn(move|| child((10, 20, 30, 40, 50, 60, 70, 80, 90)) );
t.join().ok().unwrap();
}
fn child(args: (int, int, int, int, int, int, int, int, int)) {
let (i1, i2, i3, i4, i5, i6, i7, i8, i9) = args;

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
use std::sync::mpsc::{channel, Sender};
pub fn main() { test05(); }
@ -24,7 +24,7 @@ fn test05_start(tx : &Sender<int>) {
fn test05() {
let (tx, rx) = channel();
task::spawn(move|| { test05_start(&tx) });
let _t = Thread::spawn(move|| { test05_start(&tx) });
let mut value: int = rx.recv().unwrap();
println!("{}", value);
value = rx.recv().unwrap();

View file

@ -8,13 +8,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
pub fn main() { test00(); }
fn start() { println!("Started / Finished task."); }
fn test00() {
task::try(move|| start() );
let _ = Thread::spawn(move|| start() ).join();
println!("Completing.");
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::task;
use std::thread::Thread;
use std::sync::mpsc::{channel, Sender};
fn start(tx: &Sender<Sender<String>>) {
@ -27,10 +27,10 @@ fn start(tx: &Sender<Sender<String>>) {
pub fn main() {
let (tx, rx) = channel();
let _child = task::spawn(move|| { start(&tx) });
let _child = Thread::spawn(move|| { start(&tx) });
let mut c = rx.recv().unwrap();
c.send("A".to_string()).unwrap();
c.send("B".to_string()).unwrap();
task::deschedule();
Thread::yield_now();
}

View file

@ -9,17 +9,17 @@
// except according to those terms.
use std::sync::mpsc::{channel, Sender};
use std::task;
use std::thread::Thread;
fn start(tx: &Sender<Sender<int>>) {
let (tx2, _rx) = channel();
tx.send(tx2);
tx.send(tx2).unwrap();
}
pub fn main() {
let (tx, rx) = channel();
let _child = task::spawn(move|| {
let _child = Thread::spawn(move|| {
start(&tx)
});
let _tx = rx.recv();
let _tx = rx.recv().unwrap();
}

Some files were not shown because too many files have changed in this diff Show more