Merge remote-tracking branch 'mozilla/master'

Conflicts:
	src/libextra/test.rs
	src/libstd/at_vec.rs
	src/libstd/cleanup.rs
	src/libstd/rt/comm.rs
	src/libstd/rt/global_heap.rs
	src/libstd/task/spawn.rs
	src/libstd/unstable/lang.rs
	src/libstd/vec.rs
	src/rt/rustrt.def.in
	src/test/run-pass/extern-pub.rs
This commit is contained in:
Brian Anderson 2013-07-02 17:36:58 -07:00
commit 1098d6980b
765 changed files with 23500 additions and 17316 deletions

View file

@ -11,7 +11,7 @@
use std::comm::*;
use std::task;
pub fn foo<T:Owned + Copy>(x: T) -> Port<T> {
pub fn foo<T:Send + Copy>(x: T) -> Port<T> {
let (p, c) = stream();
do task::spawn() {
c.send(copy x);

View file

@ -24,7 +24,7 @@ pub fn alist_add<A:Copy,B:Copy>(lst: &alist<A,B>, k: A, v: B) {
pub fn alist_get<A:Copy,B:Copy>(lst: &alist<A,B>, k: A) -> B {
let eq_fn = lst.eq_fn;
for lst.data.each |entry| {
for lst.data.iter().advance |entry| {
if eq_fn(copy entry.key, copy k) { return copy entry.value; }
}
fail!();

View file

@ -20,17 +20,17 @@ struct arc_destruct<T> {
}
#[unsafe_destructor]
impl<T:Const> Drop for arc_destruct<T> {
fn finalize(&self) {}
impl<T:Freeze> Drop for arc_destruct<T> {
fn drop(&self) {}
}
fn arc_destruct<T:Const>(data: int) -> arc_destruct<T> {
fn arc_destruct<T:Freeze>(data: int) -> arc_destruct<T> {
arc_destruct {
_data: data
}
}
fn arc<T:Const>(_data: T) -> arc_destruct<T> {
fn arc<T:Freeze>(_data: T) -> arc_destruct<T> {
arc_destruct(0)
}
@ -45,7 +45,7 @@ struct context_res {
}
impl Drop for context_res {
fn finalize(&self) {}
fn drop(&self) {}
}
fn context_res() -> context_res {

View file

@ -19,7 +19,7 @@ pub mod socket {
}
impl Drop for socket_handle {
fn finalize(&self) {
fn drop(&self) {
/* c::close(self.sockfd); */
}
}

View file

@ -16,7 +16,7 @@ pub struct rsrc {
}
impl Drop for rsrc {
fn finalize(&self) {
fn drop(&self) {
foo(self.x);
}
}

View file

@ -15,7 +15,7 @@ pub struct S {
}
impl Drop for S {
fn finalize(&self) {
fn drop(&self) {
println("goodbye");
}
}

View file

@ -0,0 +1 @@
pub static mut a: int = 3;

View file

@ -0,0 +1,34 @@
#[allow(default_methods)];
pub trait A {
fn f(&self) -> int;
fn g(&self) -> int { 10 }
fn h(&self) -> int { 10 }
}
impl A for int {
fn f(&self) -> int { 10 }
}
trait B<T> {
fn thing<U>(&self, x: T, y: U) -> (T, U) { (x, y) }
}
impl<T> B<T> for int { }
impl B<float> for bool { }
pub trait TestEquality {
fn test_eq(&self, rhs: &Self) -> bool;
fn test_neq(&self, rhs: &Self) -> bool {
!self.test_eq(rhs)
}
}
impl TestEquality for int {
fn test_eq(&self, rhs: &int) -> bool {
*self == *rhs
}
}

View file

@ -29,7 +29,7 @@ macro_rules! bench (
fn main() {
let argv = os::args();
let tests = vec::slice(argv, 1, argv.len());
let tests = argv.slice(1, argv.len());
bench!(shift_push);
bench!(read_line);
@ -44,7 +44,7 @@ fn maybe_run_test(argv: &[~str], name: ~str, test: &fn()) {
if os::getenv(~"RUST_BENCH").is_some() {
run_test = true
} else if argv.len() > 0 {
run_test = argv.contains(&~"all") || argv.contains(&name)
run_test = argv.iter().any_(|x| x == &~"all") || argv.iter().any_(|x| x == &name)
}
if !run_test {
@ -87,9 +87,8 @@ fn vec_plus() {
while i < 1500 {
let rv = vec::from_elem(r.gen_uint_range(0, i + 1), i);
if r.gen() {
v += rv;
}
else {
v.push_all_move(rv);
} else {
v = rv + v;
}
i += 1;

View file

@ -86,7 +86,7 @@ fn make_graph(N: uint, edges: ~[(node_id, node_id)]) -> graph {
HashSet::new()
};
for vec::each(edges) |e| {
for edges.iter().advance |e| {
match *e {
(i, j) => {
graph[i].insert(j);
@ -141,7 +141,7 @@ fn bfs(graph: graph, key: node_id) -> bfs_result {
while !q.is_empty() {
let t = q.pop_front();
do graph[t].each() |k| {
do graph[t].iter().advance |k| {
if marks[*k] == -1i64 {
marks[*k] = t;
q.add_back(*k);
@ -191,17 +191,17 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
// Do the BFS.
info!("PBFS iteration %?", i);
i += 1;
colors = do colors.mapi() |i, c| {
colors = do colors.iter().enumerate().transform |(i, c)| {
let c : color = *c;
match c {
white => {
let i = i as node_id;
let neighbors = copy graph[i];
let neighbors = &graph[i];
let mut color = white;
do neighbors.each() |k| {
do neighbors.iter().advance |k| {
if is_gray(&colors[*k]) {
color = gray(*k);
false
@ -214,17 +214,17 @@ fn bfs2(graph: graph, key: node_id) -> bfs_result {
gray(parent) => { black(parent) }
black(parent) => { black(parent) }
}
}
}.collect()
}
// Convert the results.
do vec::map(colors) |c| {
do colors.iter().transform |c| {
match *c {
white => { -1i64 }
black(parent) => { parent }
_ => { fail!("Found remaining gray nodes in BFS") }
}
}
}.collect()
}
/// A parallel version of the bfs function.
@ -286,7 +286,7 @@ fn pbfs(graph: &arc::ARC<graph>, key: node_id) -> bfs_result {
let mut color = white;
do neighbors.each() |k| {
do neighbors.iter().advance |k| {
if is_gray(&colors[*k]) {
color = gray(*k);
false
@ -341,7 +341,7 @@ fn validate(edges: ~[(node_id, node_id)],
}
else {
while parent != root {
if vec::contains(path, &parent) {
if path.contains(&parent) {
status = false;
}
@ -378,7 +378,7 @@ fn validate(edges: ~[(node_id, node_id)],
info!(~"Verifying graph edges...");
let status = do edges.all() |e| {
let status = do edges.iter().all |e| {
let (u, v) = *e;
abs(level[u] - level[v]) <= 1
@ -402,7 +402,7 @@ fn validate(edges: ~[(node_id, node_id)],
if *v == -1i64 || u == root {
true
} else {
edges.contains(&(u, *v)) || edges.contains(&(*v, u))
edges.iter().any_(|x| x == &(u, *v)) || edges.iter().any_(|x| x == &(*v, u))
}
};
result
@ -441,7 +441,7 @@ fn main() {
let stop = time::precise_time_s();
let mut total_edges = 0;
vec::each(graph, |edges| { total_edges += edges.len(); true });
for graph.iter().advance |edges| { total_edges += edges.len(); }
io::stdout().write_line(fmt!("Generated graph with %? edges in %? seconds.",
total_edges / 2,

View file

@ -83,7 +83,7 @@ fn run(args: &[~str]) {
server(&from_parent, &to_parent);
}
for vec::each(worker_results) |r| {
for worker_results.iter().advance |r| {
r.recv();
}

View file

@ -79,7 +79,7 @@ fn run(args: &[~str]) {
server(&from_parent, &to_parent);
}
for vec::each(worker_results) |r| {
for worker_results.iter().advance |r| {
r.recv();
}

View file

@ -118,10 +118,10 @@ fn main() {
};
};
/*for int::range(0, 256) |y| {
for int::range(0, 256) |y| {
for int::range(0, 256) |x| {
io::print(symbols[pixels[y*256+x] / 0.2f32 as int]);
print(symbols[pixels[y*256+x] / 0.2f32 as int]);
}
io::println("");
}*/
println("");
}
}

View file

@ -82,7 +82,7 @@ endpoint. The send endpoint is returned to the caller and the receive
endpoint is passed to the new task.
*/
pub fn spawn_service<T:Owned,Tb:Owned>(
pub fn spawn_service<T:Send,Tb:Send>(
init: extern fn() -> (RecvPacketBuffered<T, Tb>,
SendPacketBuffered<T, Tb>),
service: ~fn(v: RecvPacketBuffered<T, Tb>))
@ -103,7 +103,7 @@ pub fn spawn_service<T:Owned,Tb:Owned>(
receive state.
*/
pub fn spawn_service_recv<T:Owned,Tb:Owned>(
pub fn spawn_service_recv<T:Send,Tb:Send>(
init: extern fn() -> (SendPacketBuffered<T, Tb>,
RecvPacketBuffered<T, Tb>),
service: ~fn(v: SendPacketBuffered<T, Tb>))
@ -120,7 +120,7 @@ pub fn spawn_service_recv<T:Owned,Tb:Owned>(
client
}
fn switch<T:Owned,Tb:Owned,U>(endp: std::pipes::RecvPacketBuffered<T, Tb>,
fn switch<T:Send,Tb:Send,U>(endp: std::pipes::RecvPacketBuffered<T, Tb>,
f: &fn(v: Option<T>) -> U)
-> U {
f(std::pipes::try_recv(endp))

View file

@ -1,8 +1,4 @@
// xfail-test
// Broken due to arena API problems.
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// 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.
//
@ -15,33 +11,35 @@
extern mod extra;
use extra::arena;
enum tree<'self> {
nil,
node(&'self tree<'self>, &'self tree<'self>, int),
enum Tree<'self> {
Nil,
Node(&'self Tree<'self>, &'self Tree<'self>, int),
}
fn item_check(t: &tree) -> int {
fn item_check(t: &Tree) -> int {
match *t {
nil => { return 0; }
node(left, right, item) => {
Nil => { return 0; }
Node(left, right, item) => {
return item + item_check(left) - item_check(right);
}
}
}
fn bottom_up_tree<'r>(arena: &'r mut arena::Arena, item: int, depth: int)
-> &'r tree<'r> {
fn bottom_up_tree<'r>(arena: &'r arena::Arena, item: int, depth: int)
-> &'r Tree<'r> {
if depth > 0 {
return arena.alloc(
|| node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
|| Node(bottom_up_tree(arena, 2 * item - 1, depth - 1),
bottom_up_tree(arena, 2 * item, depth - 1),
item));
}
return arena.alloc(|| nil);
return arena.alloc(|| Nil);
}
fn main() {
let args = os::args();
use std::os;
use std::int;
let args = std::os::args();
let args = if os::getenv(~"RUST_BENCH").is_some() {
~[~"", ~"17"]
} else if args.len() <= 1u {
@ -59,34 +57,34 @@ fn main() {
max_depth = n;
}
let mut stretch_arena = arena::Arena();
let stretch_arena = arena::Arena();
let stretch_depth = max_depth + 1;
let stretch_tree = bottom_up_tree(&mut stretch_arena, 0, stretch_depth);
let stretch_tree = bottom_up_tree(&stretch_arena, 0, stretch_depth);
io::println(fmt!("stretch tree of depth %d\t check: %d",
println(fmt!("stretch tree of depth %d\t check: %d",
stretch_depth,
item_check(stretch_tree)));
let mut long_lived_arena = arena::Arena();
let long_lived_tree = bottom_up_tree(&mut long_lived_arena, 0, max_depth);
let long_lived_arena = arena::Arena();
let long_lived_tree = bottom_up_tree(&long_lived_arena, 0, max_depth);
let mut depth = min_depth;
while depth <= max_depth {
let iterations = int::pow(2, (max_depth - depth + min_depth) as uint);
let mut chk = 0;
let mut i = 1;
while i <= iterations {
let mut temp_tree = bottom_up_tree(&mut long_lived_arena, i, depth);
let mut temp_tree = bottom_up_tree(&long_lived_arena, i, depth);
chk += item_check(temp_tree);
temp_tree = bottom_up_tree(&mut long_lived_arena, -i, depth);
temp_tree = bottom_up_tree(&long_lived_arena, -i, depth);
chk += item_check(temp_tree);
i += 1;
}
io::println(fmt!("%d\t trees of depth %d\t check: %d",
println(fmt!("%d\t trees of depth %d\t check: %d",
iterations * 2, depth,
chk));
depth += 2;
}
io::println(fmt!("long lived trees of depth %d\t check: %d",
println(fmt!("long lived tree of depth %d\t check: %d",
max_depth,
item_check(long_lived_tree)));
}

View file

@ -23,11 +23,11 @@ use std::uint;
use std::vec;
fn print_complements() {
let all = ~[Blue, Red, Yellow];
for vec::each(all) |aa| {
for vec::each(all) |bb| {
io::println(show_color(*aa) + " + " + show_color(*bb) +
" -> " + show_color(transform(*aa, *bb)));
let all = [Blue, Red, Yellow];
for all.iter().advance |aa| {
for all.iter().advance |bb| {
println(show_color(*aa) + " + " + show_color(*bb) +
" -> " + show_color(transform(*aa, *bb)));
}
}
}
@ -49,9 +49,9 @@ fn show_color(cc: color) -> ~str {
fn show_color_list(set: ~[color]) -> ~str {
let mut out = ~"";
for vec::eachi(set) |_ii, col| {
out += " ";
out += show_color(*col);
for set.iter().advance |col| {
out.push_char(' ');
out.push_str(show_color(*col));
}
return out;
}
@ -85,7 +85,7 @@ fn show_number(nn: uint) -> ~str {
out = show_digit(dig) + " " + out;
}
return out;
return ~" " + out;
}
fn transform(aa: color, bb: color) -> color {
@ -152,7 +152,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
// these channels will allow us to talk to each creature by 'name'/index
let to_creature: ~[Chan<Option<CreatureInfo>>] =
vec::mapi(set, |ii, col| {
set.iter().enumerate().transform(|(ii, col)| {
// create each creature as a listener with a port, and
// give us a channel to talk to each
let ii = ii;
@ -166,7 +166,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
to_rendezvous_log.clone());
}
to_creature
});
}).collect();
let mut creatures_met = 0;
@ -182,13 +182,13 @@ fn rendezvous(nn: uint, set: ~[color]) {
}
// tell each creature to stop
for vec::eachi(to_creature) |_ii, to_one| {
for to_creature.iter().advance |to_one| {
to_one.send(None);
}
// save each creature's meeting stats
let mut report = ~[];
for vec::each(to_creature) |_to_one| {
for to_creature.iter().advance |_to_one| {
report.push(from_creatures_log.recv());
}
@ -196,7 +196,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
io::println(show_color_list(set));
// print each creature's stats
for vec::each(report) |rep| {
for report.iter().advance |rep| {
io::println(*rep);
}

View file

@ -59,7 +59,7 @@ static HOMO_SAPIENS: [AminoAcid, ..4] = [
fn sum_and_scale(a: &'static [AminoAcid]) -> ~[AminoAcid] {
let mut result = ~[];
let mut p = 0f32;
for a.each |a_i| {
for a.iter().advance |a_i| {
let mut a_i = *a_i;
p += a_i.p;
a_i.p = p * LOOKUP_SCALE;
@ -96,7 +96,7 @@ impl RepeatFasta {
copy_memory(buf, alu, alu_len);
let buf_len = buf.len();
copy_memory(vec::mut_slice(buf, alu_len, buf_len),
copy_memory(buf.mut_slice(alu_len, buf_len),
alu,
LINE_LEN);
@ -151,7 +151,7 @@ impl RandomFasta {
fn nextc(&mut self) -> u8 {
let r = self.rng(1.0);
for self.lookup.each |a| {
for self.lookup.iter().advance |a| {
if a.p >= r {
return a.c;
}

View file

@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// 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.
//
@ -19,16 +19,14 @@ extern mod extra;
use std::int;
use std::io;
use std::option;
use std::os;
use std::rand::Rng;
use std::rand;
use std::result;
use std::str;
use std::uint;
use std::vec;
fn LINE_LENGTH() -> uint { return 60u; }
static LINE_LENGTH: uint = 60u;
struct MyRandom {
last: u32
@ -47,11 +45,11 @@ struct AminoAcids {
fn make_cumulative(aa: ~[AminoAcids]) -> ~[AminoAcids] {
let mut cp: u32 = 0u32;
let mut ans: ~[AminoAcids] = ~[];
for aa.each |a| {
for aa.iter().advance |a| {
cp += a.prob;
ans += [AminoAcids {ch: a.ch, prob: cp}];
ans.push(AminoAcids {ch: a.ch, prob: cp});
}
return ans;
ans
}
fn select_random(r: u32, genelist: ~[AminoAcids]) -> char {
@ -64,7 +62,7 @@ fn select_random(r: u32, genelist: ~[AminoAcids]) -> char {
} else { return bisect(v, mid, hi, target); }
} else { return v[hi].ch; }
}
return bisect(copy genelist, 0, genelist.len() - 1, r);
bisect(copy genelist, 0, genelist.len() - 1, r)
}
fn make_random_fasta(wr: @io::Writer,
@ -81,7 +79,7 @@ fn make_random_fasta(wr: @io::Writer,
for uint::range(0u, n as uint) |_i| {
op.push_char(select_random(myrandom_next(rng, 100u32),
copy genelist));
if op.len() >= LINE_LENGTH() {
if op.len() >= LINE_LENGTH {
wr.write_line(op);
op = ~"";
}
@ -90,28 +88,28 @@ fn make_random_fasta(wr: @io::Writer,
}
fn make_repeat_fasta(wr: @io::Writer, id: ~str, desc: ~str, s: ~str, n: int) {
unsafe {
wr.write_line(~">" + id + " " + desc);
let mut op: ~str = ~"";
let sl: uint = s.len();
for uint::range(0u, n as uint) |i| {
str::raw::push_byte(&mut op, s[i % sl]);
if op.len() >= LINE_LENGTH() {
wr.write_line(op);
op = ~"";
}
wr.write_line(~">" + id + " " + desc);
let mut op = str::with_capacity( LINE_LENGTH );
let sl = s.len();
for uint::range(0u, n as uint) |i| {
if (op.len() >= LINE_LENGTH) {
wr.write_line( op );
op = str::with_capacity( LINE_LENGTH );
}
if op.len() > 0u { wr.write_line(op); }
op.push_char( s[i % sl] as char );
}
if op.len() > 0 {
wr.write_line(op)
}
}
fn acid(ch: char, prob: u32) -> AminoAcids {
return AminoAcids {ch: ch, prob: prob};
AminoAcids {ch: ch, prob: prob}
}
fn main() {
let args = os::args();
let args = if os::getenv(~"RUST_BENCH").is_some() {
let args = if os::getenv("RUST_BENCH").is_some() {
// alioth tests k-nucleotide with this data at 25,000,000
~[~"", ~"5000000"]
} else if args.len() <= 1u {
@ -120,9 +118,9 @@ fn main() {
args
};
let writer = if os::getenv(~"RUST_BENCH").is_some() {
let writer = if os::getenv("RUST_BENCH").is_some() {
result::get(&io::file_writer(&Path("./shootout-fasta.data"),
~[io::Truncate, io::Create]))
[io::Truncate, io::Create]))
} else {
io::stdout()
};

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// xfail-pretty (extra blank line is inserted in vec::mapi call)
// xfail-pretty the `let to_child` line gets an extra newline
// multi tasking k-nucleotide
extern mod extra;
@ -56,7 +56,7 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
let mut pairs = ~[];
// map -> [(k,%)]
for mm.each |&key, &val| {
for mm.iter().advance |(&key, &val)| {
pairs.push((key, pct(val, total)));
}
@ -64,13 +64,13 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str {
let mut buffer = ~"";
for pairs_sorted.each |kv| {
for pairs_sorted.iter().advance |kv| {
let (k,v) = copy *kv;
unsafe {
let b = str::raw::from_bytes(k);
// FIXME: #4318 Instead of to_ascii and to_str_ascii, could use
// to_ascii_consume and to_str_consume to not do a unnecessary copy.
buffer += (fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v));
buffer.push_str(fmt!("%s %0.3f\n", b.to_ascii().to_upper().to_str_ascii(), v));
}
}
@ -90,7 +90,7 @@ fn find(mm: &HashMap<~[u8], uint>, key: ~str) -> uint {
// given a map, increment the counter for a key
fn update_freq(mm: &mut HashMap<~[u8], uint>, key: &[u8]) {
let key = vec::slice(key, 0, key.len()).to_vec();
let key = key.to_owned();
let newval = match mm.pop(&key) {
Some(v) => v + 1,
None => 1
@ -107,11 +107,11 @@ fn windows_with_carry(bb: &[u8], nn: uint,
let len = bb.len();
while ii < len - (nn - 1u) {
it(vec::slice(bb, ii, ii+nn));
it(bb.slice(ii, ii+nn));
ii += 1u;
}
return vec::slice(bb, len - (nn - 1u), len).to_vec();
return bb.slice(len - (nn - 1u), len).to_owned();
}
fn make_sequence_processor(sz: uint,
@ -163,14 +163,13 @@ fn main() {
// initialize each sequence sorter
let sizes = ~[1,2,3,4,6,12,18];
let streams = vec::map(sizes, |_sz| Some(stream()));
let mut streams = streams;
// initialize each sequence sorter
let sizes = ~[1u,2,3,4,6,12,18];
let mut streams = vec::from_fn(sizes.len(), |_| Some(stream::<~str>()));
let mut from_child = ~[];
let to_child = vec::mapi(sizes, |ii, sz| {
let to_child = do sizes.iter().zip(streams.mut_iter()).transform |(sz, stream_ref)| {
let sz = *sz;
let stream = util::replace(&mut streams[ii], None);
let stream = util::replace(stream_ref, None);
let (from_child_, to_parent_) = stream.unwrap();
from_child.push(from_child_);
@ -182,7 +181,7 @@ fn main() {
};
to_child
});
}.collect::<~[Chan<~[u8]>]>();
// latch stores true after we've started
@ -211,7 +210,7 @@ fn main() {
(_, true) => {
let line_bytes = line.as_bytes();
for sizes.eachi |ii, _sz| {
for sizes.iter().enumerate().advance |(ii, _sz)| {
let mut lb = line_bytes.to_owned();
to_child[ii].send(lb);
}
@ -223,12 +222,12 @@ fn main() {
}
// finish...
for sizes.eachi |ii, _sz| {
for sizes.iter().enumerate().advance |(ii, _sz)| {
to_child[ii].send(~[]);
}
// now fetch and print result messages
for sizes.eachi |ii, _sz| {
for sizes.iter().enumerate().advance |(ii, _sz)| {
io::println(from_child[ii].recv());
}
}

View file

@ -8,7 +8,7 @@ use std::libc::{STDIN_FILENO, c_int, fdopen, fgets, fileno, fopen, fstat};
use std::libc::{stat, strlen};
use std::ptr::null;
use std::unstable::intrinsics::init;
use std::vec::{reverse, slice};
use std::vec::{reverse};
use extra::sort::quick_sort3;
static LINE_LEN: uint = 80;
@ -194,7 +194,7 @@ fn unpack_symbol(c: u8) -> u8 {
fn next_char<'a>(mut buf: &'a [u8]) -> &'a [u8] {
loop {
buf = slice(buf, 1, buf.len());
buf = buf.slice(1, buf.len());
if buf.len() == 0 {
break;
}
@ -226,7 +226,7 @@ fn read_stdin() -> ~[u8] {
fgets(transmute(&mut window[0]), LINE_LEN as c_int, stdin);
{
if vec::slice(window, 0, 6) == header {
if window.slice(0, 6) == header {
break;
}
}
@ -235,9 +235,7 @@ fn read_stdin() -> ~[u8] {
while fgets(transmute(&mut window[0]),
LINE_LEN as c_int,
stdin) != null() {
window = vec::mut_slice(window,
strlen(transmute(&window[0])) as uint,
window.len());
window = window.mut_slice(strlen(transmute(&window[0])) as uint, window.len());
}
}

View file

@ -23,7 +23,10 @@ fn main() {
for range(0, h) |y| {
let y = y as f64;
for range(0, w) |x| {
let mut (Zr, Zi, Tr, Ti) = (0f64, 0f64, 0f64, 0f64);
let mut Zr = 0f64;
let mut Zi = 0f64;
let mut Tr = 0f64;
let mut Ti = 0f64;
let Cr = 2.0 * (x as f64) / (w as f64) - 1.5;
let Ci = 2.0 * (y as f64) / (h as f64) - 1.0;

View file

@ -32,7 +32,6 @@ use std::str;
use std::task;
use std::u64;
use std::uint;
use std::vec;
fn fib(n: int) -> int {
fn pfib(c: &Chan<int>, n: int) {
@ -62,7 +61,7 @@ struct Config {
fn parse_opts(argv: ~[~str]) -> Config {
let opts = ~[getopts::optflag(~"stress")];
let opt_args = vec::slice(argv, 1, argv.len());
let opt_args = argv.slice(1, argv.len());
match getopts::getopts(opt_args, opts) {
Ok(ref m) => {
@ -91,7 +90,7 @@ fn stress(num_tasks: int) {
stress_task(i);
}
}
for results.each |r| {
for results.iter().advance |r| {
r.recv();
}
}

View file

@ -5,7 +5,6 @@ use std::cast::transmute;
use std::libc::{STDOUT_FILENO, c_int, fdopen, fgets, fopen, fputc, fwrite};
use std::libc::{size_t};
use std::ptr::null;
use std::vec::{capacity, reserve, reserve_at_least};
use std::vec::raw::set_len;
static LINE_LEN: u32 = 80;
@ -103,13 +102,13 @@ fn main() {
let stdout = fdopen(STDOUT_FILENO as c_int, transmute(&mode[0]));
let mut out: ~[u8] = ~[];
reserve(&mut out, 12777888);
out.reserve(12777888);
let mut pos = 0;
loop {
let needed = pos + (LINE_LEN as uint) + 1;
if capacity(&out) < needed {
reserve_at_least(&mut out, needed);
if out.capacity() < needed {
out.reserve_at_least(needed);
}
let mut ptr = out.unsafe_mut_ref(pos);

View file

@ -1,3 +1,13 @@
// 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.
use std::f64;
use std::from_str::FromStr;
use std::os;
@ -10,7 +20,7 @@ fn A(i: i32, j: i32) -> i32 {
fn dot(v: &[f64], u: &[f64]) -> f64 {
let mut sum = 0.0;
for v.eachi |i, &v_i| {
for v.iter().enumerate().advance |(i, &v_i)| {
sum += v_i * u[i];
}
sum

View file

@ -10,18 +10,20 @@
// Based on threadring.erlang by Jira Isa
// xfail-test FIXME #5985 OOM's on the mac bot
use std::os;
fn start(n_tasks: int, token: int) {
let mut (p, ch1) = comm::stream();
let (p, ch1) = stream();
let mut p = p;
let mut ch1 = ch1;
ch1.send(token);
// XXX could not get this to work with a range closure
let mut i = 2;
while i <= n_tasks {
let (next_p, ch) = comm::stream();
let (next_p, ch) = stream();
let imm_i = i;
let imm_p = p;
do task::spawn {
do spawn {
roundtrip(imm_i, n_tasks, &imm_p, &ch);
};
p = next_p;
@ -29,16 +31,16 @@ fn start(n_tasks: int, token: int) {
}
let imm_p = p;
let imm_ch = ch1;
do task::spawn {
do spawn {
roundtrip(1, n_tasks, &imm_p, &imm_ch);
}
}
fn roundtrip(id: int, n_tasks: int, p: &comm::Port<int>, ch: &comm::Chan<int>) {
fn roundtrip(id: int, n_tasks: int, p: &Port<int>, ch: &Chan<int>) {
while (true) {
match p.recv() {
1 => {
io::println(fmt!("%d\n", id));
println(fmt!("%d\n", id));
return;
}
token => {
@ -60,13 +62,13 @@ fn main() {
os::args()
};
let token = if args.len() > 1u {
int::from_str(args[1]).get()
FromStr::from_str(args[1]).get()
}
else {
1000
};
let n_tasks = if args.len() > 2u {
int::from_str(args[2]).get()
FromStr::from_str(args[2]).get()
}
else {
503

View file

@ -103,7 +103,9 @@ impl Sudoku {
for u8::range(0u8, 9u8) |row| {
for u8::range(0u8, 9u8) |col| {
let color = self.grid[row][col];
if color == 0u8 { work += [(row, col)]; }
if color == 0u8 {
work.push((row, col));
}
}
}

View file

@ -60,7 +60,7 @@ struct r {
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {}
fn drop(&self) {}
}
fn r(l: @nillist) -> r {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: reference is not valid outside of its lifetime
// error-pattern: lifetime of return value does not outlive the function call
extern mod extra;
use extra::arc;
fn main() {

View file

@ -8,14 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: reference is not valid outside of its lifetime
extern mod extra;
use extra::arc;
fn main() {
let x = ~arc::RWARC(1);
let mut y = None;
let mut y = None; //~ ERROR lifetime of variable does not enclose its declaration
do x.write |one| {
y = Some(one);
}
*y.unwrap() = 2;
//~^ ERROR lifetime of return value does not outlive the function call
//~^^ ERROR dereference of reference outside its lifetime
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: reference is not valid outside of its lifetime
// error-pattern: lifetime of variable does not enclose its declaration
extern mod extra;
use extra::arc;
fn main() {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: reference is not valid outside of its lifetime
// error-pattern: lifetime of variable does not enclose its declaration
extern mod extra;
use extra::arc;
fn main() {

View file

@ -11,7 +11,7 @@
struct X { x: () }
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("destructor runs");
}
}

View file

@ -11,7 +11,7 @@
struct X { x: (), }
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("destructor runs");
}
}

View file

@ -11,7 +11,7 @@
struct X { x: (), }
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("destructor runs");
}
}

View file

@ -11,7 +11,7 @@
struct X { x: (), }
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("destructor runs");
}
}

View file

@ -13,7 +13,7 @@
struct X { x: (), }
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("destructor runs");
}
}

View file

@ -13,7 +13,7 @@
struct X { x: (), }
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("destructor runs");
}
}

View file

@ -11,7 +11,7 @@
struct X { x: (), }
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("destructor runs");
}
}

View file

@ -8,10 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::vec;
fn main() {
for vec::each(~[0]) |_i| { //~ ERROR A for-loop body must return (), but
for 2.times { //~ ERROR A for-loop body must return (), but
true
}
}

View file

@ -13,7 +13,7 @@
struct r;
impl Drop for r {
fn finalize(&self) {
fn drop(&self) {
true
}
}

View file

@ -14,7 +14,7 @@ struct defer<'self> {
#[unsafe_destructor]
impl<'self> Drop for defer<'self> {
fn finalize(&self) {
fn drop(&self) {
unsafe {
error!("%?", self.x);
}

View file

@ -16,7 +16,7 @@ struct Foo {
impl Foo {
pub fn foo(&mut self, fun: &fn(&int)) {
for self.n.each |f| {
for self.n.iter().advance |f| {
fun(f);
}
}

View file

@ -1,6 +1,4 @@
extern mod extra;
fn main() {
pub fn main() {
let foo = ~3;
let _pfoo = &foo;
let _f: @fn() -> int = || *foo + 5;

View file

@ -10,7 +10,7 @@
fn main() {
let v = @mut [ 1, 2, 3 ];
for v.each |_x| {
for v.iter().advance |_x| {
v[1] = 4; //~ ERROR cannot assign
}
}

View file

@ -58,5 +58,5 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
fn main() {
let nyan : @noisy = @cat(0, 2, ~"nyan") as @noisy;
nyan.eat(); //~ ERROR type `@noisy` does not implement any method in scope named `eat`
nyan.eat(); //~ ERROR does not implement any method in scope named `eat`
}

View file

@ -0,0 +1,20 @@
// 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.
struct X {
field: @fn:Copy(),
}
fn foo(blk: @fn:()) -> X {
return X { field: blk }; //~ ERROR expected bounds `Copy` but found no bounds
}
fn main() {
}

View file

@ -0,0 +1,26 @@
// 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.
use std::comm;
// If this were legal you could use it to copy captured noncopyables.
// Issue (#2828)
fn foo(blk: ~fn:Copy()) {
blk();
}
fn main() {
let (p,c) = comm::stream();
do foo {
c.send(()); //~ ERROR does not fulfill `Copy`
}
p.recv();
}

View file

@ -0,0 +1,21 @@
// 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.
fn bar(blk: &fn:'static()) {
}
fn foo(x: &()) {
do bar {
let _ = x; //~ ERROR does not fulfill `'static`
}
}
fn main() {
}

View file

@ -1,34 +1,39 @@
fn take_any(_: &fn()) {
fn take_any(_: &fn:()) {
}
fn take_copyable(_: &fn:Copy()) {
}
fn take_copyable_owned(_: &fn:Copy+Owned()) {
fn take_copyable_owned(_: &fn:Copy+Send()) {
}
fn give_any(f: &fn()) {
fn take_const_owned(_: &fn:Freeze+Send()) {
}
fn give_any(f: &fn:()) {
take_any(f);
take_copyable(f); //~ ERROR expected bounds `Copy` but found no bounds
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Owned` but found no bounds
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found no bounds
}
fn give_copyable(f: &fn:Copy()) {
take_any(f);
take_copyable(f);
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Owned` but found bounds `Copy`
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found bounds `Copy`
}
fn give_owned(f: &fn:Owned()) {
fn give_owned(f: &fn:Send()) {
take_any(f);
take_copyable(f); //~ ERROR expected bounds `Copy` but found bounds `Owned`
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Owned` but found bounds `Owned`
take_copyable(f); //~ ERROR expected bounds `Copy` but found bounds `Send`
take_copyable_owned(f); //~ ERROR expected bounds `Copy+Send` but found bounds `Send`
}
fn give_copyable_owned(f: &fn:Copy+Owned()) {
fn give_copyable_owned(f: &fn:Copy+Send()) {
take_any(f);
take_copyable(f);
take_copyable_owned(f);
take_const_owned(f); //~ ERROR expected bounds `Send+Freeze` but found bounds `Copy+Send`
}
fn main() {}
fn main() {}

View file

@ -13,7 +13,7 @@ struct foo {
}
impl Drop for foo {
fn finalize(&self) {}
fn drop(&self) {}
}
fn foo(i:int) -> foo {

View file

@ -14,7 +14,7 @@ struct X {
}
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("value: %s", self.x);
}
}

View file

@ -13,7 +13,7 @@ struct X {
}
impl Drop for X {
fn finalize(&self) {
fn drop(&self) {
error!("value: %s", self.x);
}
}

View file

@ -12,7 +12,7 @@ type Foo = @[u8];
impl Drop for Foo { //~ ERROR the Drop trait may only be implemented
//~^ ERROR cannot provide an extension implementation
fn finalize(&self) {
fn drop(&self) {
println("kaboom");
}
}

View file

@ -8,18 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct Node<'self, T> {
val: T,
next: Option<&'self Node<'self, T>>
}
enum Foo { C { a: int, b: int } }
struct C { a: int, b: int } //~ ERROR error: duplicate definition of type `C`
impl<'self, T> Node<'self, T> {
fn get(&self) -> &'self T {
match self.next {
Some(ref next) => next.get(),
None => &self.val
}
}
}
struct A { x: int }
enum Bar { A { x: int } } //~ ERROR error: duplicate definition of type `A`
fn main() {}

View file

@ -13,12 +13,12 @@ struct Foo {
}
impl Drop for Foo {
fn finalize(&self) {
fn drop(&self) {
println("kaboom");
}
}
fn main() {
let x = Foo { x: 3 };
x.finalize(); //~ ERROR explicit call to destructor
x.drop(); //~ ERROR explicit call to destructor
}

View file

@ -17,14 +17,14 @@ trait Bar : Drop {
}
impl Drop for Foo {
fn finalize(&self) {
fn drop(&self) {
println("kaboom");
}
}
impl Bar for Foo {
fn blah(&self) {
self.finalize(); //~ ERROR explicit call to destructor
self.drop(); //~ ERROR explicit call to destructor
}
}

View file

@ -13,5 +13,5 @@ extern fn f() {
fn main() {
// extern functions are *u8 types
let _x: &fn() = f; //~ ERROR mismatched types: expected `&fn()` but found `*u8`
let _x: &fn() = f; //~ ERROR found `*u8`
}

View file

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:mismatched types
fn main() { let x = if true { 10i } else { 10u }; }
fn main() {
let x = if true { 10i } else { 10u };
//~^ ERROR if and else have incompatible types: expected `int` but found `uint`
}

View file

@ -0,0 +1,24 @@
// 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.
pub trait Clone2 {
fn clone(&self) -> Self;
}
trait Getter<T: Clone2> {
fn get(&self) -> T;
}
impl Getter<int> for int { //~ ERROR failed to find an implementation of trait Clone2 for int
fn get(&self) -> int { *self }
}
fn main() { }

View file

@ -11,7 +11,7 @@
struct Foo;
impl Foo {
fn orange(&self){}
fn orange(&self){} //~ ERROR error: duplicate definition of method `orange`
fn orange(&self){} //~ ERROR error: duplicate definition of value `orange`
}
fn main() {}

View file

@ -15,7 +15,7 @@ trait vec_monad<A> {
impl<A> vec_monad<A> for ~[A] {
fn bind<B>(&self, f: &fn(A) -> ~[B]) {
let mut r = fail!();
for self.each |elt| { r += f(*elt); }
for self.iter().advance |elt| { r = r + f(*elt); }
//~^ WARNING unreachable expression
//~^^ ERROR the type of this value must be known
}

View file

@ -14,7 +14,7 @@
fn fail_len(v: ~[int]) -> uint {
let mut i = 3;
fail!();
for v.each |x| { i += 1u; }
for v.iter().advance |x| { i += 1u; }
//~^ ERROR: unreachable statement
return i;
}

View file

@ -8,10 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::vec;
fn main() {
for vec::each(fail!()) |i| {
let _ = i * 2; //~ ERROR the type of this value must be known
};
let x = fail!();
x.clone(); //~ ERROR the type of this value must be known in this context
}

View file

@ -18,7 +18,7 @@ struct foo {
#[unsafe_destructor]
impl Drop for foo {
fn finalize(&self) {
fn drop(&self) {
unsafe {
println("Goodbye, World!");
*self.x += 1;

View file

@ -20,7 +20,7 @@ struct E {
}
impl A for E {
fn b<F:Copy + Const,G>(_x: F) -> F { fail!() } //~ ERROR type parameter 0 requires `Const`
fn b<F:Copy + Freeze,G>(_x: F) -> F { fail!() } //~ ERROR type parameter 0 requires `Freeze`
}
fn main() {}

View file

@ -9,12 +9,12 @@
// except according to those terms.
pub mod stream {
pub enum Stream<T:Owned> { send(T, ::stream::server::Stream<T>), }
pub enum Stream<T:Send> { send(T, ::stream::server::Stream<T>), }
pub mod server {
use std::option;
use std::pipes;
impl<T:Owned> Stream<T> {
impl<T:Send> Stream<T> {
pub fn recv() -> extern fn(v: Stream<T>) -> ::stream::Stream<T> {
// resolve really should report just one error here.
// Change the test case when it changes.
@ -28,7 +28,7 @@ pub mod stream {
}
}
pub type Stream<T:Owned> = pipes::RecvPacket<::stream::Stream<T>>;
pub type Stream<T:Send> = pipes::RecvPacket<::stream::Stream<T>>;
}
}

View file

@ -13,7 +13,7 @@ struct C {
}
impl Drop for C {
fn finalize(&self) {
fn drop(&self) {
error!("dropping: %?", self.x);
}
}

View file

@ -10,6 +10,6 @@
pub mod a {}
pub mod a {} //~ ERROR duplicate definition of type `a`
pub mod a {} //~ ERROR duplicate definition of module `a`
fn main() {}

View file

@ -10,7 +10,7 @@
// xfail-test
// error-pattern: instantiating a type parameter with an incompatible type
struct S<T:Const> {
struct S<T:Freeze> {
s: T,
cant_nest: ()
}

View file

@ -15,7 +15,7 @@ fn foo<T>() {
}
impl<T> Drop for foo<T> {
fn finalize(&self) {}
fn drop(&self) {}
}
}
fn main() { }

View file

@ -10,7 +10,7 @@
fn foopy() {}
static f: &'static fn() = foopy; //~ ERROR mismatched types: expected `&'static fn()`
static f: &'static fn() = foopy; //~ ERROR found extern fn
fn main () {
f();

View file

@ -16,8 +16,8 @@ pub enum TraitWrapper {
fn get_tw_map<'lt>(tw: &'lt TraitWrapper) -> &'lt MyTrait {
match *tw {
A(~ref map) => map, //~ ERROR mismatched types: expected `~MyTrait` but found a ~-box pattern
A(~ref map) => map, //~ ERROR found a ~-box pattern
}
}
pub fn main() {}
pub fn main() {}

View file

@ -0,0 +1,29 @@
// 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.
use std::io;
macro_rules! print_hd_tl (
($field_hd:ident, $($field_tl:ident),+) => ({
io::print(stringify!($field)); //~ ERROR unknown macro variable
io::print("::[");
$(
io::print(stringify!($field_tl));
io::print(", ");
)+
io::print("]\n");
})
)
fn main() {
print_hd_tl!(x, y, z, w)
}

View file

@ -37,7 +37,7 @@ fn main() {
('c', 'd'),
('e', 'f')];
for v.each |&(x,y)| {} // should be OK
for v.iter().advance |&(x,y)| {} // should be OK
// Make sure none of the errors above were fatal
let x: char = true; //~ ERROR expected `char` but found `bool`

View file

@ -2,8 +2,8 @@ struct Foo {
f: @mut int,
}
impl Drop for Foo { //~ ERROR cannot implement a destructor on a struct that is not Owned
fn finalize(&self) {
impl Drop for Foo { //~ ERROR cannot implement a destructor on a structure that does not satisfy Send
fn drop(&self) {
*self.f = 10;
}
}

View file

@ -12,7 +12,7 @@ fn foo(_x: @uint) {}
fn main() {
let x = @3u;
let _: ~fn() = || foo(x); //~ ERROR value has non-owned type `@uint`
let _: ~fn() = || foo(x); //~ ERROR value has non-owned type `@uint`
let _: ~fn() = || foo(x); //~ ERROR value has non-owned type `@uint`
let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send`
let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send`
let _: ~fn() = || foo(x); //~ ERROR does not fulfill `Send`
}

View file

@ -23,13 +23,13 @@ fn main() {
// Error results because the type of is inferred to be
// @repeat<&'blk int> where blk is the lifetime of the block below.
let y = { //~ ERROR reference is not valid
let y = { //~ ERROR lifetime of variable does not enclose its declaration
let x: &'blk int = &3;
repeater(@x)
};
assert!(3 == *(y.get())); //~ ERROR dereference of reference outside its lifetime
//~^ ERROR reference is not valid outside of its lifetime
//~^^ ERROR reference is not valid outside of its lifetime
//~^^^ ERROR reference is not valid outside of its lifetime
assert!(3 == *(y.get()));
//~^ ERROR dereference of reference outside its lifetime
//~^^ ERROR automatically borrowed pointer is not valid at the time of borrow
//~^^^ ERROR lifetime of return value does not outlive the function call
//~^^^^ ERROR cannot infer an appropriate lifetime
}

View file

@ -11,7 +11,9 @@
trait foo { fn foo(&self); }
fn to_foo<T:Copy + foo>(t: T) -> @foo {
@t as @foo //~ ERROR value may contain borrowed pointers; add `'static` bound
@t as @foo
//~^ ERROR value may contain borrowed pointers; add `'static` bound
//~^^ ERROR cannot pack type
}
fn to_foo2<T:Copy + foo + 'static>(t: T) -> @foo {

View file

@ -9,8 +9,7 @@
// except according to those terms.
fn copy1<T:Copy>(t: T) -> @fn() -> T {
let result: @fn() -> T = || copy t;
//~^ ERROR value may contain borrowed pointers
let result: @fn() -> T = || copy t; //~ ERROR does not fulfill `'static`
result
}
@ -30,6 +29,6 @@ fn main() {
copy2(boxed);
let owned: ~fn() = || {};
copy2(owned); //~ ERROR does not fulfill `Copy`
let borrowed: &fn() = || {};
let borrowed: &fn:Copy() = || {};
copy2(borrowed); //~ ERROR does not fulfill `'static`
}

View file

@ -0,0 +1,30 @@
// 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.
#[deny(warnings)];
fn main() {
while true {} //~ ERROR: infinite
}
#[allow(warnings)]
fn foo() {
while true {}
}
#[warn(warnings)]
fn bar() {
while true {} //~ WARNING: infinite
}
#[forbid(warnings)]
fn baz() {
while true {} //~ ERROR: warnings
}

View file

@ -30,7 +30,7 @@ use std::io::WriterUtil;
// Make sure this import is warned about when at least one of its imported names
// is unused
use std::vec::{filter, map}; //~ ERROR unused import
use std::vec::{filter, from_elem}; //~ ERROR unused import
mod foo {
pub struct Point{x: int, y: int}
@ -58,7 +58,5 @@ fn main() {
let a = 3;
ignore(a);
io::stdout().write_str("a");
let _a = do map([2]) |&x| {
x + 2
};
let _a = from_elem(0, 0);
}

View file

@ -12,7 +12,7 @@ use std::vec;
fn main() {
let a: ~[int] = ~[];
vec::each(a, |_| -> bool {
a.iter().advance(|_| -> bool {
//~^ ERROR mismatched types
});
}

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn send<T:Owned>(ch: _chan<T>, data: T) {
fn send<T:Send>(ch: _chan<T>, data: T) {
debug!(ch);
debug!(data);
fail!();

View file

@ -0,0 +1,52 @@
// 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.
// Test that we correctly consider the type of `match` to be the LUB
// of the various arms, particularly in the case where regions are
// involved.
pub fn opt_str0<'a>(maybestr: &'a Option<~str>) -> &'a str {
if maybestr.is_none() {
"(none)"
} else {
let s: &'a str = *maybestr.get_ref();
s
}
}
pub fn opt_str1<'a>(maybestr: &'a Option<~str>) -> &'a str {
if maybestr.is_some() {
let s: &'a str = *maybestr.get_ref();
s
} else {
"(none)"
}
}
pub fn opt_str2<'a>(maybestr: &'a Option<~str>) -> &'static str {
if maybestr.is_none() { //~ ERROR mismatched types
"(none)"
} else {
let s: &'a str = *maybestr.get_ref();
s
}
}
pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str {
if maybestr.is_some() { //~ ERROR mismatched types
let s: &'a str = *maybestr.get_ref();
s
} else {
"(none)"
}
}
fn main() {}

View file

@ -0,0 +1,55 @@
// 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.
// Test that we correctly consider the type of `match` to be the LUB
// of the various arms, particularly in the case where regions are
// involved.
pub fn opt_str0<'a>(maybestr: &'a Option<~str>) -> &'a str {
match *maybestr {
Some(ref s) => {
let s: &'a str = *s;
s
}
None => "(none)",
}
}
pub fn opt_str1<'a>(maybestr: &'a Option<~str>) -> &'a str {
match *maybestr {
None => "(none)",
Some(ref s) => {
let s: &'a str = *s;
s
}
}
}
pub fn opt_str2<'a>(maybestr: &'a Option<~str>) -> &'static str {
match *maybestr { //~ ERROR mismatched types
None => "(none)",
Some(ref s) => {
let s: &'a str = *s;
s
}
}
}
pub fn opt_str3<'a>(maybestr: &'a Option<~str>) -> &'static str {
match *maybestr { //~ ERROR mismatched types
Some(ref s) => {
let s: &'a str = *s;
s
}
None => "(none)",
}
}
fn main() {}

View file

@ -17,5 +17,5 @@ fn main() {
let x: @Map<~str, ~str> = @HashMap::new::<~str, ~str>() as
@Map<~str, ~str>;
let y: @Map<uint, ~str> = @x;
//~^ ERROR mismatched types: expected `@std::container::Map<uint,~str>`
//~^ ERROR expected trait std::container::Map but found @-ptr
}

View file

@ -13,7 +13,7 @@
fn foo(f: &fn()) { f() }
fn main() {
~"" || 42; //~ ERROR binary operation || cannot be applied to type `~str`
foo || {}; //~ ERROR binary operation || cannot be applied to type `extern "Rust" fn(&fn())`
~"" || 42; //~ ERROR binary operation || cannot be applied to type
foo || {}; //~ ERROR binary operation || cannot be applied to type
//~^ NOTE did you forget the `do` keyword for the call?
}

View file

@ -1,8 +1,6 @@
// Tests that references to move-by-default values trigger moves when
// they occur as part of various kinds of expressions.
use std::vec;
struct Foo<A> { f: A }
fn guard(_s: ~str) -> bool {fail!()}
fn touch<A>(_a: &A) {}
@ -92,7 +90,7 @@ fn f110() {
fn f120() {
let mut x = ~[~"hi", ~"ho"];
vec::swap(x, 0, 1);
x.swap(0, 1);
touch(&x[0]);
touch(&x[1]);
}

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[mutable]
#[no_freeze]
enum Foo { A }
fn bar<T: Const>(_: T) {}
fn bar<T: Freeze>(_: T) {}
fn main() {
let x = A;
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Const`
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Freeze`
}

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[mutable]
#[no_freeze]
struct Foo { a: int }
fn bar<T: Const>(_: T) {}
fn bar<T: Freeze>(_: T) {}
fn main() {
let x = Foo { a: 5 };
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Const`
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Freeze`
}

View file

@ -20,7 +20,7 @@ fn main() {
#[unsafe_destructor]
impl Drop for foo {
fn finalize(&self) {}
fn drop(&self) {}
}
fn foo(x: Port<()>) -> foo {
@ -32,7 +32,7 @@ fn main() {
let x = Cell::new(foo(Port(@())));
do task::spawn {
let y = x.take(); //~ ERROR value has non-owned type
let y = x.take(); //~ ERROR does not fulfill `Send`
error!(y);
}
}

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[non_owned]
#[no_send]
enum Foo { A }
fn bar<T: Owned>(_: T) {}
fn bar<T: Send>(_: T) {}
fn main() {
let x = A;
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Owned`
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Send`
}

View file

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[non_owned]
#[no_send]
struct Foo { a: int }
fn bar<T: Owned>(_: T) {}
fn bar<T: Send>(_: T) {}
fn main() {
let x = Foo { a: 5 };
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Owned`
bar(x); //~ ERROR instantiating a type parameter with an incompatible type `Foo`, which does not fulfill `Send`
}

View file

@ -15,7 +15,7 @@ struct bar {
}
impl Drop for bar {
fn finalize(&self) {}
fn drop(&self) {}
}
fn bar(x:int) -> bar {

View file

@ -0,0 +1,29 @@
// 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.
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.
extern mod extra;
use extra::arc;
use std::util;
fn foo(blk: ~once fn()) {
blk();
blk(); //~ ERROR use of moved value
}
fn main() {
let x = arc::ARC(true);
do foo {
assert!(*x.get());
util::ignore(x);
}
}

View file

@ -0,0 +1,30 @@
// 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.
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.
// compile-flags:-Z once-fns
extern mod extra;
use extra::arc;
use std::util;
fn foo(blk: &once fn()) {
blk();
blk(); //~ ERROR use of moved value
}
fn main() {
let x = arc::ARC(true);
do foo {
assert!(*x.get());
util::ignore(x);
}
}

View file

@ -0,0 +1,20 @@
// 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.
// Though it should be legal to copy a heap-allocated "once fn:Copy",
// stack closures are not deep-copied, so (counterintuitively) it should be
// illegal to copy them.
fn foo<'r>(blk: &'r once fn:Copy()) -> (&'r once fn:Copy(), &'r once fn:Copy()) {
(copy blk, blk) //~ ERROR copying a value of non-copyable type
}
fn main() {
}

View file

@ -0,0 +1,29 @@
// 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.
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.
extern mod extra;
use extra::arc;
use std::util;
fn foo(blk: ~fn()) {
blk();
blk();
}
fn main() {
let x = arc::ARC(true);
do foo {
assert!(*x.get());
util::ignore(x); //~ ERROR cannot move out of captured outer variable
}
}

View file

@ -0,0 +1,29 @@
// 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.
// Testing guarantees provided by once functions.
// This program would segfault if it were legal.
extern mod extra;
use extra::arc;
use std::util;
fn foo(blk: &fn()) {
blk();
blk();
}
fn main() {
let x = arc::ARC(true);
do foo {
assert!(*x.get());
util::ignore(x); //~ ERROR cannot move out of captured outer variable
}
}

View file

@ -14,7 +14,7 @@ struct r {
#[unsafe_destructor]
impl Drop for r {
fn finalize(&self) {
fn drop(&self) {
unsafe {
*(self.i) = *(self.i) + 1;
}

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