}
impl ToStr for cat {
- pure fn to_str(&self) -> ~str { copy self.name }
+ fn to_str(&self) -> ~str { copy self.name }
}
priv impl cat {
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 }
}
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 }
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 }
}
}
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; }
}
}
}
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 } }
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;
}
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
}
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
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
}
}
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) { }
}
struct foo(~uint);
impl Add<foo, foo> for foo {
- pure fn add(f: &foo) -> foo {
+ fn add(f: &foo) -> foo {
foo(~(**self + **(*f)))
}
}
}
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)
}
}
trait methods {
fn impurem(&self);
fn blockm(&self, f: &fn());
- pure fn purem(&self);
+ fn purem(&self);
}
impl methods for point {
fn blockm(&self, f: &fn()) { f() }
- pure fn purem(&self) {
+ fn purem(&self) {
}
}
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() {}
}
pub impl Obj {
- pure fn boom() -> bool {
+ fn boom() -> bool {
return 1+1 == 2
}
- pure fn chirp() {
+ fn chirp() {
self.boom(); //~ ERROR wat
}
}
}
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}
}
}
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() {
Point { x: x, y: y }
}
- pure fn to_str(&self) -> ~str {
+ fn to_str(&self) -> ~str {
fmt!("(%f, %f)", self.x, self.y)
}
}
// except according to those terms.
trait MyEq {
- pure fn eq(&self, other: &Self) -> bool;
+ fn eq(&self, other: &Self) -> bool;
}
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
// error-pattern:test
-pure fn f() {
+fn f() {
fail!(~"test");
}
// 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); }
}
impl cmp::Eq for Expr {
- pure fn eq(&self, other: &Expr) -> bool {
+ fn eq(&self, other: &Expr) -> bool {
match *self {
Val(e0a) => {
match *other {
}
}
}
- 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 {
},
}
}
- 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]
// 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() {
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
}
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; }
}
}
- 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> {
}
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;};
}
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 {
}
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 }
}
}
}
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()
-pure fn negate(x: &int) -> int {
+fn negate(x: &int) -> int {
-*x
}
}
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 {
// 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;
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) }
}
}
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 };
// 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 { }
}
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) {
*
* 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 }
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; }
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() {
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() {
// 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); }
}
impl to_str::ToStr for square {
- pure fn to_str(&self) -> ~str {
+ fn to_str(&self) -> ~str {
match *self {
bot => { ~"R" }
wall => { ~"#" }
// 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,
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()
}
}
// 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)};
// 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);
}
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 } }
}
impl ToStr for Thingy {
- pure fn to_str(&self) -> ~str {
+ fn to_str(&self) -> ~str {
fmt!("{ x: %d, y: %d }", self.x, self.y)
}
}
}
impl<T:ToStr> ToStr for PolymorphicThingy<T> {
- pure fn to_str(&self) -> ~str {
+ fn to_str(&self) -> ~str {
self.x.to_str()
}
}
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));
}
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() {
// 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() { }
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,
// 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];
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];
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];
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];
// except according to those terms.
-fn something(f: &pure fn()) { f(); }
+fn something(f: &fn()) { f(); }
pub fn main() {
something(|| error!("hi!") );
}
// 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)
}
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() {
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() {
}
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() {
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) {
}
}
}
- 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)); }
}
impl cmp::Eq for t {
- pure fn eq(&self, other: &t) -> bool {
+ fn eq(&self, other: &t) -> bool {
match *self {
tag1 => {
match (*other) {
}
}
}
- pure fn ne(&self, other: &t) -> bool { !(*self).eq(other) }
+ fn ne(&self, other: &t) -> bool { !(*self).eq(other) }
}
fn test_tag() {
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;
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));
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));
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;
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));
// 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> { }
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;
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));
mod base {
pub trait HasNew<T> {
- pure fn new() -> T;
+ fn new() -> T;
}
pub struct Foo {
}
impl ::base::HasNew<Foo> for Foo {
- pure fn new() -> Foo {
+ fn new() -> Foo {
unsafe { io::println("Foo"); }
Foo { dummy: () }
}
}
impl ::base::HasNew<Bar> for Bar {
- pure fn new() -> Bar {
+ fn new() -> Bar {
unsafe { io::println("Bar"); }
Bar { dummy: () }
}
// 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() {
}
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));