mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
test: Clean out the test suite a bit
This updates a number of ignore-test tests, and removes a few completely outdated tests due to the feature being tested no longer being supported. This brings a number of bench/shootout tests up to date so they're compiling again. I make no claims to the performance of these benchmarks, it's just nice to not have bitrotted code. Closes #2604 Closes #9407
This commit is contained in:
parent
34a224f4a1
commit
9cc26cfdf4
@ -1394,8 +1394,6 @@ mod test {
|
||||
});
|
||||
}
|
||||
|
||||
// FIXME: #9407: ignore-test
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn dont_starve_1() {
|
||||
let mut pool = SchedPool::new(PoolConfig {
|
||||
|
@ -10,6 +10,6 @@
|
||||
|
||||
mod super_sekrit {
|
||||
pub enum sooper_sekrit {
|
||||
pub quux, priv baz
|
||||
quux, priv baz
|
||||
}
|
||||
}
|
||||
|
@ -8,11 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test reading from os::args()[1] - bogus!
|
||||
|
||||
use std::from_str::FromStr;
|
||||
use std::os;
|
||||
use std::vec::MutableVector;
|
||||
use std::vec;
|
||||
|
||||
fn max(a: i32, b: i32) -> i32 {
|
||||
@ -23,7 +19,6 @@ fn max(a: i32, b: i32) -> i32 {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn fannkuch_redux(n: i32) -> i32 {
|
||||
let mut perm = vec::from_elem(n as uint, 0i32);
|
||||
let mut perm1 = vec::from_fn(n as uint, |i| i as i32);
|
||||
@ -34,74 +29,70 @@ fn fannkuch_redux(n: i32) -> i32 {
|
||||
|
||||
let mut r = n;
|
||||
loop {
|
||||
unsafe {
|
||||
while r != 1 {
|
||||
count.unsafe_set((r-1) as uint, r);
|
||||
r -= 1;
|
||||
}
|
||||
|
||||
for (perm_i, perm1_i) in perm.mut_iter().zip(perm1.iter()) {
|
||||
*perm_i = *perm1_i;
|
||||
}
|
||||
|
||||
let mut flips_count: i32 = 0;
|
||||
let mut k: i32;
|
||||
loop {
|
||||
k = *perm.unsafe_ref(0);
|
||||
if k == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
let k2 = (k+1) >> 1;
|
||||
for i in range(0i32, k2) {
|
||||
let (perm_i, perm_k_i) = {
|
||||
(*perm.unsafe_ref(i as uint),
|
||||
*perm.unsafe_ref((k-i) as uint))
|
||||
};
|
||||
perm.unsafe_set(i as uint, perm_k_i);
|
||||
perm.unsafe_set((k-i) as uint, perm_i);
|
||||
}
|
||||
flips_count += 1;
|
||||
}
|
||||
|
||||
max_flips_count = max(max_flips_count, flips_count);
|
||||
checksum += if perm_count % 2 == 0 {
|
||||
flips_count
|
||||
} else {
|
||||
-flips_count
|
||||
};
|
||||
|
||||
// Use incremental change to generate another permutation.
|
||||
loop {
|
||||
if r == n {
|
||||
println!("{}", checksum);
|
||||
return max_flips_count;
|
||||
}
|
||||
|
||||
let perm0 = perm1[0];
|
||||
let mut i: i32 = 0;
|
||||
while i < r {
|
||||
let j = i + 1;
|
||||
let perm1_j = { *perm1.unsafe_ref(j as uint) };
|
||||
perm1.unsafe_set(i as uint, perm1_j);
|
||||
i = j;
|
||||
}
|
||||
perm1.unsafe_set(r as uint, perm0);
|
||||
|
||||
let count_r = { *count.unsafe_ref(r as uint) };
|
||||
count.unsafe_set(r as uint, count_r - 1);
|
||||
if *count.unsafe_ref(r as uint) > 0 {
|
||||
break;
|
||||
}
|
||||
r += 1;
|
||||
}
|
||||
|
||||
perm_count += 1;
|
||||
while r != 1 {
|
||||
count[r - 1] = r;
|
||||
r -= 1;
|
||||
}
|
||||
|
||||
for (perm_i, perm1_i) in perm.mut_iter().zip(perm1.iter()) {
|
||||
*perm_i = *perm1_i;
|
||||
}
|
||||
|
||||
let mut flips_count: i32 = 0;
|
||||
let mut k: i32;
|
||||
loop {
|
||||
k = perm[0];
|
||||
if k == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
let k2 = (k+1) >> 1;
|
||||
for i in range(0i32, k2) {
|
||||
perm.swap(i as uint, (k - i) as uint);
|
||||
}
|
||||
flips_count += 1;
|
||||
}
|
||||
|
||||
max_flips_count = max(max_flips_count, flips_count);
|
||||
checksum += if perm_count % 2 == 0 {
|
||||
flips_count
|
||||
} else {
|
||||
-flips_count
|
||||
};
|
||||
|
||||
// Use incremental change to generate another permutation.
|
||||
loop {
|
||||
if r == n {
|
||||
println!("{}", checksum);
|
||||
return max_flips_count;
|
||||
}
|
||||
|
||||
let perm0 = perm1[0];
|
||||
let mut i: i32 = 0;
|
||||
while i < r {
|
||||
let j = i + 1;
|
||||
perm1[i] = perm1[j];
|
||||
i = j;
|
||||
}
|
||||
perm1[r] = perm0;
|
||||
|
||||
count[r] -= 1;
|
||||
if count[r] > 0 {
|
||||
break;
|
||||
}
|
||||
r += 1;
|
||||
}
|
||||
|
||||
perm_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n: i32 = FromStr::from_str(os::args()[1]).unwrap();
|
||||
let args = os::args();
|
||||
let n = if args.len() > 1 {
|
||||
from_str::<i32>(args[1]).unwrap()
|
||||
} else {
|
||||
2
|
||||
};
|
||||
println!("Pfannkuchen({}) = {}", n as int, fannkuch_redux(n) as int);
|
||||
}
|
||||
|
@ -8,13 +8,9 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test reading from os::args()[1] - bogus!
|
||||
|
||||
use std::cast::transmute;
|
||||
use std::from_str::FromStr;
|
||||
use std::libc::{FILE, STDOUT_FILENO, c_int, fdopen, fputc, fputs, fwrite, size_t};
|
||||
use std::cmp::min;
|
||||
use std::io::{stdout, BufferedWriter, IoResult};
|
||||
use std::os;
|
||||
use std::uint::min;
|
||||
use std::vec::bytes::copy_memory;
|
||||
use std::vec;
|
||||
|
||||
@ -37,10 +33,6 @@ static ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\
|
||||
|
||||
static NULL_AMINO_ACID: AminoAcid = AminoAcid { c: ' ' as u8, p: 0.0 };
|
||||
|
||||
static MESSAGE_1: &'static str = ">ONE Homo sapiens alu\n";
|
||||
static MESSAGE_2: &'static str = ">TWO IUB ambiguity codes\n";
|
||||
static MESSAGE_3: &'static str = ">THREE Homo sapiens frequency\n";
|
||||
|
||||
static IUB: [AminoAcid, ..15] = [
|
||||
AminoAcid { c: 'a' as u8, p: 0.27 },
|
||||
AminoAcid { c: 'c' as u8, p: 0.12 },
|
||||
@ -85,75 +77,70 @@ struct AminoAcid {
|
||||
p: f32,
|
||||
}
|
||||
|
||||
struct RepeatFasta {
|
||||
struct RepeatFasta<'a, W> {
|
||||
alu: &'static str,
|
||||
stdout: *FILE,
|
||||
out: &'a mut W
|
||||
}
|
||||
|
||||
impl RepeatFasta {
|
||||
fn new(stdout: *FILE, alu: &'static str) -> RepeatFasta {
|
||||
RepeatFasta {
|
||||
alu: alu,
|
||||
stdout: stdout,
|
||||
}
|
||||
impl<'a, W: Writer> RepeatFasta<'a, W> {
|
||||
fn new(alu: &'static str, w: &'a mut W) -> RepeatFasta<'a, W> {
|
||||
RepeatFasta { alu: alu, out: w }
|
||||
}
|
||||
|
||||
fn make(&mut self, n: uint) {
|
||||
unsafe {
|
||||
let stdout = self.stdout;
|
||||
let alu_len = self.alu.len();
|
||||
let mut buf = vec::from_elem(alu_len + LINE_LEN, 0u8);
|
||||
let alu: &[u8] = self.alu.as_bytes();
|
||||
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 alu: &[u8] = self.alu.as_bytes();
|
||||
|
||||
copy_memory(buf, alu);
|
||||
let buf_len = buf.len();
|
||||
copy_memory(buf.mut_slice(alu_len, buf_len),
|
||||
alu.slice_to(LINE_LEN));
|
||||
copy_memory(buf, alu);
|
||||
let buf_len = buf.len();
|
||||
copy_memory(buf.mut_slice(alu_len, buf_len),
|
||||
alu.slice_to(LINE_LEN));
|
||||
|
||||
let mut pos = 0;
|
||||
let mut bytes;
|
||||
let mut n = n;
|
||||
while n > 0 {
|
||||
bytes = min(LINE_LEN, n);
|
||||
fwrite(transmute(&buf[pos]), bytes as size_t, 1, stdout);
|
||||
fputc('\n' as c_int, stdout);
|
||||
pos += bytes;
|
||||
if pos > alu_len {
|
||||
pos -= alu_len;
|
||||
}
|
||||
n -= bytes;
|
||||
let mut pos = 0;
|
||||
let mut bytes;
|
||||
let mut n = n;
|
||||
while n > 0 {
|
||||
bytes = min(LINE_LEN, n);
|
||||
try!(self.out.write(buf.slice(pos, pos + bytes)));
|
||||
try!(self.out.write_u8('\n' as u8));
|
||||
pos += bytes;
|
||||
if pos > alu_len {
|
||||
pos -= alu_len;
|
||||
}
|
||||
n -= bytes;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct RandomFasta {
|
||||
seed: u32,
|
||||
stdout: *FILE,
|
||||
lookup: [AminoAcid, ..LOOKUP_SIZE],
|
||||
fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
|
||||
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
|
||||
let mut j = 0;
|
||||
for (i, slot) in lookup.mut_iter().enumerate() {
|
||||
while a[j].p < (i as f32) {
|
||||
j += 1;
|
||||
}
|
||||
*slot = a[j];
|
||||
}
|
||||
lookup
|
||||
}
|
||||
|
||||
impl RandomFasta {
|
||||
fn new(stdout: *FILE, a: &[AminoAcid]) -> RandomFasta {
|
||||
struct RandomFasta<'a, W> {
|
||||
seed: u32,
|
||||
lookup: [AminoAcid, ..LOOKUP_SIZE],
|
||||
out: &'a mut W,
|
||||
}
|
||||
|
||||
impl<'a, W: Writer> RandomFasta<'a, W> {
|
||||
fn new(w: &'a mut W, a: &[AminoAcid]) -> RandomFasta<'a, W> {
|
||||
RandomFasta {
|
||||
seed: 42,
|
||||
stdout: stdout,
|
||||
lookup: RandomFasta::make_lookup(a),
|
||||
out: w,
|
||||
lookup: make_lookup(a),
|
||||
}
|
||||
}
|
||||
|
||||
fn make_lookup(a: &[AminoAcid]) -> [AminoAcid, ..LOOKUP_SIZE] {
|
||||
let mut lookup = [ NULL_AMINO_ACID, ..LOOKUP_SIZE ];
|
||||
let mut j = 0;
|
||||
for (i, slot) in lookup.mut_iter().enumerate() {
|
||||
while a[j].p < (i as f32) {
|
||||
j += 1;
|
||||
}
|
||||
*slot = a[j];
|
||||
}
|
||||
lookup
|
||||
}
|
||||
|
||||
fn rng(&mut self, max: f32) -> f32 {
|
||||
self.seed = (self.seed * IA + IC) % IM;
|
||||
max * (self.seed as f32) / (IM as f32)
|
||||
@ -169,51 +156,50 @@ impl RandomFasta {
|
||||
0
|
||||
}
|
||||
|
||||
fn make(&mut self, n: uint) {
|
||||
unsafe {
|
||||
let lines = n / LINE_LEN;
|
||||
let chars_left = n % LINE_LEN;
|
||||
let mut buf = [0, ..LINE_LEN + 1];
|
||||
fn make(&mut self, n: uint) -> IoResult<()> {
|
||||
let lines = n / LINE_LEN;
|
||||
let chars_left = n % LINE_LEN;
|
||||
let mut buf = [0, ..LINE_LEN + 1];
|
||||
|
||||
for _ in range(0, lines) {
|
||||
for i in range(0u, LINE_LEN) {
|
||||
buf[i] = self.nextc();
|
||||
}
|
||||
buf[LINE_LEN] = '\n' as u8;
|
||||
fwrite(transmute(&buf[0]),
|
||||
LINE_LEN as size_t + 1,
|
||||
1,
|
||||
self.stdout);
|
||||
}
|
||||
for i in range(0u, chars_left) {
|
||||
for _ in range(0, lines) {
|
||||
for i in range(0u, LINE_LEN) {
|
||||
buf[i] = self.nextc();
|
||||
}
|
||||
fwrite(transmute(&buf[0]), chars_left as size_t, 1, self.stdout);
|
||||
buf[LINE_LEN] = '\n' as u8;
|
||||
try!(self.out.write(buf));
|
||||
}
|
||||
for i in range(0u, chars_left) {
|
||||
buf[i] = self.nextc();
|
||||
}
|
||||
self.out.write(buf.slice_to(chars_left))
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let n: uint = FromStr::from_str(os::args()[1]).unwrap();
|
||||
let args = os::args();
|
||||
let n = if args.len() > 1 {
|
||||
from_str::<uint>(args[1]).unwrap()
|
||||
} else {
|
||||
5
|
||||
};
|
||||
|
||||
unsafe {
|
||||
let mode = "w";
|
||||
let stdout = fdopen(STDOUT_FILENO as c_int, transmute(&mode[0]));
|
||||
let mut out = BufferedWriter::new(stdout());
|
||||
|
||||
fputs(transmute(&MESSAGE_1[0]), stdout);
|
||||
let mut repeat = RepeatFasta::new(stdout, ALU);
|
||||
repeat.make(n * 2);
|
||||
|
||||
fputs(transmute(&MESSAGE_2[0]), stdout);
|
||||
let iub = sum_and_scale(IUB);
|
||||
let mut random = RandomFasta::new(stdout, iub);
|
||||
random.make(n * 3);
|
||||
|
||||
fputs(transmute(&MESSAGE_3[0]), stdout);
|
||||
let homo_sapiens = sum_and_scale(HOMO_SAPIENS);
|
||||
random.lookup = RandomFasta::make_lookup(homo_sapiens);
|
||||
random.make(n * 5);
|
||||
|
||||
fputc('\n' as c_int, stdout);
|
||||
out.write_line(">ONE Homo sapiens alu").unwrap();
|
||||
{
|
||||
let mut repeat = RepeatFasta::new(ALU, &mut out);
|
||||
repeat.make(n * 2).unwrap();
|
||||
}
|
||||
|
||||
out.write_line(">TWO IUB ambiguity codes").unwrap();
|
||||
let iub = sum_and_scale(IUB);
|
||||
let mut random = RandomFasta::new(&mut out, iub);
|
||||
random.make(n * 3).unwrap();
|
||||
|
||||
random.out.write_line(">THREE Homo sapiens frequency").unwrap();
|
||||
let homo_sapiens = sum_and_scale(HOMO_SAPIENS);
|
||||
random.lookup = make_lookup(homo_sapiens);
|
||||
random.make(n * 5).unwrap();
|
||||
|
||||
random.out.write_str("\n").unwrap();
|
||||
}
|
||||
|
@ -8,19 +8,11 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
// ignore-pretty
|
||||
|
||||
extern crate extra;
|
||||
use std::str;
|
||||
use std::vec;
|
||||
|
||||
use std::cast::transmute;
|
||||
use std::i32::range;
|
||||
use std::libc::{STDIN_FILENO, c_int, fdopen, fgets, fileno, fopen, fstat};
|
||||
use std::libc::{stat, strlen};
|
||||
use std::mem::init;
|
||||
use std::ptr::null;
|
||||
use std::vec::{reverse};
|
||||
|
||||
static LINE_LEN: uint = 80;
|
||||
static TABLE: [u8, ..4] = [ 'A' as u8, 'C' as u8, 'G' as u8, 'T' as u8 ];
|
||||
static TABLE_SIZE: uint = 2 << 16;
|
||||
|
||||
@ -34,41 +26,37 @@ static OCCURRENCES: [&'static str, ..5] = [
|
||||
|
||||
// Code implementation
|
||||
|
||||
#[deriving(Eq, Ord)]
|
||||
#[deriving(Eq, TotalOrd, TotalEq)]
|
||||
struct Code(u64);
|
||||
|
||||
impl Code {
|
||||
fn hash(&self) -> u64 {
|
||||
**self
|
||||
let Code(ret) = *self;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn push_char(&self, c: u8) -> Code {
|
||||
Code((**self << 2) + (pack_symbol(c) as u64))
|
||||
Code((self.hash() << 2) + (pack_symbol(c) as u64))
|
||||
}
|
||||
|
||||
fn rotate(&self, c: u8, frame: i32) -> Code {
|
||||
Code(*self.push_char(c) & ((1u64 << (2 * (frame as u64))) - 1))
|
||||
Code(self.push_char(c).hash() & ((1u64 << (2 * (frame as u64))) - 1))
|
||||
}
|
||||
|
||||
fn pack(string: &str) -> Code {
|
||||
let mut code = Code(0u64);
|
||||
for i in range(0u, string.len()) {
|
||||
code = code.push_char(string[i]);
|
||||
}
|
||||
code
|
||||
string.bytes().fold(Code(0u64), |a, b| a.push_char(b))
|
||||
}
|
||||
|
||||
// FIXME: Inefficient.
|
||||
fn unpack(&self, frame: i32) -> ~str {
|
||||
let mut key = **self;
|
||||
let mut key = self.hash();
|
||||
let mut result = ~[];
|
||||
for _ in range(0, frame) {
|
||||
result.push(unpack_symbol((key as u8) & 3));
|
||||
key >>= 2;
|
||||
}
|
||||
|
||||
reverse(result);
|
||||
result.reverse();
|
||||
str::from_utf8_owned(result).unwrap()
|
||||
}
|
||||
}
|
||||
@ -91,7 +79,8 @@ struct PrintCallback(&'static str);
|
||||
|
||||
impl TableCallback for PrintCallback {
|
||||
fn f(&self, entry: &mut Entry) {
|
||||
println!("{}\t{}", entry.count as int, **self);
|
||||
let PrintCallback(s) = *self;
|
||||
println!("{}\t{}", entry.count as int, s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,14 +92,19 @@ struct Entry {
|
||||
|
||||
struct Table {
|
||||
count: i32,
|
||||
items: [Option<~Entry>, ..TABLE_SIZE]
|
||||
items: ~[Option<~Entry>]
|
||||
}
|
||||
|
||||
struct Items<'a> {
|
||||
cur: Option<&'a Entry>,
|
||||
items: vec::Items<'a, Option<~Entry>>,
|
||||
}
|
||||
|
||||
impl Table {
|
||||
fn new() -> Table {
|
||||
Table {
|
||||
count: 0,
|
||||
items: [ None, ..TABLE_SIZE ],
|
||||
items: vec::from_fn(TABLE_SIZE, |_| None),
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +131,7 @@ impl Table {
|
||||
}
|
||||
|
||||
fn lookup<C:TableCallback>(&mut self, key: Code, c: C) {
|
||||
let index = *key % (TABLE_SIZE as u64);
|
||||
let index = key.hash() % (TABLE_SIZE as u64);
|
||||
|
||||
{
|
||||
if self.items[index].is_none() {
|
||||
@ -153,7 +147,7 @@ impl Table {
|
||||
}
|
||||
|
||||
{
|
||||
let mut entry = &mut *self.items[index].get_mut_ref();
|
||||
let entry = &mut *self.items[index].get_mut_ref();
|
||||
if entry.code == key {
|
||||
c.f(*entry);
|
||||
return;
|
||||
@ -163,37 +157,45 @@ impl Table {
|
||||
}
|
||||
}
|
||||
|
||||
fn each(&self, f: |entry: &Entry| -> bool) {
|
||||
for self.items.each |item| {
|
||||
match *item {
|
||||
None => {}
|
||||
Some(ref item) => {
|
||||
let mut item: &Entry = *item;
|
||||
loop {
|
||||
if !f(item) {
|
||||
return;
|
||||
}
|
||||
fn iter<'a>(&'a self) -> Items<'a> {
|
||||
Items { cur: None, items: self.items.iter() }
|
||||
}
|
||||
}
|
||||
|
||||
match item.next {
|
||||
None => break,
|
||||
Some(ref next_item) => item = &**next_item,
|
||||
}
|
||||
impl<'a> Iterator<&'a Entry> for Items<'a> {
|
||||
fn next(&mut self) -> Option<&'a Entry> {
|
||||
let ret = match self.cur {
|
||||
None => {
|
||||
let i;
|
||||
loop {
|
||||
match self.items.next() {
|
||||
None => return None,
|
||||
Some(&None) => {}
|
||||
Some(&Some(ref a)) => { i = &**a; break }
|
||||
}
|
||||
}
|
||||
};
|
||||
self.cur = Some(&*i);
|
||||
&*i
|
||||
}
|
||||
Some(c) => c
|
||||
};
|
||||
match ret.next {
|
||||
None => { self.cur = None; }
|
||||
Some(ref next) => { self.cur = Some(&**next); }
|
||||
}
|
||||
return Some(ret);
|
||||
}
|
||||
}
|
||||
|
||||
// Main program
|
||||
|
||||
fn pack_symbol(c: u8) -> u8 {
|
||||
match c {
|
||||
'a' as u8 | 'A' as u8 => 0,
|
||||
'c' as u8 | 'C' as u8 => 1,
|
||||
'g' as u8 | 'G' as u8 => 2,
|
||||
't' as u8 | 'T' as u8 => 3,
|
||||
_ => fail!(c.to_str())
|
||||
match c as char {
|
||||
'a' | 'A' => 0,
|
||||
'c' | 'C' => 1,
|
||||
'g' | 'G' => 2,
|
||||
't' | 'T' => 3,
|
||||
_ => fail!("{}", c as char),
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,43 +217,6 @@ fn next_char<'a>(mut buf: &'a [u8]) -> &'a [u8] {
|
||||
buf
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn read_stdin() -> ~[u8] {
|
||||
unsafe {
|
||||
let mode = "r";
|
||||
//let stdin = fdopen(STDIN_FILENO as c_int, transmute(&mode[0]));
|
||||
let path = "knucleotide-input.txt";
|
||||
let stdin = fopen(transmute(&path[0]), transmute(&mode[0]));
|
||||
|
||||
let mut st: stat = init();
|
||||
fstat(fileno(stdin), &mut st);
|
||||
let mut buf = vec::from_elem(st.st_size as uint, 0);
|
||||
|
||||
let header = ">THREE".as_bytes();
|
||||
|
||||
{
|
||||
let mut window: &mut [u8] = buf;
|
||||
loop {
|
||||
fgets(transmute(&mut window[0]), LINE_LEN as c_int, stdin);
|
||||
|
||||
{
|
||||
if window.slice(0, 6) == header {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while fgets(transmute(&mut window[0]),
|
||||
LINE_LEN as c_int,
|
||||
stdin) != null() {
|
||||
window = window.mut_slice(strlen(transmute(&window[0])) as uint, window.len());
|
||||
}
|
||||
}
|
||||
|
||||
buf
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_frequencies(frequencies: &mut Table,
|
||||
mut input: &[u8],
|
||||
frame: i32) {
|
||||
@ -273,20 +238,20 @@ fn generate_frequencies(frequencies: &mut Table,
|
||||
|
||||
fn print_frequencies(frequencies: &Table, frame: i32) {
|
||||
let mut vector = ~[];
|
||||
for frequencies.each |entry| {
|
||||
for entry in frequencies.iter() {
|
||||
vector.push((entry.code, entry.count));
|
||||
}
|
||||
vector.sort();
|
||||
|
||||
let mut total_count = 0;
|
||||
for vector.each |&(_, count)| {
|
||||
for &(_, count) in vector.iter() {
|
||||
total_count += count;
|
||||
}
|
||||
|
||||
for vector.each |&(key, count)| {
|
||||
for &(key, count) in vector.iter() {
|
||||
println!("{} {:.3f}",
|
||||
key.unpack(frame),
|
||||
(count as float * 100.0) / (total_count as float));
|
||||
(count as f32 * 100.0) / (total_count as f32));
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,22 +260,24 @@ fn print_occurrences(frequencies: &mut Table, occurrence: &'static str) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let input = read_stdin();
|
||||
let input = include_str!("shootout-k-nucleotide.data");
|
||||
let pos = input.find_str(">THREE").unwrap();
|
||||
let pos2 = pos + input.slice_from(pos).find_str("\n").unwrap();
|
||||
let input = input.slice_from(pos2 + 1).as_bytes();
|
||||
|
||||
let mut frequencies = ~Table::new();
|
||||
generate_frequencies(frequencies, input, 1);
|
||||
print_frequencies(frequencies, 1);
|
||||
let mut frequencies = Table::new();
|
||||
generate_frequencies(&mut frequencies, input, 1);
|
||||
print_frequencies(&frequencies, 1);
|
||||
|
||||
*frequencies = Table::new();
|
||||
generate_frequencies(frequencies, input, 2);
|
||||
print_frequencies(frequencies, 2);
|
||||
frequencies = Table::new();
|
||||
generate_frequencies(&mut frequencies, input, 2);
|
||||
print_frequencies(&frequencies, 2);
|
||||
|
||||
for range(0, 5) |i| {
|
||||
let occurrence = OCCURRENCES[i];
|
||||
*frequencies = Table::new();
|
||||
generate_frequencies(frequencies,
|
||||
for occurrence in OCCURRENCES.iter() {
|
||||
frequencies = Table::new();
|
||||
generate_frequencies(&mut frequencies,
|
||||
input,
|
||||
occurrence.len() as i32);
|
||||
print_occurrences(frequencies, occurrence);
|
||||
print_occurrences(&mut frequencies, *occurrence);
|
||||
}
|
||||
}
|
||||
|
@ -1,103 +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-pretty
|
||||
// ignore-test linked failure
|
||||
|
||||
// Copyright 2012-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.
|
||||
|
||||
/**
|
||||
* Test performance of killing many tasks in a taskgroup.
|
||||
* Along the way, tests various edge cases of ancestor group management.
|
||||
* In particular, this tries to get each grandchild task to hit the
|
||||
* "nobe_is_dead" case in each_ancestor only during task exit, but not during
|
||||
* task spawn. This makes sure that defunct ancestor groups are handled correctly
|
||||
* w.r.t. possibly leaving stale *rust_tasks lying around.
|
||||
*/
|
||||
|
||||
// Creates in the background 'num_tasks' tasks, all blocked forever.
|
||||
// Doesn't return until all such tasks are ready, but doesn't block forever itself.
|
||||
|
||||
use std::comm::{stream, Chan};
|
||||
use std::os;
|
||||
use std::result;
|
||||
use std::task;
|
||||
use std::uint;
|
||||
|
||||
fn grandchild_group(num_tasks: uint) {
|
||||
let (po, ch) = stream();
|
||||
let ch = Chan::new(ch);
|
||||
|
||||
for _ in range(0, num_tasks) {
|
||||
let ch = ch.clone();
|
||||
let mut t = task::task();
|
||||
t.spawn(proc() { // linked
|
||||
ch.send(());
|
||||
let (p, _c) = stream::<()>();
|
||||
p.recv(); // block forever
|
||||
});
|
||||
}
|
||||
error!("Grandchild group getting started");
|
||||
for _ in range(0, num_tasks) {
|
||||
// Make sure all above children are fully spawned; i.e., enlisted in
|
||||
// their ancestor groups.
|
||||
po.recv();
|
||||
}
|
||||
error!("Grandchild group ready to go.");
|
||||
// Master grandchild task exits early.
|
||||
}
|
||||
|
||||
fn spawn_supervised_blocking(myname: &str, f: proc()) {
|
||||
let mut builder = task::task();
|
||||
let res = builder.future_result();
|
||||
builder.supervised();
|
||||
builder.spawn(f);
|
||||
error!("{} group waiting", myname);
|
||||
let x = res.recv();
|
||||
assert!(x.is_ok());
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = os::args();
|
||||
let args = if os::getenv("RUST_BENCH").is_some() {
|
||||
~[~"", ~"100000"]
|
||||
} else if args.len() <= 1u {
|
||||
~[~"", ~"100"]
|
||||
} else {
|
||||
args.clone()
|
||||
};
|
||||
|
||||
let num_tasks = from_str::<uint>(args[1]).unwrap();
|
||||
|
||||
// Main group #0 waits for unsupervised group #1.
|
||||
// Grandparent group #1 waits for middle group #2, then fails, killing #3.
|
||||
// Middle group #2 creates grandchild_group #3, waits for it to be ready, exits.
|
||||
let x: result::Result<(), ~Any> = task::try(proc() { // unlinked
|
||||
spawn_supervised_blocking("grandparent", proc() {
|
||||
spawn_supervised_blocking("middle", proc() {
|
||||
grandchild_group(num_tasks);
|
||||
});
|
||||
// When grandchild group is ready to go, make the middle group exit.
|
||||
error!("Middle group wakes up and exits");
|
||||
});
|
||||
// Grandparent group waits for middle group to be gone, then fails
|
||||
error!("Grandparent group wakes up and fails");
|
||||
fail!();
|
||||
});
|
||||
assert!(x.is_err());
|
||||
}
|
@ -8,24 +8,11 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
// ignored because the lint pass doesn't know to ignore standard library
|
||||
// stuff.
|
||||
|
||||
// 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: unreachable statement
|
||||
|
||||
#[deny(unreachable_code)];
|
||||
|
||||
fn main() {
|
||||
return;
|
||||
info!("Paul is dead"); //~ ERROR: unreachable
|
||||
info!("Paul is dead");
|
||||
}
|
||||
|
@ -8,10 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:empty #[link_name] not allowed; use #[nolink].
|
||||
|
||||
// ignore-test
|
||||
|
||||
#[link_name = ""]
|
||||
#[link(name = "")] //~ ERROR: given with empty name
|
||||
extern {
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2012-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-test
|
||||
|
||||
// error-pattern:empty #[link_name] not allowed; use #[nolink].
|
||||
// Issue #1326
|
||||
|
||||
#[link_name = ""]
|
||||
#[nolink]
|
||||
extern {
|
||||
}
|
@ -8,26 +8,24 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
// test that autoderef of a type like this does not
|
||||
// cause compiler to loop. Note that no instances
|
||||
// of such a type could ever be constructed.
|
||||
struct t(@t); //~ ERROR this type cannot be instantiated
|
||||
struct t(~t); //~ ERROR this type cannot be instantiated
|
||||
|
||||
trait to_str_2 {
|
||||
fn to_str() -> ~str;
|
||||
fn my_to_str() -> ~str;
|
||||
}
|
||||
|
||||
// I use an impl here because it will cause
|
||||
// the compiler to attempt autoderef and then
|
||||
// try to resolve the method.
|
||||
impl to_str_2 for t {
|
||||
fn to_str() -> ~str { ~"t" }
|
||||
fn my_to_str() -> ~str { ~"t" }
|
||||
}
|
||||
|
||||
fn new_t(x: t) {
|
||||
x.to_str();
|
||||
x.my_to_str(); //~ ERROR does not implement
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2012-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-test
|
||||
|
||||
fn main()
|
||||
{
|
||||
// See #2969 -- error message should be improved
|
||||
let mut x = [1, 2, 4];
|
||||
let v : &int = &x[2];
|
||||
x[2] = 6;
|
||||
assert_eq!(*v, 6);
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// Copyright 2012-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-test
|
||||
// error-pattern: instantiating a type parameter with an incompatible type
|
||||
|
||||
struct S<T:Freeze> {
|
||||
s: T,
|
||||
cant_nest: ()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a1 = ~S{ s: true, cant_nest: () };
|
||||
let _a2 = ~S{ s: a1, cant_nest: () };
|
||||
}
|
@ -23,11 +23,11 @@ impl ToStr for Point { //~ ERROR implements a method not defined in the trait
|
||||
}
|
||||
|
||||
fn to_str(&self) -> ~str {
|
||||
fmt!("(%f, %f)", self.x, self.y)
|
||||
format!("({}, {})", self.x, self.y)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p = Point::new(0.0f, 0.0f);
|
||||
let p = Point::new(0.0, 0.0);
|
||||
println!("{}", p.to_str());
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2013-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-test
|
||||
|
||||
fn main() {
|
||||
for os::args().each |arg| {
|
||||
match (*arg).clone() {
|
||||
s => { }
|
||||
}
|
||||
}
|
||||
}
|
@ -8,9 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
trait I {}
|
||||
type K = I;
|
||||
impl K for int {}
|
||||
type K = I; //~ ERROR: reference to trait
|
||||
impl K for int {} //~ ERROR: `K` is not a trait
|
||||
fn main() {}
|
||||
|
@ -8,8 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
// Creating a stack closure which references an owned pointer and then
|
||||
// transferring ownership of the owned box before invoking the stack
|
||||
// closure results in a crash.
|
||||
@ -26,6 +24,6 @@ fn main() {
|
||||
let x : ~uint = ~9;
|
||||
let sq : || -> uint = || { *x * *x };
|
||||
|
||||
twice(x);
|
||||
twice(x); //~ ERROR: cannot move out of
|
||||
invoke(sq);
|
||||
}
|
||||
|
@ -1,61 +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-test
|
||||
// ignored because to_foo() doesn't work.
|
||||
|
||||
// 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.
|
||||
|
||||
// A dummy trait/impl that work close over any type. The trait will
|
||||
// be parameterized by a region due to the &'a int constraint.
|
||||
|
||||
trait foo {
|
||||
fn foo(&self, i: &'a int) -> int;
|
||||
}
|
||||
|
||||
impl<T:Clone> foo for T {
|
||||
fn foo(&self, i: &'a int) -> int {*i}
|
||||
}
|
||||
|
||||
fn to_foo<T:Clone>(t: T) {
|
||||
// This version is ok because, although T may contain references
|
||||
// it never escapes the fn body. We know this because
|
||||
// the type of foo includes a region which will be resolved to
|
||||
// the fn body itself.
|
||||
let v = &3;
|
||||
struct F<T> { f: T }
|
||||
let x = @F {f:t} as @foo;
|
||||
assert_eq!(x.foo(v), 3);
|
||||
}
|
||||
|
||||
fn to_foo_2<T:Clone>(t: T) -> @foo {
|
||||
// Not OK---T may contain references and it is going to escape
|
||||
// as part of the returned foo value
|
||||
struct F<T> { f: T }
|
||||
@F {f:t} as @foo //~ ERROR value may contain references; add `'static` bound
|
||||
}
|
||||
|
||||
fn to_foo_3<T:Clone + 'static>(t: T) -> @foo {
|
||||
// OK---T may escape as part of the returned foo value, but it is
|
||||
// owned and hence does not contain references
|
||||
struct F<T> { f: T }
|
||||
@F {f:t} as @foo
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
@ -8,21 +8,9 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
// ignored because lint is messed up with the new visitor transition
|
||||
|
||||
// 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.
|
||||
|
||||
#[deny(unused_variable)];
|
||||
#[deny(dead_assignment)];
|
||||
#[allow(dead_code, non_camel_case_types)];
|
||||
|
||||
fn f1(x: int) {
|
||||
//~^ ERROR unused variable: `x`
|
||||
|
@ -8,13 +8,12 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
type foo = Option<int>;
|
||||
|
||||
fn bar(_t: foo) {}
|
||||
fn let_in<T>(x: T, f: |T|) {}
|
||||
|
||||
fn main() {
|
||||
// we used to print foo<int>:
|
||||
bar(Some(3u)); //~ ERROR mismatched types: expected `foo`
|
||||
let_in(3u, |i| { assert!(i == 3i); });
|
||||
//~^ ERROR expected `uint` but found `int`
|
||||
|
||||
let_in(3i, |i| { assert!(i == 3u); });
|
||||
//~^ ERROR expected `int` but found `uint`
|
||||
}
|
||||
|
@ -8,12 +8,11 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
// aux-build:private_variant_xc.rs
|
||||
|
||||
extern crate private_variant_xc;
|
||||
|
||||
pub fn main() {
|
||||
let _ = private_variant_xc::Bar;
|
||||
let _ = private_variant_xc::Baz; //~ ERROR unresolved name
|
||||
let _ = private_variant_xc::Baz; //~ ERROR variant `Baz` is private
|
||||
}
|
||||
|
@ -8,11 +8,10 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
// aux-build:private_variant_1.rs
|
||||
|
||||
extern crate private_variant_1;
|
||||
|
||||
fn main() {
|
||||
let _x = private_variant_1::super_sekrit::baz; //~ ERROR baz is private
|
||||
let _x = private_variant_1::super_sekrit::baz; //~ ERROR is private
|
||||
}
|
||||
|
@ -8,20 +8,19 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
enum Nil {Nil}
|
||||
struct Cons<T> {head:int, tail:T}
|
||||
trait Dot {fn dot(other:self) -> int;}
|
||||
trait Dot {fn dot(&self, other:Self) -> int;}
|
||||
impl Dot for Nil {
|
||||
fn dot(_:Nil) -> int {0}
|
||||
fn dot(&self, _:Nil) -> int {0}
|
||||
}
|
||||
impl<T:Dot> Dot for Cons<T> {
|
||||
fn dot(other:Cons<T>) -> int {
|
||||
fn dot(&self, other:Cons<T>) -> int {
|
||||
self.head * other.head + self.tail.dot(other.tail)
|
||||
}
|
||||
}
|
||||
fn test<T:Dot> (n:int, i:int, first:T, second:T) ->int {
|
||||
//~^ ERROR: overly deep expansion of inlined function
|
||||
match n {
|
||||
0 => {first.dot(second)}
|
||||
// Error message should be here. It should be a type error
|
@ -1,30 +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.
|
||||
|
||||
// ignore-fast
|
||||
// ignore-test
|
||||
|
||||
// error-pattern:library 'm' already added: can't specify link_args.
|
||||
|
||||
/* I think it should undefined to have multiple modules that link in the same
|
||||
library, but provide different link arguments. Unfortunately we don't track
|
||||
link_args by module -- they are just appended as discovered into the crate
|
||||
store -- but for now, it should be an error to provide link_args on a module
|
||||
that's already been included (with or without link_args). */
|
||||
|
||||
#[link_name= "m"]
|
||||
#[link_args="-foo"] // this could have been elided.
|
||||
extern {
|
||||
}
|
||||
|
||||
#[link_name= "m"]
|
||||
#[link_args="-bar"] // this is the actual error trigger.
|
||||
extern {
|
||||
}
|
@ -24,21 +24,23 @@
|
||||
fn of<T>() -> |T| { fail!(); }
|
||||
fn subtype<T>(x: |T|) { fail!(); }
|
||||
|
||||
fn test_fn<T>(_x: &'x T, _y: &'y T, _z: &'z T) {
|
||||
fn test_fn<'x, 'y, 'z, T>(_x: &'x T, _y: &'y T, _z: &'z T) {
|
||||
// Here, x, y, and z are free. Other letters
|
||||
// are bound. Note that the arrangement
|
||||
// subtype::<T1>(of::<T2>()) will typecheck
|
||||
// iff T1 <: T2.
|
||||
|
||||
// should be the default:
|
||||
subtype::<'static ||>(of::<||>());
|
||||
subtype::<||>(of::<'static ||>());
|
||||
subtype::< ||:'static>(of::<||>());
|
||||
subtype::<||>(of::< ||:'static>());
|
||||
|
||||
//
|
||||
subtype::<'x ||>(of::<||>()); //~ ERROR mismatched types
|
||||
subtype::<'x ||>(of::<'y ||>()); //~ ERROR mismatched types
|
||||
subtype::< <'x> ||>(of::<||>()); //~ ERROR mismatched types
|
||||
subtype::< <'x> ||>(of::< <'y> ||>()); //~ ERROR mismatched types
|
||||
|
||||
subtype::<'x ||>(of::<'static ||>()); //~ ERROR mismatched types
|
||||
subtype::<'static ||>(of::<'x ||>());
|
||||
subtype::< <'x> ||>(of::< ||:'static>()); //~ ERROR mismatched types
|
||||
subtype::< ||:'static>(of::< <'x> ||>());
|
||||
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -8,13 +8,13 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
// this now fails (correctly, I claim) because hygiene prevents
|
||||
// the assembled identifier from being a reference to the binding.
|
||||
|
||||
pub fn main() {
|
||||
let asdf_fdsa = ~"<.<";
|
||||
assert_eq!(concat_idents!(asd, f_f, dsa), ~"<.<");
|
||||
//~^ ERROR: unresolved name `asdf_fdsa`
|
||||
|
||||
assert!(stringify!(use_mention_distinction) ==
|
||||
"use_mention_distinction");
|
@ -1,32 +0,0 @@
|
||||
// Copyright 2012-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-test
|
||||
// error-pattern: what
|
||||
|
||||
trait Foo {
|
||||
fn f();
|
||||
}
|
||||
|
||||
trait Bar : Foo {
|
||||
fn g();
|
||||
}
|
||||
|
||||
struct A {
|
||||
x: int
|
||||
}
|
||||
|
||||
// Can't implement Bar without an impl of Foo
|
||||
impl Bar for A {
|
||||
fn g() { }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
// error-pattern: ran out of stack
|
||||
// error-pattern: task '<main>' has overflowed its stack
|
||||
|
||||
struct R {
|
||||
b: int,
|
||||
|
@ -1,25 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
// error-pattern:1 == 2
|
||||
|
||||
extern crate extra;
|
||||
|
||||
use std::comm;
|
||||
use std::task;
|
||||
|
||||
fn child() { assert!((1 == 2)); }
|
||||
|
||||
fn main() {
|
||||
let (p, _c) = comm::stream::<int>();
|
||||
task::spawn(|| child() );
|
||||
let x = p.recv();
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
// error-pattern:fail
|
||||
|
||||
use std::comm;
|
||||
use std::task;
|
||||
|
||||
fn child() { fail!(); }
|
||||
|
||||
fn main() {
|
||||
let (p, _c) = comm::stream::<()>();
|
||||
task::spawn(|| child() );
|
||||
task::deschedule();
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
// error-pattern:fail
|
||||
|
||||
use std::comm;
|
||||
use std::task;
|
||||
|
||||
fn grandchild() { fail!("grandchild dies"); }
|
||||
|
||||
fn child() {
|
||||
let (p, _c) = comm::stream::<int>();
|
||||
task::spawn(|| grandchild() );
|
||||
let x = p.recv();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let (p, _c) = comm::stream::<int>();
|
||||
task::spawn(|| child() );
|
||||
let x = p.recv();
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
// error-pattern:1 == 2
|
||||
|
||||
use std::comm;
|
||||
use std::task;
|
||||
|
||||
fn child() { assert!((1 == 2)); }
|
||||
|
||||
fn parent() {
|
||||
let (p, _c) = comm::stream::<int>();
|
||||
task::spawn(|| child() );
|
||||
let x = p.recv();
|
||||
}
|
||||
|
||||
// This task is not linked to the failure chain, but since the other
|
||||
// tasks are going to fail the kernel, this one will fail too
|
||||
fn sleeper() {
|
||||
let (p, _c) = comm::stream::<int>();
|
||||
let x = p.recv();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn(|| sleeper() );
|
||||
task::spawn(|| parent() );
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
// error-pattern:explicit
|
||||
|
||||
extern crate extra;
|
||||
|
||||
use std::task;
|
||||
|
||||
// We don't want to see any invalid reads
|
||||
fn main() {
|
||||
fn f() {
|
||||
fail!();
|
||||
}
|
||||
task::spawn(|| f() );
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
// error-pattern:goodfail
|
||||
|
||||
use std::comm;
|
||||
use std::task;
|
||||
|
||||
fn goodfail() {
|
||||
task::deschedule();
|
||||
fail!("goodfail");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
task::spawn(|| goodfail() );
|
||||
let (po, _c) = comm::stream();
|
||||
// We shouldn't be able to get past this recv since there's no
|
||||
// message available
|
||||
let i: int = po.recv();
|
||||
fail!("badfail");
|
||||
}
|
@ -13,32 +13,32 @@
|
||||
|
||||
#[feature(managed_boxes)];
|
||||
|
||||
extern crate extra;
|
||||
extern crate time;
|
||||
extern crate serialize;
|
||||
|
||||
// These tests used to be separate files, but I wanted to refactor all
|
||||
// the common code.
|
||||
|
||||
use std::hashmap::{HashMap, HashSet};
|
||||
|
||||
use EBReader = extra::ebml::reader;
|
||||
use EBWriter = extra::ebml::writer;
|
||||
use EBReader = serialize::ebml::reader;
|
||||
use EBWriter = serialize::ebml::writer;
|
||||
use std::cmp::Eq;
|
||||
use std::cmp;
|
||||
use std::io;
|
||||
use serialize::{Decodable, Encodable};
|
||||
|
||||
fn test_ebml<'a, A:
|
||||
fn test_ebml<'a, 'b, A:
|
||||
Eq +
|
||||
Encodable<EBWriter::Encoder> +
|
||||
Decodable<EBReader::Decoder<'a>>
|
||||
Encodable<EBWriter::Encoder<'a>> +
|
||||
Decodable<EBReader::Decoder<'b>>
|
||||
>(a1: &A) {
|
||||
let mut wr = std::io::MemWriter::new();
|
||||
let mut ebml_w = EBWriter::Encoder(&mut wr);
|
||||
a1.encode(&mut ebml_w);
|
||||
let bytes = wr.get_ref();
|
||||
|
||||
let d: extra::ebml::Doc<'a> = EBReader::Doc(bytes);
|
||||
let d: serialize::ebml::Doc<'a> = EBReader::Doc(bytes);
|
||||
let mut decoder: EBReader::Decoder<'a> = EBReader::Decoder(d);
|
||||
let a2: A = Decodable::decode(&mut decoder);
|
||||
assert!(*a1 == a2);
|
||||
|
@ -54,7 +54,7 @@ struct G<T> {
|
||||
t: T
|
||||
}
|
||||
|
||||
fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder> +
|
||||
fn roundtrip<'a, T: Rand + Eq + Encodable<Encoder<'a>> +
|
||||
Decodable<Decoder<'a>>>() {
|
||||
let obj: T = random();
|
||||
let mut w = MemWriter::new();
|
||||
|
@ -8,13 +8,10 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test: #3511: does not currently compile, due to rvalue issues
|
||||
|
||||
use std::vec;
|
||||
|
||||
struct Pair { x: int, y: int }
|
||||
|
||||
pub fn main() {
|
||||
for vec::each(~[Pair {x: 10, y: 20}, Pair {x: 30, y: 0}]) |elt| {
|
||||
for elt in (~[Pair {x: 10, y: 20}, Pair {x: 30, y: 0}]).iter() {
|
||||
assert_eq!(elt.x + elt.y, 30);
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2012-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-test FIXME I don't know how to test this (#2604)
|
||||
// compile-flags:-L.
|
||||
// The -L flag is also used for linking foreign libraries
|
||||
|
||||
mod WHATGOESHERE {
|
||||
// FIXME: I want to name a mod that would not link successfully
|
||||
// wouthout providing a -L argument to the compiler, and that
|
||||
// will also be found successfully at runtime.
|
||||
extern {
|
||||
pub fn IDONTKNOW() -> u32;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(IDONTKNOW(), 0x_BAD_DOOD_u32);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright 2012-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-test FIXME #7308
|
||||
|
||||
native mod libc = target_libc {
|
||||
fn open(int name, int flags, int mode) -> int;
|
||||
fn close(int fd) -> int;
|
||||
fn read(int fd, int buf, int count) -> int;
|
||||
fn write(int fd, int buf, int count) -> int;
|
||||
fn malloc(int sz) -> int;
|
||||
fn free(int p) -> ();
|
||||
}
|
||||
|
||||
native "cdecl" mod rustrt {
|
||||
fn str_buf(str s) -> int;
|
||||
}
|
||||
|
||||
mod inner = "native-mod-src/inner.rs";
|
@ -1,22 +0,0 @@
|
||||
// Copyright 2012-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-test
|
||||
|
||||
native "cdecl" mod rustrt {
|
||||
fn str_buf(str s) -> int;
|
||||
}
|
||||
|
||||
|
||||
native mod libc = target_libc {
|
||||
fn puts(int s) -> ();
|
||||
}
|
||||
|
||||
mod user = "native-src/native.rs";
|
@ -8,22 +8,26 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test linked failure
|
||||
#[allow(unused_variable)];
|
||||
|
||||
extern crate extra;
|
||||
struct T { f: extern "Rust" fn() }
|
||||
struct S { f: extern "Rust" fn() }
|
||||
|
||||
use std::task;
|
||||
|
||||
fn die() {
|
||||
fail!();
|
||||
fn fooS(t: S) {
|
||||
}
|
||||
|
||||
fn iloop() {
|
||||
task::spawn(|| die() );
|
||||
fn fooT(t: T) {
|
||||
}
|
||||
|
||||
fn bar() {
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
for _ in range(0u, 100u) {
|
||||
task::spawn_unlinked(|| iloop() );
|
||||
}
|
||||
let x: extern "Rust" fn() = bar;
|
||||
fooS(S {f: x});
|
||||
fooS(S {f: bar});
|
||||
|
||||
let x: extern "Rust" fn() = bar;
|
||||
fooT(T {f: x});
|
||||
fooT(T {f: bar});
|
||||
}
|
@ -8,13 +8,16 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
extern crate extra;
|
||||
|
||||
use list = extra::oldmap::chained;
|
||||
use extra::list;
|
||||
#[allow(non_camel_case_types)];
|
||||
|
||||
pub fn main() {
|
||||
let _x: list::T<int, int> = list::mk();
|
||||
let one: || -> uint = || {
|
||||
enum r { a };
|
||||
a as uint
|
||||
};
|
||||
let two: || -> uint = || {
|
||||
enum r { a };
|
||||
a as uint
|
||||
};
|
||||
one(); two();
|
||||
}
|
@ -8,18 +8,24 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
use std::task;
|
||||
|
||||
static generations: uint = 1024+256+128+49;
|
||||
|
||||
fn spawn(f: proc()) {
|
||||
let mut t = task::task();
|
||||
t.opts.stack_size = Some(32 * 1024);
|
||||
t.spawn(f);
|
||||
}
|
||||
|
||||
fn child_no(x: uint) -> proc() {
|
||||
|| {
|
||||
proc() {
|
||||
if x < generations {
|
||||
task::spawn(child_no(x+1));
|
||||
spawn(child_no(x+1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
task::spawn(child_no(0));
|
||||
spawn(child_no(0));
|
||||
}
|
||||
|
@ -17,13 +17,13 @@ mod a {
|
||||
}
|
||||
|
||||
mod b {
|
||||
fn foo(f: Option<||>) { f.iter(|x|x()) }
|
||||
fn foo(f: Option<||>) { f.map(|x|x()); }
|
||||
fn bar() {}
|
||||
pub fn main() { foo(Some(bar)); }
|
||||
}
|
||||
|
||||
mod c {
|
||||
fn foo(f: Option<||>) { f.iter(|x|x()) }
|
||||
fn foo(f: Option<||>) { f.map(|x|x()); }
|
||||
fn bar() {}
|
||||
pub fn main() { foo(Some(||bar())); }
|
||||
}
|
||||
|
@ -1,19 +0,0 @@
|
||||
// Copyright 2012-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-test
|
||||
|
||||
type t = {
|
||||
f: proc()
|
||||
};
|
||||
|
||||
pub fn main() {
|
||||
let _t: t = { f: {||()} };
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
// ignore-fast
|
||||
|
||||
use std::comm;
|
||||
use std::task;
|
||||
|
||||
pub fn main() {
|
||||
let (p,c) = comm::stream();
|
||||
task::try(|| {
|
||||
let (p2,c2) = comm::stream();
|
||||
task::spawn(|| {
|
||||
p2.recv();
|
||||
error!("sibling fails");
|
||||
fail!();
|
||||
});
|
||||
let (p3,c3) = comm::stream();
|
||||
c.send(c3);
|
||||
c2.send(());
|
||||
error!("child blocks");
|
||||
p3.recv();
|
||||
});
|
||||
error!("parent tries");
|
||||
assert!(!p.recv().try_send(()));
|
||||
error!("all done!");
|
||||
}
|
@ -8,7 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test FIXME #3290
|
||||
pub fn main() {
|
||||
let mut x = ~3;
|
||||
x = x;
|
||||
|
@ -1,20 +0,0 @@
|
||||
// Copyright 2013-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-test FIXME #3796
|
||||
|
||||
#[deny(dead_assignment)];
|
||||
pub fn main() {
|
||||
let mut x = 1;
|
||||
let f: || -> int = || { x + 20 };
|
||||
assert_eq!(f(), 21);
|
||||
x += 1;
|
||||
assert_eq!(f(), 22);
|
||||
}
|
@ -8,30 +8,28 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
type ErrPrinter = |&str, &str|;
|
||||
type ErrPrinter<'a> = 'a |&str, &str|;
|
||||
|
||||
fn example_err(prog: &str, arg: &str) {
|
||||
println!("{}: {}", prog, arg)
|
||||
}
|
||||
|
||||
fn exit(+print: ErrPrinter, prog: &str, arg: &str) {
|
||||
fn exit(print: ErrPrinter, prog: &str, arg: &str) {
|
||||
print(prog, arg);
|
||||
}
|
||||
|
||||
struct X {
|
||||
err: ErrPrinter
|
||||
struct X<'a> {
|
||||
err: ErrPrinter<'a>
|
||||
}
|
||||
|
||||
impl X {
|
||||
pub fn boom() {
|
||||
impl<'a> X<'a> {
|
||||
pub fn boom(self) {
|
||||
exit(self.err, "prog", "arg");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main(){
|
||||
let val = &X{
|
||||
let val = X {
|
||||
err: example_err,
|
||||
};
|
||||
val.boom();
|
||||
|
@ -1,130 +0,0 @@
|
||||
// Copyright 2013-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-fast
|
||||
// ignore-test needs networking
|
||||
|
||||
extern crate extra;
|
||||
|
||||
use extra::net::tcp::TcpSocketBuf;
|
||||
|
||||
use std::io;
|
||||
use std::int;
|
||||
|
||||
use std::io::{ReaderUtil,WriterUtil};
|
||||
|
||||
enum Result {
|
||||
Nil,
|
||||
Int(int),
|
||||
Data(~[u8]),
|
||||
List(~[Result]),
|
||||
Error(~str),
|
||||
Status(~str)
|
||||
}
|
||||
|
||||
priv fn parse_data(len: uint, io: @io::Reader) -> Result {
|
||||
let res =
|
||||
if (len > 0) {
|
||||
let bytes = io.read_bytes(len as uint);
|
||||
assert_eq!(bytes.len(), len);
|
||||
Data(bytes)
|
||||
} else {
|
||||
Data(~[])
|
||||
};
|
||||
assert_eq!(io.read_char(), '\r');
|
||||
assert_eq!(io.read_char(), '\n');
|
||||
return res;
|
||||
}
|
||||
|
||||
priv fn parse_list(len: uint, io: @io::Reader) -> Result {
|
||||
let mut list: ~[Result] = ~[];
|
||||
for _ in range(0, len) {
|
||||
let v = match io.read_char() {
|
||||
'$' => parse_bulk(io),
|
||||
':' => parse_int(io),
|
||||
_ => fail!()
|
||||
};
|
||||
list.push(v);
|
||||
}
|
||||
return List(list);
|
||||
}
|
||||
|
||||
priv fn chop(s: ~str) -> ~str {
|
||||
s.slice(0, s.len() - 1).to_owned()
|
||||
}
|
||||
|
||||
priv fn parse_bulk(io: @io::Reader) -> Result {
|
||||
match from_str::<int>(chop(io.read_line())) {
|
||||
None => fail!(),
|
||||
Some(-1) => Nil,
|
||||
Some(len) if len >= 0 => parse_data(len as uint, io),
|
||||
Some(_) => fail!()
|
||||
}
|
||||
}
|
||||
|
||||
priv fn parse_multi(io: @io::Reader) -> Result {
|
||||
match from_str::<int>(chop(io.read_line())) {
|
||||
None => fail!(),
|
||||
Some(-1) => Nil,
|
||||
Some(0) => List(~[]),
|
||||
Some(len) if len >= 0 => parse_list(len as uint, io),
|
||||
Some(_) => fail!()
|
||||
}
|
||||
}
|
||||
|
||||
priv fn parse_int(io: @io::Reader) -> Result {
|
||||
match from_str::<int>(chop(io.read_line())) {
|
||||
None => fail!(),
|
||||
Some(i) => Int(i)
|
||||
}
|
||||
}
|
||||
|
||||
priv fn parse_response(io: @io::Reader) -> Result {
|
||||
match io.read_char() {
|
||||
'$' => parse_bulk(io),
|
||||
'*' => parse_multi(io),
|
||||
'+' => Status(chop(io.read_line())),
|
||||
'-' => Error(chop(io.read_line())),
|
||||
':' => parse_int(io),
|
||||
_ => fail!()
|
||||
}
|
||||
}
|
||||
|
||||
priv fn cmd_to_str(cmd: ~[~str]) -> ~str {
|
||||
let mut res = ~"*";
|
||||
res.push_str(cmd.len().to_str());
|
||||
res.push_str("\r\n");
|
||||
for s in cmd.iter() {
|
||||
res.push_str([~"$", s.len().to_str(), ~"\r\n",
|
||||
(*s).clone(), ~"\r\n"].concat() );
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
fn query(cmd: ~[~str], sb: TcpSocketBuf) -> Result {
|
||||
let cmd = cmd_to_str(cmd);
|
||||
//println!("{}", cmd);
|
||||
sb.write_str(cmd);
|
||||
let res = parse_response(@sb as @io::Reader);
|
||||
res
|
||||
}
|
||||
|
||||
fn query2(cmd: ~[~str]) -> Result {
|
||||
let _cmd = cmd_to_str(cmd);
|
||||
io::with_str_reader(~"$3\r\nXXX\r\n")(|sb| {
|
||||
let res = parse_response(@sb as @io::Reader);
|
||||
println!("{:?}", res);
|
||||
res
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
pub fn main() {
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
@ -11,9 +11,8 @@
|
||||
use std::os;
|
||||
|
||||
pub fn main() {
|
||||
let x = os::args();
|
||||
for arg in x.iter() {
|
||||
match arg.clone() {
|
||||
for arg in os::args().iter() {
|
||||
match (*arg).clone() {
|
||||
_s => { }
|
||||
}
|
||||
}
|
||||
|
@ -8,19 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-test
|
||||
|
||||
// ignored due to a bug in move detection for macros.
|
||||
|
||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <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(macro_rules)];
|
||||
|
||||
use std::{option, cast};
|
||||
|
||||
@ -42,7 +30,7 @@ impl<T> E<T> {
|
||||
}
|
||||
fn get_ref<'r>(&'r self) -> (int, &'r T) {
|
||||
match *self {
|
||||
Nothing(..) => fail!("E::get_ref(Nothing::<%s>)", stringify!($T)),
|
||||
Nothing(..) => fail!("E::get_ref(Nothing::<{}>)", stringify!(T)),
|
||||
Thing(x, ref y) => (x, y)
|
||||
}
|
||||
}
|
||||
@ -71,7 +59,7 @@ macro_rules! check_fancy {
|
||||
let t_ = Thing::<$T>(23, e);
|
||||
match t_.get_ref() {
|
||||
(23, $v) => { $chk }
|
||||
_ => fail!("Thing::<%s>(23, %s).get_ref() != (23, _)",
|
||||
_ => fail!("Thing::<{}>(23, {}).get_ref() != (23, _)",
|
||||
stringify!($T), stringify!($e))
|
||||
}
|
||||
}}
|
||||
@ -91,7 +79,7 @@ pub fn main() {
|
||||
check_type!(~"foo": ~str);
|
||||
check_type!(~[20, 22]: ~[int]);
|
||||
let mint: uint = unsafe { cast::transmute(main) };
|
||||
check_type!(main: extern fn(), |pthing| {
|
||||
check_type!(main: fn(), |pthing| {
|
||||
assert!(mint == unsafe { cast::transmute(*pthing) })
|
||||
});
|
||||
}
|
||||
|
@ -1,39 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
extern crate extra;
|
||||
|
||||
use std::comm;
|
||||
use std::task;
|
||||
|
||||
fn die() {
|
||||
fail!();
|
||||
}
|
||||
|
||||
fn iloop() {
|
||||
task::spawn(|| die() );
|
||||
let (p, c) = comm::stream::<()>();
|
||||
loop {
|
||||
// Sending and receiving here because these actions deschedule,
|
||||
// at which point our child can kill us.
|
||||
c.send(());
|
||||
p.recv();
|
||||
// The above comment no longer makes sense but I'm
|
||||
// reluctant to remove a linked failure test case.
|
||||
task::deschedule();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
for _ in range(0u, 16u) {
|
||||
task::spawn_unlinked(|| iloop() );
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
|
||||
// A port of task-killjoin to use a class with a dtor to manage
|
||||
// the join.
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::comm::*;
|
||||
use std::ptr;
|
||||
use std::task;
|
||||
|
||||
struct notify {
|
||||
ch: Chan<bool>,
|
||||
v: @Cell<bool>,
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
impl Drop for notify {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
error!("notify: task=%? v=%x unwinding=%b b=%b",
|
||||
0,
|
||||
ptr::to_unsafe_ptr(&(*(self.v))) as uint,
|
||||
task::failing(),
|
||||
*(self.v));
|
||||
let b = *(self.v);
|
||||
self.ch.send(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn notify(ch: Chan<bool>, v: @Cell<bool>) -> notify {
|
||||
notify {
|
||||
ch: ch,
|
||||
v: v
|
||||
}
|
||||
}
|
||||
|
||||
fn joinable(f: proc()) -> Port<bool> {
|
||||
fn wrapper(c: Chan<bool>, f: ||) {
|
||||
let b = @Cell::new(false);
|
||||
error!("wrapper: task=%? allocated v=%x",
|
||||
0,
|
||||
ptr::to_unsafe_ptr(&b) as uint);
|
||||
let _r = notify(c, b);
|
||||
f();
|
||||
*b = true;
|
||||
}
|
||||
let (p, c) = stream();
|
||||
task::spawn_unlinked(proc() {
|
||||
let ccc = c;
|
||||
wrapper(ccc, f)
|
||||
});
|
||||
p
|
||||
}
|
||||
|
||||
fn join(port: Port<bool>) -> bool {
|
||||
port.recv()
|
||||
}
|
||||
|
||||
fn supervised() {
|
||||
// Deschedule to make sure the supervisor joins before we
|
||||
// fail. This is currently not needed because the supervisor
|
||||
// runs first, but I can imagine that changing.
|
||||
error!("supervised task=%?", 0);
|
||||
task::deschedule();
|
||||
fail!();
|
||||
}
|
||||
|
||||
fn supervisor() {
|
||||
error!("supervisor task=%?", 0);
|
||||
let t = joinable(supervised);
|
||||
join(t);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
join(joinable(supervisor));
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
// Copyright 2012-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-test linked failure
|
||||
|
||||
// Create a task that is supervised by another task, join the supervised task
|
||||
// from the supervising task, then fail the supervised task. The supervised
|
||||
// task will kill the supervising task, waking it up. The supervising task no
|
||||
// longer needs to be wakened when the supervised task exits.
|
||||
|
||||
use std::task;
|
||||
|
||||
fn supervised() {
|
||||
// Deschedule to make sure the supervisor joins before we fail. This is
|
||||
// currently not needed because the supervisor runs first, but I can
|
||||
// imagine that changing.
|
||||
task::deschedule();
|
||||
fail!();
|
||||
}
|
||||
|
||||
fn supervisor() {
|
||||
// Unsupervise this task so the process doesn't return a failure status as
|
||||
// a result of the main task being killed.
|
||||
let f = supervised;
|
||||
task::try(supervised);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
task::spawn_unlinked(supervisor)
|
||||
}
|
Loading…
Reference in New Issue
Block a user