test: Remove pure from the test suite

This commit is contained in:
Patrick Walton 2013-03-22 11:23:21 -07:00
parent fbe22afdbe
commit 3eda11a4f7
62 changed files with 153 additions and 158 deletions

View File

@ -18,7 +18,7 @@ pub mod kitty {
} }
impl ToStr for cat { impl ToStr for cat {
pure fn to_str(&self) -> ~str { copy self.name } fn to_str(&self) -> ~str { copy self.name }
} }
priv impl cat { priv impl cat {

View File

@ -25,11 +25,11 @@ pub enum e {
pub fn nominal() -> e { e_val } pub fn nominal() -> e { e_val }
pub pure fn nominal_eq(e1: e, e2: e) -> bool { true } pub fn nominal_eq(e1: e, e2: e) -> bool { true }
impl Eq for e { impl Eq for e {
pure fn eq(&self, other: &e) -> bool { nominal_eq(*self, *other) } fn eq(&self, other: &e) -> bool { nominal_eq(*self, *other) }
pure fn ne(&self, other: &e) -> bool { !nominal_eq(*self, *other) } fn ne(&self, other: &e) -> bool { !nominal_eq(*self, *other) }
} }
pub fn f() -> int { 10 } pub fn f() -> int { 10 }

View File

@ -23,12 +23,12 @@ pub enum e {
} }
impl Eq for e { impl Eq for e {
pure fn eq(&self, other: &e) -> bool { !nominal_neq(*self, *other) } fn eq(&self, other: &e) -> bool { !nominal_neq(*self, *other) }
pure fn ne(&self, other: &e) -> bool { nominal_neq(*self, *other) } fn ne(&self, other: &e) -> bool { nominal_neq(*self, *other) }
} }
pub fn nominal() -> e { e_val } pub fn nominal() -> e { e_val }
pub pure fn nominal_neq(e1: e, e2: e) -> bool { false } pub fn nominal_neq(e1: e, e2: e) -> bool { false }
pub fn f() -> int { 20 } pub fn f() -> int { 20 }

View File

@ -7,8 +7,8 @@ pub struct Fish {
mod unexported { mod unexported {
use super::Fish; use super::Fish;
impl Eq for Fish { impl Eq for Fish {
pure fn eq(&self, _: &Fish) -> bool { true } fn eq(&self, _: &Fish) -> bool { true }
pure fn ne(&self, _: &Fish) -> bool { false } fn ne(&self, _: &Fish) -> bool { false }
} }
} }

View File

@ -1,11 +1,11 @@
pub mod num { pub mod num {
pub trait Num2 { pub trait Num2 {
pure fn from_int2(n: int) -> Self; fn from_int2(n: int) -> Self;
} }
} }
pub mod float { pub mod float {
impl ::num::Num2 for float { impl ::num::Num2 for float {
pure fn from_int2(n: int) -> float { return n as float; } fn from_int2(n: int) -> float { return n as float; }
} }
} }

View File

@ -18,24 +18,24 @@ pub struct MyInt {
} }
impl Add<MyInt, MyInt> for MyInt { impl Add<MyInt, MyInt> for MyInt {
pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) }
} }
impl Sub<MyInt, MyInt> for MyInt { impl Sub<MyInt, MyInt> for MyInt {
pure fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) } fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) }
} }
impl Mul<MyInt, MyInt> for MyInt { impl Mul<MyInt, MyInt> for MyInt {
pure fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) } fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) }
} }
impl Eq for MyInt { impl Eq for MyInt {
pure fn eq(&self, other: &MyInt) -> bool { self.val == other.val } fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) } fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
} }
impl MyNum for MyInt; impl MyNum for MyInt;
pure fn mi(v: int) -> MyInt { MyInt { val: v } } fn mi(v: int) -> MyInt { MyInt { val: v } }

View File

@ -27,14 +27,14 @@ fn sort_and_fmt(mm: HashMap<~[u8], uint>, total: uint) -> ~str {
return (xx as float) * 100f / (yy as float); return (xx as float) * 100f / (yy as float);
} }
pure fn le_by_val<TT:Copy,UU:Copy + Ord>(kv0: &(TT,UU), fn le_by_val<TT:Copy,UU:Copy + Ord>(kv0: &(TT,UU),
kv1: &(TT,UU)) -> bool { kv1: &(TT,UU)) -> bool {
let (_, v0) = *kv0; let (_, v0) = *kv0;
let (_, v1) = *kv1; let (_, v1) = *kv1;
return v0 >= v1; return v0 >= v1;
} }
pure fn le_by_key<TT:Copy + Ord,UU:Copy>(kv0: &(TT,UU), fn le_by_key<TT:Copy + Ord,UU:Copy>(kv0: &(TT,UU),
kv1: &(TT,UU)) -> bool { kv1: &(TT,UU)) -> bool {
let (k0, _) = *kv0; let (k0, _) = *kv0;
let (k1, _) = *kv1; let (k1, _) = *kv1;

View File

@ -33,7 +33,7 @@ struct cmplx {
} }
impl ops::Mul<cmplx,cmplx> for cmplx { impl ops::Mul<cmplx,cmplx> for cmplx {
pure fn mul(&self, x: &cmplx) -> cmplx { fn mul(&self, x: &cmplx) -> cmplx {
cmplx { cmplx {
re: self.re*(*x).re - self.im*(*x).im, re: self.re*(*x).re - self.im*(*x).im,
im: self.re*(*x).im + self.im*(*x).re im: self.re*(*x).im + self.im*(*x).re
@ -42,7 +42,7 @@ impl ops::Mul<cmplx,cmplx> for cmplx {
} }
impl ops::Add<cmplx,cmplx> for cmplx { impl ops::Add<cmplx,cmplx> for cmplx {
pure fn add(&self, x: &cmplx) -> cmplx { fn add(&self, x: &cmplx) -> cmplx {
cmplx { cmplx {
re: self.re + (*x).re, re: self.re + (*x).re,
im: self.im + (*x).im im: self.im + (*x).im
@ -52,7 +52,7 @@ impl ops::Add<cmplx,cmplx> for cmplx {
struct Line {i: uint, b: ~[u8]} struct Line {i: uint, b: ~[u8]}
pure fn cabs(x: cmplx) -> f64 fn cabs(x: cmplx) -> f64
{ {
x.re*x.re + x.im*x.im x.re*x.re + x.im*x.im
} }

View File

@ -20,9 +20,9 @@ fn main() {
} }
trait MyIter { trait MyIter {
pure fn test_mut(&mut self); fn test_mut(&mut self);
} }
impl MyIter for &'self [int] { impl MyIter for &'self [int] {
pure fn test_mut(&mut self) { } fn test_mut(&mut self) { }
} }

View File

@ -13,7 +13,7 @@
struct foo(~uint); struct foo(~uint);
impl Add<foo, foo> for foo { impl Add<foo, foo> for foo {
pure fn add(f: &foo) -> foo { fn add(f: &foo) -> foo {
foo(~(**self + **(*f))) foo(~(**self + **(*f)))
} }
} }

View File

@ -14,7 +14,7 @@ struct Point {
} }
impl ops::Add<int,int> for Point { impl ops::Add<int,int> for Point {
pure fn add(&self, z: &int) -> int { fn add(&self, z: &int) -> int {
self.x + self.y + (*z) self.x + self.y + (*z)
} }
} }

View File

@ -13,7 +13,7 @@ struct point { x: int, y: int }
trait methods { trait methods {
fn impurem(&self); fn impurem(&self);
fn blockm(&self, f: &fn()); fn blockm(&self, f: &fn());
pure fn purem(&self); fn purem(&self);
} }
impl methods for point { impl methods for point {
@ -22,7 +22,7 @@ impl methods for point {
fn blockm(&self, f: &fn()) { f() } fn blockm(&self, f: &fn()) { f() }
pure fn purem(&self) { fn purem(&self) {
} }
} }

View File

@ -10,8 +10,8 @@
struct thing(uint); struct thing(uint);
impl cmp::Ord for thing { //~ ERROR missing method `gt` impl cmp::Ord for thing { //~ ERROR missing method `gt`
pure fn lt(&self, other: &thing) -> bool { **self < **other } fn lt(&self, other: &thing) -> bool { **self < **other }
pure fn le(&self, other: &thing) -> bool { **self < **other } fn le(&self, other: &thing) -> bool { **self < **other }
pure fn ge(&self, other: &thing) -> bool { **self < **other } fn ge(&self, other: &thing) -> bool { **self < **other }
} }
fn main() {} fn main() {}

View File

@ -14,10 +14,10 @@ struct Obj {
} }
pub impl Obj { pub impl Obj {
pure fn boom() -> bool { fn boom() -> bool {
return 1+1 == 2 return 1+1 == 2
} }
pure fn chirp() { fn chirp() {
self.boom(); //~ ERROR wat self.boom(); //~ ERROR wat
} }
} }

View File

@ -14,7 +14,7 @@ struct Thing {
} }
impl Mul<int, Thing>*/ for Thing/* { //~ ERROR Look ma, no Mul! impl Mul<int, Thing>*/ for Thing/* { //~ ERROR Look ma, no Mul!
pure fn mul(c: &int) -> Thing { fn mul(c: &int) -> Thing {
Thing {x: self.x * *c} Thing {x: self.x * *c}
} }
} }

View File

@ -25,8 +25,8 @@ struct Lol(int);
impl Hahaha for Lol { } impl Hahaha for Lol { }
impl Eq for Lol { impl Eq for Lol {
pure fn eq(&self, other: &Lol) -> bool { **self != **other } fn eq(&self, other: &Lol) -> bool { **self != **other }
pure fn ne(&self, other: &Lol) -> bool { **self == **other } fn ne(&self, other: &Lol) -> bool { **self == **other }
} }
fn main() { fn main() {

View File

@ -20,7 +20,7 @@ impl ToStr for Point { //~ ERROR implements a method not defined in the trait
Point { x: x, y: y } Point { x: x, y: y }
} }
pure fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
fmt!("(%f, %f)", self.x, self.y) fmt!("(%f, %f)", self.x, self.y)
} }
} }

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
trait MyEq { trait MyEq {
pure fn eq(&self, other: &Self) -> bool; fn eq(&self, other: &Self) -> bool;
} }
struct A { struct A {
@ -17,7 +17,7 @@ struct A {
} }
impl MyEq for int { impl MyEq for int {
pure fn eq(&self, other: &int) -> bool { *self == *other } fn eq(&self, other: &int) -> bool { *self == *other }
} }
impl MyEq for A; //~ ERROR missing method impl MyEq for A; //~ ERROR missing method

View File

@ -1,6 +1,6 @@
// error-pattern:test // error-pattern:test
pure fn f() { fn f() {
fail!(~"test"); fail!(~"test");
} }

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
// error-pattern:Number is odd // error-pattern:Number is odd
pure fn even(x: uint) -> bool { fn even(x: uint) -> bool {
if x < 2u { if x < 2u {
return false; return false;
} else if x == 2u { return true; } else { return even(x - 2u); } } else if x == 2u { return true; } else { return even(x - 2u); }

View File

@ -60,7 +60,7 @@ enum Expr {
} }
impl cmp::Eq for Expr { impl cmp::Eq for Expr {
pure fn eq(&self, other: &Expr) -> bool { fn eq(&self, other: &Expr) -> bool {
match *self { match *self {
Val(e0a) => { Val(e0a) => {
match *other { match *other {
@ -82,18 +82,18 @@ impl cmp::Eq for Expr {
} }
} }
} }
pure fn ne(&self, other: &Expr) -> bool { !(*self).eq(other) } fn ne(&self, other: &Expr) -> bool { !(*self).eq(other) }
} }
impl cmp::Eq for Point { impl cmp::Eq for Point {
pure fn eq(&self, other: &Point) -> bool { fn eq(&self, other: &Point) -> bool {
self.x == other.x && self.y == other.y self.x == other.x && self.y == other.y
} }
pure fn ne(&self, other: &Point) -> bool { !(*self).eq(other) } fn ne(&self, other: &Point) -> bool { !(*self).eq(other) }
} }
impl<T:cmp::Eq> cmp::Eq for Quark<T> { impl<T:cmp::Eq> cmp::Eq for Quark<T> {
pure fn eq(&self, other: &Quark<T>) -> bool { fn eq(&self, other: &Quark<T>) -> bool {
match *self { match *self {
Top(ref q) => { Top(ref q) => {
match *other { match *other {
@ -109,14 +109,14 @@ impl<T:cmp::Eq> cmp::Eq for Quark<T> {
}, },
} }
} }
pure fn ne(&self, other: &Quark<T>) -> bool { !(*self).eq(other) } fn ne(&self, other: &Quark<T>) -> bool { !(*self).eq(other) }
} }
impl cmp::Eq for CLike { impl cmp::Eq for CLike {
pure fn eq(&self, other: &CLike) -> bool { fn eq(&self, other: &CLike) -> bool {
(*self) as int == *other as int (*self) as int == *other as int
} }
pure fn ne(&self, other: &CLike) -> bool { !self.eq(other) } fn ne(&self, other: &CLike) -> bool { !self.eq(other) }
} }
#[auto_encode] #[auto_encode]

View File

@ -12,18 +12,18 @@
// and also references them to create the &self pointer // and also references them to create the &self pointer
trait MyIter { trait MyIter {
pure fn test_imm(&self); fn test_imm(&self);
pure fn test_const(&const self); fn test_const(&const self);
} }
impl MyIter for &'self [int] { impl MyIter for &'self [int] {
pure fn test_imm(&self) { fail_unless!(self[0] == 1) } fn test_imm(&self) { fail_unless!(self[0] == 1) }
pure fn test_const(&const self) { fail_unless!(self[0] == 1) } fn test_const(&const self) { fail_unless!(self[0] == 1) }
} }
impl MyIter for &'self str { impl MyIter for &'self str {
pure fn test_imm(&self) { fail_unless!(*self == "test") } fn test_imm(&self) { fail_unless!(*self == "test") }
pure fn test_const(&const self) { fail_unless!(*self == "test") } fn test_const(&const self) { fail_unless!(*self == "test") }
} }
pub fn main() { pub fn main() {

View File

@ -16,10 +16,10 @@ use core::iter::BaseIter;
enum cat_type { tuxedo, tabby, tortoiseshell } enum cat_type { tuxedo, tabby, tortoiseshell }
impl cmp::Eq for cat_type { impl cmp::Eq for cat_type {
pure fn eq(&self, other: &cat_type) -> bool { fn eq(&self, other: &cat_type) -> bool {
((*self) as uint) == ((*other) as uint) ((*self) as uint) == ((*other) as uint)
} }
pure fn ne(&self, other: &cat_type) -> bool { !(*self).eq(other) } fn ne(&self, other: &cat_type) -> bool { !(*self).eq(other) }
} }
// Very silly -- this just returns the value of the name field // Very silly -- this just returns the value of the name field
@ -50,7 +50,7 @@ pub impl<T> cat<T> {
} }
impl<T> BaseIter<(int, &'self T)> for cat<T> { impl<T> BaseIter<(int, &'self T)> for cat<T> {
pure fn each(&self, f: &fn(&(int, &'self T)) -> bool) { fn each(&self, f: &fn(&(int, &'self T)) -> bool) {
let mut n = int::abs(self.meows); let mut n = int::abs(self.meows);
while n > 0 { while n > 0 {
if !f(&(n, &self.name)) { break; } if !f(&(n, &self.name)) { break; }
@ -58,12 +58,12 @@ impl<T> BaseIter<(int, &'self T)> for cat<T> {
} }
} }
pure fn size_hint(&self) -> Option<uint> { Some(self.len()) } fn size_hint(&self) -> Option<uint> { Some(self.len()) }
} }
impl<T> Container for cat<T> { impl<T> Container for cat<T> {
pure fn len(&const self) -> uint { self.meows as uint } fn len(&const self) -> uint { self.meows as uint }
pure fn is_empty(&const self) -> bool { self.meows == 0 } fn is_empty(&const self) -> bool { self.meows == 0 }
} }
impl<T> Mutable for cat<T> { impl<T> Mutable for cat<T> {
@ -71,13 +71,13 @@ impl<T> Mutable for cat<T> {
} }
impl<T> Map<int, T> for cat<T> { impl<T> Map<int, T> for cat<T> {
pure fn contains_key(&self, k: &int) -> bool { *k <= self.meows } fn contains_key(&self, k: &int) -> bool { *k <= self.meows }
pure fn each_key(&self, f: &fn(v: &int) -> bool) { fn each_key(&self, f: &fn(v: &int) -> bool) {
for self.each |&(k, _)| { if !f(&k) { break; } loop;}; for self.each |&(k, _)| { if !f(&k) { break; } loop;};
} }
pure fn each_value(&self, f: &fn(v: &T) -> bool) { fn each_value(&self, f: &fn(v: &T) -> bool) {
for self.each |&(_, v)| { if !f(v) { break; } loop;}; for self.each |&(_, v)| { if !f(v) { break; } loop;};
} }
@ -90,7 +90,7 @@ impl<T> Map<int, T> for cat<T> {
true true
} }
pure fn find(&self, k: &int) -> Option<&'self T> { fn find(&self, k: &int) -> Option<&'self T> {
if *k <= self.meows { if *k <= self.meows {
Some(&self.name) Some(&self.name)
} else { } else {
@ -108,14 +108,14 @@ impl<T> Map<int, T> for cat<T> {
} }
pub impl<T> cat<T> { pub impl<T> cat<T> {
pure fn get(&self, k: &int) -> &'self T { fn get(&self, k: &int) -> &'self T {
match self.find(k) { match self.find(k) {
Some(v) => { v } Some(v) => { v }
None => { fail!(~"epic fail"); } None => { fail!(~"epic fail"); }
} }
} }
pure fn new(in_x: int, in_y: int, in_name: T) -> cat<T> { fn new(in_x: int, in_y: int, in_name: T) -> cat<T> {
cat{meows: in_x, how_hungry: in_y, name: in_name } cat{meows: in_x, how_hungry: in_y, name: in_name }
} }
} }

View File

@ -51,7 +51,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> cat {
} }
impl ToStr for cat { impl ToStr for cat {
pure fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
// FIXME #5384: this unsafe block is to work around purity // FIXME #5384: this unsafe block is to work around purity
unsafe { unsafe {
self.name.clone() self.name.clone()

View File

@ -1,4 +1,4 @@
pure fn negate(x: &int) -> int { fn negate(x: &int) -> int {
-*x -*x
} }

View File

@ -3,7 +3,7 @@ struct SpeechMaker {
} }
pub impl SpeechMaker { pub impl SpeechMaker {
pure fn how_many(&const self) -> uint { self.speeches } fn how_many(&const self) -> uint { self.speeches }
} }
fn foo(speaker: &const SpeechMaker) -> uint { fn foo(speaker: &const SpeechMaker) -> uint {

View File

@ -1,6 +1,6 @@
// xfail-test // xfail-test
pure fn sum(x: &[int]) -> int { fn sum(x: &[int]) -> int {
let mut sum = 0; let mut sum = 0;
for x.each |y| { sum += *y; } for x.each |y| { sum += *y; }
return sum; return sum;

View File

@ -11,9 +11,9 @@
pub fn main() { pub fn main() {
enum x { foo } enum x { foo }
impl ::core::cmp::Eq for x { impl ::core::cmp::Eq for x {
pure fn eq(&self, other: &x) -> bool { fn eq(&self, other: &x) -> bool {
(*self) as int == (*other) as int (*self) as int == (*other) as int
} }
pure fn ne(&self, other: &x) -> bool { !(*self).eq(other) } fn ne(&self, other: &x) -> bool { !(*self).eq(other) }
} }
} }

View File

@ -12,12 +12,12 @@
struct foo { a: int, b: int, c: int } struct foo { a: int, b: int, c: int }
impl cmp::Eq for foo { impl cmp::Eq for foo {
pure fn eq(&self, other: &foo) -> bool { fn eq(&self, other: &foo) -> bool {
(*self).a == (*other).a && (*self).a == (*other).a &&
(*self).b == (*other).b && (*self).b == (*other).b &&
(*self).c == (*other).c (*self).c == (*other).c
} }
pure fn ne(&self, other: &foo) -> bool { !(*self).eq(other) } fn ne(&self, other: &foo) -> bool { !(*self).eq(other) }
} }
const x : foo = foo { a:1, b:2, c: 3 }; const x : foo = foo { a:1, b:2, c: 3 };

View File

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
pure fn f(f: &fn()) { fn f(f: &fn()) {
} }
pure fn g() { fn g() {
// `f || { }` is considered pure, so `do f { }` should be too // `f || { }` is considered pure, so `do f { }` should be too
do f { } do f { }
} }

View File

@ -11,10 +11,10 @@
enum chan { chan_t, } enum chan { chan_t, }
impl cmp::Eq for chan { impl cmp::Eq for chan {
pure fn eq(&self, other: &chan) -> bool { fn eq(&self, other: &chan) -> bool {
((*self) as uint) == ((*other) as uint) ((*self) as uint) == ((*other) as uint)
} }
pure fn ne(&self, other: &chan) -> bool { !(*self).eq(other) } fn ne(&self, other: &chan) -> bool { !(*self).eq(other) }
} }
fn wrapper3(i: chan) { fn wrapper3(i: chan) {

View File

@ -15,8 +15,8 @@ extern mod std;
* *
* The hash should concentrate entropy in the lower bits. * The hash should concentrate entropy in the lower bits.
*/ */
type HashFn<K> = ~pure fn(K) -> uint; type HashFn<K> = ~fn(K) -> uint;
type EqFn<K> = ~pure fn(K, K) -> bool; type EqFn<K> = ~fn(K, K) -> bool;
struct LM { resize_at: uint, size: uint } struct LM { resize_at: uint, size: uint }

View File

@ -16,10 +16,10 @@ mod foo {
enum t { t1, t2, } enum t { t1, t2, }
impl cmp::Eq for t { impl cmp::Eq for t {
pure fn eq(&self, other: &t) -> bool { fn eq(&self, other: &t) -> bool {
((*self) as uint) == ((*other) as uint) ((*self) as uint) == ((*other) as uint)
} }
pure fn ne(&self, other: &t) -> bool { !(*self).eq(other) } fn ne(&self, other: &t) -> bool { !(*self).eq(other) }
} }
pub fn f() -> t { return t1; } pub fn f() -> t { return t1; }

View File

@ -24,10 +24,10 @@ fn test_rec() {
enum mood { happy, sad, } enum mood { happy, sad, }
impl cmp::Eq for mood { impl cmp::Eq for mood {
pure fn eq(&self, other: &mood) -> bool { fn eq(&self, other: &mood) -> bool {
((*self) as uint) == ((*other) as uint) ((*self) as uint) == ((*other) as uint)
} }
pure fn ne(&self, other: &mood) -> bool { !(*self).eq(other) } fn ne(&self, other: &mood) -> bool { !(*self).eq(other) }
} }
fn test_tag() { fn test_tag() {

View File

@ -25,10 +25,10 @@ fn test_rec() {
enum mood { happy, sad, } enum mood { happy, sad, }
impl cmp::Eq for mood { impl cmp::Eq for mood {
pure fn eq(&self, other: &mood) -> bool { fn eq(&self, other: &mood) -> bool {
((*self) as uint) == ((*other) as uint) ((*self) as uint) == ((*other) as uint)
} }
pure fn ne(&self, other: &mood) -> bool { !(*self).eq(other) } fn ne(&self, other: &mood) -> bool { !(*self).eq(other) }
} }
fn test_tag() { fn test_tag() {

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
pure fn even(x: uint) -> bool { fn even(x: uint) -> bool {
if x < 2u { if x < 2u {
return false; return false;
} else if x == 2u { return true; } else { return even(x - 2u); } } else if x == 2u { return true; } else { return even(x - 2u); }

View File

@ -28,7 +28,7 @@ enum square {
} }
impl to_str::ToStr for square { impl to_str::ToStr for square {
pure fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
match *self { match *self {
bot => { ~"R" } bot => { ~"R" }
wall => { ~"#" } wall => { ~"#" }

View File

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
pure fn Matrix4<T:Copy>(m11: T, m12: T, m13: T, m14: T, fn Matrix4<T:Copy>(m11: T, m12: T, m13: T, m14: T,
m21: T, m22: T, m23: T, m24: T, m21: T, m22: T, m23: T, m24: T,
m31: T, m32: T, m33: T, m34: T, m31: T, m32: T, m33: T, m34: T,
m41: T, m42: T, m43: T, m44: T) m41: T, m42: T, m43: T, m44: T)
-> Matrix4<T> { -> Matrix4<T> {
Matrix4 { Matrix4 {
m11: m11, m12: m12, m13: m13, m14: m14, m11: m11, m12: m12, m13: m13, m14: m14,

View File

@ -13,13 +13,12 @@ type IMap<K:Copy,V:Copy> = ~[(K, V)];
trait ImmutableMap<K:Copy,V:Copy> trait ImmutableMap<K:Copy,V:Copy>
{ {
pure fn contains_key(key: K) -> bool; fn contains_key(key: K) -> bool;
} }
impl<K:Copy,V:Copy> IMap<K, V> : ImmutableMap<K, V> impl<K:Copy,V:Copy> IMap<K, V> : ImmutableMap<K, V>
{ {
pure fn contains_key(key: K) -> bool fn contains_key(key: K) -> bool {
{
vec::find(self, |e| {e.first() == key}).is_some() vec::find(self, |e| {e.first() == key}).is_some()
} }
} }

View File

@ -111,8 +111,7 @@ impl AsciiArt
// Allows AsciiArt to be converted to a string using the libcore ToStr trait. // Allows AsciiArt to be converted to a string using the libcore ToStr trait.
// Note that the %s fmt! specifier will not call this automatically. // Note that the %s fmt! specifier will not call this automatically.
impl ToStr for AsciiArt { impl ToStr for AsciiArt {
pure fn to_str(&self) -> ~str fn to_str(&self) -> ~str {
{
// Convert each line into a string. // Convert each line into a string.
let lines = do self.lines.map |line| {str::from_chars(*line)}; let lines = do self.lines.map |line| {str::from_chars(*line)};

View File

@ -11,7 +11,7 @@
// xfail-test // xfail-test
enum PureCounter { PureCounter(uint) } enum PureCounter { PureCounter(uint) }
pure fn each(self: PureCounter, blk: &fn(v: &uint)) { fn each(self: PureCounter, blk: &fn(v: &uint)) {
let PureCounter(ref x) = self; let PureCounter(ref x) = self;
blk(x); blk(x);
} }

View File

@ -13,4 +13,4 @@
use T = self::inst::T; use T = self::inst::T;
pub const bits: uint = inst::bits; pub const bits: uint = inst::bits;
pub pure fn min(x: T, y: T) -> T { if x < y { x } else { y } } pub fn min(x: T, y: T) -> T { if x < y { x } else { y } }

View File

@ -4,7 +4,7 @@ struct Thingy {
} }
impl ToStr for Thingy { impl ToStr for Thingy {
pure fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
fmt!("{ x: %d, y: %d }", self.x, self.y) fmt!("{ x: %d, y: %d }", self.x, self.y)
} }
} }
@ -14,7 +14,7 @@ struct PolymorphicThingy<T> {
} }
impl<T:ToStr> ToStr for PolymorphicThingy<T> { impl<T:ToStr> ToStr for PolymorphicThingy<T> {
pure fn to_str(&self) -> ~str { fn to_str(&self) -> ~str {
self.x.to_str() self.x.to_str()
} }
} }

View File

@ -14,13 +14,13 @@ extern mod std;
use std::list::*; use std::list::*;
pure fn pure_length_go<T:Copy>(ls: @List<T>, acc: uint) -> uint { fn pure_length_go<T:Copy>(ls: @List<T>, acc: uint) -> uint {
match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } } match *ls { Nil => { acc } Cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
} }
pure fn pure_length<T:Copy>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) } fn pure_length<T:Copy>(ls: @List<T>) -> uint { pure_length_go(ls, 0u) }
pure fn nonempty_list<T:Copy>(ls: @List<T>) -> bool { pure_length(ls) > 0u } fn nonempty_list<T:Copy>(ls: @List<T>) -> bool { pure_length(ls) > 0u }
fn safe_head<T:Copy>(ls: @List<T>) -> T { fn safe_head<T:Copy>(ls: @List<T>) -> T {
fail_unless!(!is_empty(ls)); fail_unless!(!is_empty(ls));

View File

@ -16,40 +16,40 @@ struct Point {
} }
impl ops::Add<Point,Point> for Point { impl ops::Add<Point,Point> for Point {
pure fn add(&self, other: &Point) -> Point { fn add(&self, other: &Point) -> Point {
Point {x: self.x + (*other).x, y: self.y + (*other).y} Point {x: self.x + (*other).x, y: self.y + (*other).y}
} }
} }
impl ops::Sub<Point,Point> for Point { impl ops::Sub<Point,Point> for Point {
pure fn sub(&self, other: &Point) -> Point { fn sub(&self, other: &Point) -> Point {
Point {x: self.x - (*other).x, y: self.y - (*other).y} Point {x: self.x - (*other).x, y: self.y - (*other).y}
} }
} }
impl ops::Neg<Point> for Point { impl ops::Neg<Point> for Point {
pure fn neg(&self) -> Point { fn neg(&self) -> Point {
Point {x: -self.x, y: -self.y} Point {x: -self.x, y: -self.y}
} }
} }
impl ops::Not<Point> for Point { impl ops::Not<Point> for Point {
pure fn not(&self) -> Point { fn not(&self) -> Point {
Point {x: !self.x, y: !self.y } Point {x: !self.x, y: !self.y }
} }
} }
impl ops::Index<bool,int> for Point { impl ops::Index<bool,int> for Point {
pure fn index(&self, +x: bool) -> int { fn index(&self, +x: bool) -> int {
if x { self.x } else { self.y } if x { self.x } else { self.y }
} }
} }
impl cmp::Eq for Point { impl cmp::Eq for Point {
pure fn eq(&self, other: &Point) -> bool { fn eq(&self, other: &Point) -> bool {
(*self).x == (*other).x && (*self).y == (*other).y (*self).x == (*other).x && (*self).y == (*other).y
} }
pure fn ne(&self, other: &Point) -> bool { !(*self).eq(other) } fn ne(&self, other: &Point) -> bool { !(*self).eq(other) }
} }
pub fn main() { pub fn main() {

View File

@ -11,6 +11,6 @@
// this checks that a pred with a non-bool return // this checks that a pred with a non-bool return
// type is rejected, even if the pred is never used // type is rejected, even if the pred is never used
pure fn bad(a: int) -> int { return 37; } //~ ERROR Non-boolean return type fn bad(a: int) -> int { return 37; } //~ ERROR Non-boolean return type
pub fn main() { } pub fn main() { }

View File

@ -13,7 +13,7 @@
struct Big { b: @~str, c: uint, d: int, e: char, struct Big { b: @~str, c: uint, d: int, e: char,
f: float, g: bool } f: float, g: bool }
pure fn foo() { fn foo() {
let a = Big { let a = Big {
b: @~"hi", b: @~"hi",
c: 0, c: 0,

View File

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// Check that pure functions can modify local state. // Check that functions can modify local state.
pure fn sums_to(v: ~[int], sum: int) -> bool { fn sums_to(v: ~[int], sum: int) -> bool {
let mut i = 0u, sum0 = 0; let mut i = 0u, sum0 = 0;
while i < v.len() { while i < v.len() {
sum0 += v[i]; sum0 += v[i];
@ -19,7 +19,7 @@ pure fn sums_to(v: ~[int], sum: int) -> bool {
return sum0 == sum; return sum0 == sum;
} }
pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool { fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
let mut i = 0u, sum0 = ~0; let mut i = 0u, sum0 = ~0;
while i < v.len() { while i < v.len() {
*sum0 += v[i]; *sum0 += v[i];
@ -28,7 +28,7 @@ pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
return *sum0 == sum; return *sum0 == sum;
} }
pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool { fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
let mut i = 0u, sum0 = F {f: 0}; let mut i = 0u, sum0 = F {f: 0};
while i < v.len() { while i < v.len() {
sum0.f += v[i]; sum0.f += v[i];
@ -39,7 +39,7 @@ pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
struct F<T> { f: T } struct F<T> { f: T }
pure fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool { fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool {
let mut i = 0u, sum0 = F {f: ~0}; let mut i = 0u, sum0 = F {f: ~0};
while i < v.len() { while i < v.len() {
*sum0.f += v[i]; *sum0.f += v[i];

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
fn something(f: &pure fn()) { f(); } fn something(f: &fn()) { f(); }
pub fn main() { pub fn main() {
something(|| error!("hi!") ); something(|| error!("hi!") );
} }

View File

@ -35,28 +35,25 @@ impl bool_like for int {
// A trait for sequences that can be constructed imperatively. // A trait for sequences that can be constructed imperatively.
trait buildable<A> { trait buildable<A> {
pure fn build_sized(size: uint, fn build_sized(size: uint, builder: &fn(push: &fn(+v: A))) -> Self;
builder: &fn(push: &pure fn(+v: A))) -> Self;
} }
impl<A> buildable<A> for @[A] { impl<A> buildable<A> for @[A] {
#[inline(always)] #[inline(always)]
pure fn build_sized(size: uint, fn build_sized(size: uint, builder: &fn(push: &fn(+v: A))) -> @[A] {
builder: &fn(push: &pure fn(+v: A))) -> @[A] {
at_vec::build_sized(size, builder) at_vec::build_sized(size, builder)
} }
} }
impl<A> buildable<A> for ~[A] { impl<A> buildable<A> for ~[A] {
#[inline(always)] #[inline(always)]
pure fn build_sized(size: uint, fn build_sized(size: uint, builder: &fn(push: &fn(+v: A))) -> ~[A] {
builder: &fn(push: &pure fn(+v: A))) -> ~[A] {
vec::build_sized(size, builder) vec::build_sized(size, builder)
} }
} }
#[inline(always)] #[inline(always)]
pure fn build<A, B: buildable<A>>(builder: &fn(push: &pure fn(+v: A))) -> B { fn build<A, B: buildable<A>>(builder: &fn(push: &fn(+v: A))) -> B {
buildable::build_sized(4, builder) buildable::build_sized(4, builder)
} }

View File

@ -1,17 +1,17 @@
pub trait Number: NumConv { pub trait Number: NumConv {
pure fn from<T:Number>(n: T) -> Self; fn from<T:Number>(n: T) -> Self;
} }
impl Number for float { impl Number for float {
pure fn from<T:Number>(n: T) -> float { n.to_float() } fn from<T:Number>(n: T) -> float { n.to_float() }
} }
pub trait NumConv { pub trait NumConv {
pure fn to_float(&self) -> float; fn to_float(&self) -> float;
} }
impl NumConv for float { impl NumConv for float {
pure fn to_float(&self) -> float { *self } fn to_float(&self) -> float { *self }
} }
pub fn main() { pub fn main() {

View File

@ -13,10 +13,10 @@
enum foo { large, small, } enum foo { large, small, }
impl cmp::Eq for foo { impl cmp::Eq for foo {
pure fn eq(&self, other: &foo) -> bool { fn eq(&self, other: &foo) -> bool {
((*self) as uint) == ((*other) as uint) ((*self) as uint) == ((*other) as uint)
} }
pure fn ne(&self, other: &foo) -> bool { !(*self).eq(other) } fn ne(&self, other: &foo) -> bool { !(*self).eq(other) }
} }
pub fn main() { pub fn main() {

View File

@ -20,10 +20,10 @@ enum color {
} }
impl cmp::Eq for color { impl cmp::Eq for color {
pure fn eq(&self, other: &color) -> bool { fn eq(&self, other: &color) -> bool {
((*self) as uint) == ((*other) as uint) ((*self) as uint) == ((*other) as uint)
} }
pure fn ne(&self, other: &color) -> bool { !(*self).eq(other) } fn ne(&self, other: &color) -> bool { !(*self).eq(other) }
} }
pub fn main() { pub fn main() {

View File

@ -15,7 +15,7 @@
enum colour { red(int, int), green, } enum colour { red(int, int), green, }
impl cmp::Eq for colour { impl cmp::Eq for colour {
pure fn eq(&self, other: &colour) -> bool { fn eq(&self, other: &colour) -> bool {
match *self { match *self {
red(a0, b0) => { red(a0, b0) => {
match (*other) { match (*other) {
@ -31,7 +31,7 @@ impl cmp::Eq for colour {
} }
} }
} }
pure fn ne(&self, other: &colour) -> bool { !(*self).eq(other) } fn ne(&self, other: &colour) -> bool { !(*self).eq(other) }
} }
fn f() { let x = red(1, 2); let y = green; fail_unless!((x != y)); } fn f() { let x = red(1, 2); let y = green; fail_unless!((x != y)); }

View File

@ -52,7 +52,7 @@ enum t {
} }
impl cmp::Eq for t { impl cmp::Eq for t {
pure fn eq(&self, other: &t) -> bool { fn eq(&self, other: &t) -> bool {
match *self { match *self {
tag1 => { tag1 => {
match (*other) { match (*other) {
@ -75,7 +75,7 @@ impl cmp::Eq for t {
} }
} }
} }
pure fn ne(&self, other: &t) -> bool { !(*self).eq(other) } fn ne(&self, other: &t) -> bool { !(*self).eq(other) }
} }
fn test_tag() { fn test_tag() {

View File

@ -15,8 +15,8 @@ trait MyNum : Eq { }
struct MyInt { val: int } struct MyInt { val: int }
impl Eq for MyInt { impl Eq for MyInt {
pure fn eq(&self, other: &MyInt) -> bool { self.val == other.val } fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) } fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
} }
impl MyNum for MyInt; impl MyNum for MyInt;
@ -25,7 +25,7 @@ fn f<T:MyNum>(x: T, y: T) -> bool {
return x == y; return x == y;
} }
pure fn mi(v: int) -> MyInt { MyInt { val: v } } fn mi(v: int) -> MyInt { MyInt { val: v } }
pub fn main() { pub fn main() {
let (x, y, z) = (mi(3), mi(5), mi(3)); let (x, y, z) = (mi(3), mi(5), mi(3));

View File

@ -18,7 +18,7 @@ fn f<T:Copy + MyNum>(x: T, y: T) -> (T, T, T) {
return (x + y, x - y, x * y); return (x + y, x - y, x * y);
} }
pure fn mi(v: int) -> MyInt { MyInt { val: v } } fn mi(v: int) -> MyInt { MyInt { val: v } }
pub fn main() { pub fn main() {
let (x, y) = (mi(3), mi(5)); let (x, y) = (mi(3), mi(5));

View File

@ -15,20 +15,20 @@ trait MyNum : Add<Self,Self> + Sub<Self,Self> + Mul<Self,Self> + Eq { }
struct MyInt { val: int } struct MyInt { val: int }
impl Add<MyInt, MyInt> for MyInt { impl Add<MyInt, MyInt> for MyInt {
pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) }
} }
impl Sub<MyInt, MyInt> for MyInt { impl Sub<MyInt, MyInt> for MyInt {
pure fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) } fn sub(&self, other: &MyInt) -> MyInt { mi(self.val - other.val) }
} }
impl Mul<MyInt, MyInt> for MyInt { impl Mul<MyInt, MyInt> for MyInt {
pure fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) } fn mul(&self, other: &MyInt) -> MyInt { mi(self.val * other.val) }
} }
impl Eq for MyInt { impl Eq for MyInt {
pure fn eq(&self, other: &MyInt) -> bool { self.val == other.val } fn eq(&self, other: &MyInt) -> bool { self.val == other.val }
pure fn ne(&self, other: &MyInt) -> bool { !self.eq(other) } fn ne(&self, other: &MyInt) -> bool { !self.eq(other) }
} }
impl MyNum for MyInt; impl MyNum for MyInt;
@ -37,7 +37,7 @@ fn f<T:Copy + MyNum>(x: T, y: T) -> (T, T, T) {
return (x + y, x - y, x * y); return (x + y, x - y, x * y);
} }
pure fn mi(v: int) -> MyInt { MyInt { val: v } } fn mi(v: int) -> MyInt { MyInt { val: v } }
pub fn main() { pub fn main() {
let (x, y) = (mi(3), mi(5)); let (x, y) = (mi(3), mi(5));

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
pub trait Add<RHS,Result> { pub trait Add<RHS,Result> {
pure fn add(&self, rhs: &RHS) -> Result; fn add(&self, rhs: &RHS) -> Result;
} }
trait MyNum : Add<Self,Self> { } trait MyNum : Add<Self,Self> { }
@ -17,7 +17,7 @@ trait MyNum : Add<Self,Self> { }
struct MyInt { val: int } struct MyInt { val: int }
impl Add<MyInt, MyInt> for MyInt { impl Add<MyInt, MyInt> for MyInt {
pure fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) } fn add(&self, other: &MyInt) -> MyInt { mi(self.val + other.val) }
} }
impl MyNum for MyInt; impl MyNum for MyInt;
@ -26,7 +26,7 @@ fn f<T:MyNum>(x: T, y: T) -> T {
return x.add(&y); return x.add(&y);
} }
pure fn mi(v: int) -> MyInt { MyInt { val: v } } fn mi(v: int) -> MyInt { MyInt { val: v } }
pub fn main() { pub fn main() {
let (x, y) = (mi(3), mi(5)); let (x, y) = (mi(3), mi(5));

View File

@ -12,7 +12,7 @@
mod base { mod base {
pub trait HasNew<T> { pub trait HasNew<T> {
pure fn new() -> T; fn new() -> T;
} }
pub struct Foo { pub struct Foo {
@ -20,7 +20,7 @@ mod base {
} }
impl ::base::HasNew<Foo> for Foo { impl ::base::HasNew<Foo> for Foo {
pure fn new() -> Foo { fn new() -> Foo {
unsafe { io::println("Foo"); } unsafe { io::println("Foo"); }
Foo { dummy: () } Foo { dummy: () }
} }
@ -31,7 +31,7 @@ mod base {
} }
impl ::base::HasNew<Bar> for Bar { impl ::base::HasNew<Bar> for Bar {
pure fn new() -> Bar { fn new() -> Bar {
unsafe { io::println("Bar"); } unsafe { io::println("Bar"); }
Bar { dummy: () } Bar { dummy: () }
} }

View File

@ -10,7 +10,7 @@
// xfail-test // xfail-test
pure fn is_even(i: int) -> bool { (i%2) == 0 } fn is_even(i: int) -> bool { (i%2) == 0 }
fn even(i: int) : is_even(i) -> int { i } fn even(i: int) : is_even(i) -> int { i }
fn test() { fn test() {

View File

@ -56,7 +56,7 @@ fn notsure() {
} }
fn canttouchthis() -> uint { fn canttouchthis() -> uint {
pure fn p() -> bool { true } fn p() -> bool { true }
let _a = (fail_unless!((true)) == (fail_unless!(p()))); let _a = (fail_unless!((true)) == (fail_unless!(p())));
let _c = (fail_unless!((p())) == ()); let _c = (fail_unless!((p())) == ());
let _b: bool = (debug!("%d", 0) == (return 0u)); let _b: bool = (debug!("%d", 0) == (return 0u));