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 {
pure fn to_str(&self) -> ~str { copy self.name }
fn to_str(&self) -> ~str { copy self.name }
}
priv impl cat {

View file

@ -25,11 +25,11 @@ pub enum e {
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 {
pure fn eq(&self, other: &e) -> bool { nominal_eq(*self, *other) }
pure fn ne(&self, other: &e) -> bool { !nominal_eq(*self, *other) }
fn eq(&self, other: &e) -> bool { nominal_eq(*self, *other) }
fn ne(&self, other: &e) -> bool { !nominal_eq(*self, *other) }
}
pub fn f() -> int { 10 }

View file

@ -23,12 +23,12 @@ pub enum e {
}
impl Eq for e {
pure fn eq(&self, other: &e) -> bool { !nominal_neq(*self, *other) }
pure fn ne(&self, other: &e) -> bool { nominal_neq(*self, *other) }
fn eq(&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 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 }

View file

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

View file

@ -1,11 +1,11 @@
pub mod num {
pub trait Num2 {
pure fn from_int2(n: int) -> Self;
fn from_int2(n: int) -> Self;
}
}
pub mod 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 {
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 {
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 {
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 {
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;
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);
}
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 {
let (_, v0) = *kv0;
let (_, v1) = *kv1;
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 {
let (k0, _) = *kv0;
let (k1, _) = *kv1;

View file

@ -33,7 +33,7 @@ struct cmplx {
}
impl ops::Mul<cmplx,cmplx> for cmplx {
pure fn mul(&self, x: &cmplx) -> cmplx {
fn mul(&self, x: &cmplx) -> cmplx {
cmplx {
re: self.re*(*x).re - self.im*(*x).im,
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 {
pure fn add(&self, x: &cmplx) -> cmplx {
fn add(&self, x: &cmplx) -> cmplx {
cmplx {
re: self.re + (*x).re,
im: self.im + (*x).im
@ -52,7 +52,7 @@ impl ops::Add<cmplx,cmplx> for cmplx {
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
}

View file

@ -20,9 +20,9 @@ fn main() {
}
trait MyIter {
pure fn test_mut(&mut self);
fn test_mut(&mut self);
}
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);
impl Add<foo, foo> for foo {
pure fn add(f: &foo) -> foo {
fn add(f: &foo) -> foo {
foo(~(**self + **(*f)))
}
}

View file

@ -14,7 +14,7 @@ struct 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)
}
}

View file

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

View file

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

View file

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

View file

@ -14,7 +14,7 @@ struct Thing {
}
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}
}
}

View file

@ -25,8 +25,8 @@ struct Lol(int);
impl Hahaha for Lol { }
impl Eq for Lol {
pure fn eq(&self, other: &Lol) -> bool { **self != **other }
pure fn ne(&self, other: &Lol) -> bool { **self == **other }
fn eq(&self, other: &Lol) -> bool { **self != **other }
fn ne(&self, other: &Lol) -> bool { **self == **other }
}
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 }
}
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
fmt!("(%f, %f)", self.x, self.y)
}
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
trait MyEq {
pure fn eq(&self, other: &Self) -> bool;
fn eq(&self, other: &Self) -> bool;
}
struct A {
@ -17,7 +17,7 @@ struct A {
}
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

View file

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

View file

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

View file

@ -60,7 +60,7 @@ enum Expr {
}
impl cmp::Eq for Expr {
pure fn eq(&self, other: &Expr) -> bool {
fn eq(&self, other: &Expr) -> bool {
match *self {
Val(e0a) => {
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 {
pure fn eq(&self, other: &Point) -> bool {
fn eq(&self, other: &Point) -> bool {
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> {
pure fn eq(&self, other: &Quark<T>) -> bool {
fn eq(&self, other: &Quark<T>) -> bool {
match *self {
Top(ref q) => {
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 {
pure fn eq(&self, other: &CLike) -> bool {
fn eq(&self, other: &CLike) -> bool {
(*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]

View file

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

View file

@ -16,10 +16,10 @@ use core::iter::BaseIter;
enum cat_type { tuxedo, tabby, tortoiseshell }
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)
}
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
@ -50,7 +50,7 @@ pub impl<T> 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);
while n > 0 {
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> {
pure fn len(&const self) -> uint { self.meows as uint }
pure fn is_empty(&const self) -> bool { self.meows == 0 }
fn len(&const self) -> uint { self.meows as uint }
fn is_empty(&const self) -> bool { self.meows == 0 }
}
impl<T> Mutable for cat<T> {
@ -71,13 +71,13 @@ impl<T> Mutable 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;};
}
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;};
}
@ -90,7 +90,7 @@ impl<T> Map<int, T> for cat<T> {
true
}
pure fn find(&self, k: &int) -> Option<&'self T> {
fn find(&self, k: &int) -> Option<&'self T> {
if *k <= self.meows {
Some(&self.name)
} else {
@ -108,14 +108,14 @@ impl<T> Map<int, T> for 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) {
Some(v) => { v }
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 }
}
}

View file

@ -51,7 +51,7 @@ fn cat(in_x : uint, in_y : int, in_name: ~str) -> 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
unsafe {
self.name.clone()

View file

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

View file

@ -3,7 +3,7 @@ struct 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 {

View file

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

View file

@ -11,9 +11,9 @@
pub fn main() {
enum x { foo }
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
}
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 }
impl cmp::Eq for foo {
pure fn eq(&self, other: &foo) -> bool {
fn eq(&self, other: &foo) -> bool {
(*self).a == (*other).a &&
(*self).b == (*other).b &&
(*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 };

View file

@ -8,10 +8,10 @@
// option. This file may not be copied, modified, or distributed
// 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
do f { }
}

View file

@ -11,10 +11,10 @@
enum chan { chan_t, }
impl cmp::Eq for chan {
pure fn eq(&self, other: &chan) -> bool {
fn eq(&self, other: &chan) -> bool {
((*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) {

View file

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

View file

@ -16,10 +16,10 @@ mod foo {
enum t { t1, t2, }
impl cmp::Eq for t {
pure fn eq(&self, other: &t) -> bool {
fn eq(&self, other: &t) -> bool {
((*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; }

View file

@ -24,10 +24,10 @@ fn test_rec() {
enum mood { happy, sad, }
impl cmp::Eq for mood {
pure fn eq(&self, other: &mood) -> bool {
fn eq(&self, other: &mood) -> bool {
((*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() {

View file

@ -25,10 +25,10 @@ fn test_rec() {
enum mood { happy, sad, }
impl cmp::Eq for mood {
pure fn eq(&self, other: &mood) -> bool {
fn eq(&self, other: &mood) -> bool {
((*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() {

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pure fn even(x: uint) -> bool {
fn even(x: uint) -> bool {
if x < 2u {
return false;
} 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 {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
match *self {
bot => { ~"R" }
wall => { ~"#" }

View file

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

View file

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

View file

@ -11,7 +11,7 @@
// xfail-test
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;
blk(x);
}

View file

@ -13,4 +13,4 @@
use T = self::inst::T;
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 {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
fmt!("{ x: %d, y: %d }", self.x, self.y)
}
}
@ -14,7 +14,7 @@ struct PolymorphicThingy<T> {
}
impl<T:ToStr> ToStr for PolymorphicThingy<T> {
pure fn to_str(&self) -> ~str {
fn to_str(&self) -> ~str {
self.x.to_str()
}
}

View file

@ -14,13 +14,13 @@ extern mod std;
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) } }
}
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 {
fail_unless!(!is_empty(ls));

View file

@ -16,40 +16,40 @@ struct 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}
}
}
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}
}
}
impl ops::Neg<Point> for Point {
pure fn neg(&self) -> Point {
fn neg(&self) -> Point {
Point {x: -self.x, y: -self.y}
}
}
impl ops::Not<Point> for Point {
pure fn not(&self) -> Point {
fn not(&self) -> Point {
Point {x: !self.x, y: !self.y }
}
}
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 }
}
}
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
}
pure fn ne(&self, other: &Point) -> bool { !(*self).eq(other) }
fn ne(&self, other: &Point) -> bool { !(*self).eq(other) }
}
pub fn main() {

View file

@ -11,6 +11,6 @@
// this checks that a pred with a non-bool return
// 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() { }

View file

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

View file

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed
// 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;
while i < v.len() {
sum0 += v[i];
@ -19,7 +19,7 @@ pure fn sums_to(v: ~[int], sum: int) -> bool {
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;
while i < v.len() {
*sum0 += v[i];
@ -28,7 +28,7 @@ pure fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
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};
while i < v.len() {
sum0.f += v[i];
@ -39,7 +39,7 @@ pure fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
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};
while i < v.len() {
*sum0.f += v[i];

View file

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

View file

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

View file

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

View file

@ -13,10 +13,10 @@
enum foo { large, small, }
impl cmp::Eq for foo {
pure fn eq(&self, other: &foo) -> bool {
fn eq(&self, other: &foo) -> bool {
((*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() {

View file

@ -20,10 +20,10 @@ enum 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)
}
pure fn ne(&self, other: &color) -> bool { !(*self).eq(other) }
fn ne(&self, other: &color) -> bool { !(*self).eq(other) }
}
pub fn main() {

View file

@ -15,7 +15,7 @@
enum colour { red(int, int), green, }
impl cmp::Eq for colour {
pure fn eq(&self, other: &colour) -> bool {
fn eq(&self, other: &colour) -> bool {
match *self {
red(a0, b0) => {
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)); }

View file

@ -52,7 +52,7 @@ enum t {
}
impl cmp::Eq for t {
pure fn eq(&self, other: &t) -> bool {
fn eq(&self, other: &t) -> bool {
match *self {
tag1 => {
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() {

View file

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

View file

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

View file

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

View file

@ -10,7 +10,7 @@
// 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 test() {

View file

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