diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs index 6c35c62c3a7..a85ab1a29b7 100644 --- a/src/libcore/cell.rs +++ b/src/libcore/cell.rs @@ -30,7 +30,7 @@ pub pure fn empty_cell() -> Cell { pub impl Cell { /// Yields the value, failing if the cell is empty. - fn take() -> T { + fn take(&self) -> T { if self.is_empty() { fail!(~"attempt to take an empty cell"); } @@ -41,7 +41,7 @@ pub impl Cell { } /// Returns the value, failing if the cell is full. - fn put_back(value: T) { + fn put_back(&self, value: T) { if !self.is_empty() { fail!(~"attempt to put a value back into a full cell"); } @@ -49,12 +49,12 @@ pub impl Cell { } /// Returns true if the cell is empty and false if the cell is full. - pure fn is_empty() -> bool { + pure fn is_empty(&self) -> bool { self.value.is_none() } // Calls a closure with a reference to the value. - fn with_ref(op: fn(v: &T) -> R) -> R { + fn with_ref(&self, op: fn(v: &T) -> R) -> R { let v = self.take(); let r = op(&v); self.put_back(v); diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 94272f63e67..4f812a5ae76 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -24,31 +24,31 @@ pub use pipes::Selectable; /// A trait for things that can send multiple messages. pub trait GenericChan { /// Sends a message. - fn send(x: T); + fn send(&self, x: T); } /// Things that can send multiple messages and can detect when the receiver /// is closed pub trait GenericSmartChan { /// Sends a message, or report if the receiver has closed the connection. - fn try_send(x: T) -> bool; + fn try_send(&self, x: T) -> bool; } /// A trait for things that can receive multiple messages. pub trait GenericPort { /// Receives a message, or fails if the connection closes. - fn recv() -> T; + fn recv(&self) -> T; /** Receives a message, or returns `none` if the connection is closed or closes. */ - fn try_recv() -> Option; + fn try_recv(&self) -> Option; } /// Ports that can `peek` pub trait Peekable { /// Returns true if a message is available - pure fn peek() -> bool; + pure fn peek(&self) -> bool; } /// Returns the index of an endpoint that is ready to receive. @@ -105,7 +105,7 @@ pub fn stream() -> (Port, Chan) { } impl GenericChan for Chan { - fn send(x: T) { + fn send(&self, x: T) { let mut endp = None; endp <-> self.endp; self.endp = Some( @@ -115,7 +115,7 @@ impl GenericChan for Chan { impl GenericSmartChan for Chan { - fn try_send(x: T) -> bool { + fn try_send(&self, x: T) -> bool { let mut endp = None; endp <-> self.endp; match streamp::client::try_data(unwrap(endp), x) { @@ -129,7 +129,7 @@ impl GenericSmartChan for Chan { } impl GenericPort for Port { - fn recv() -> T { + fn recv(&self) -> T { let mut endp = None; endp <-> self.endp; let streamp::data(x, endp) = recv(unwrap(endp)); @@ -137,7 +137,7 @@ impl GenericPort for Port { x } - fn try_recv() -> Option { + fn try_recv(&self) -> Option { let mut endp = None; endp <-> self.endp; match try_recv(unwrap(endp)) { @@ -151,7 +151,7 @@ impl GenericPort for Port { } impl Peekable for Port { - pure fn peek() -> bool { + pure fn peek(&self) -> bool { unsafe { let mut endp = None; endp <-> self.endp; @@ -166,7 +166,7 @@ impl Peekable for Port { } impl Selectable for Port { - pure fn header() -> *PacketHeader { + pure fn header(&self) -> *PacketHeader { unsafe { match self.endp { Some(ref endp) => endp.header(), @@ -189,11 +189,11 @@ pub fn PortSet() -> PortSet{ pub impl PortSet { - fn add(port: Port) { + fn add(&self, port: Port) { self.ports.push(port) } - fn chan() -> Chan { + fn chan(&self) -> Chan { let (po, ch) = stream(); self.add(po); ch @@ -202,7 +202,7 @@ pub impl PortSet { impl GenericPort for PortSet { - fn try_recv() -> Option { + fn try_recv(&self) -> Option { let mut result = None; // we have to swap the ports array so we aren't borrowing // aliasable mutable memory. @@ -224,14 +224,14 @@ impl GenericPort for PortSet { result } - fn recv() -> T { + fn recv(&self) -> T { self.try_recv().expect("port_set: endpoints closed") } } impl Peekable for PortSet { - pure fn peek() -> bool { + pure fn peek(&self) -> bool { // It'd be nice to use self.port.each, but that version isn't // pure. for vec::each(self.ports) |p| { @@ -245,7 +245,7 @@ impl Peekable for PortSet { pub type SharedChan = unstable::Exclusive>; impl GenericChan for SharedChan { - fn send(x: T) { + fn send(&self, x: T) { let mut xx = Some(x); do self.with_imm |chan| { let mut x = None; @@ -256,7 +256,7 @@ impl GenericChan for SharedChan { } impl GenericSmartChan for SharedChan { - fn try_send(x: T) -> bool { + fn try_send(&self, x: T) -> bool { let mut xx = Some(x); do self.with_imm |chan| { let mut x = None; @@ -274,9 +274,9 @@ pub fn SharedChan(c: Chan) -> SharedChan { /// Receive a message from one of two endpoints. pub trait Select2 { /// Receive a message or return `None` if a connection closes. - fn try_select() -> Either, Option>; + fn try_select(&self) -> Either, Option>; /// Receive a message or fail if a connection closes. - fn select() -> Either; + fn select(&self) -> Either; } impl> Select2 for (Left, Right) { - fn select() -> Either { - match self { + fn select(&self) -> Either { + match *self { (ref lp, ref rp) => match select2i(lp, rp) { Left(()) => Left (lp.recv()), Right(()) => Right(rp.recv()) @@ -293,8 +293,8 @@ impl Either, Option> { - match self { + fn try_select(&self) -> Either, Option> { + match *self { (ref lp, ref rp) => match select2i(lp, rp) { Left(()) => Left (lp.try_recv()), Right(()) => Right(rp.try_recv()) diff --git a/src/libcore/condition.rs b/src/libcore/condition.rs index 00048beae5a..87752cff1bf 100644 --- a/src/libcore/condition.rs +++ b/src/libcore/condition.rs @@ -35,12 +35,12 @@ pub impl Condition { } } - fn raise(t: T) -> U { + fn raise(&self, t: T) -> U { let msg = fmt!("Unhandled condition: %s: %?", self.name, t); self.raise_default(t, || fail!(copy msg)) } - fn raise_default(t: T, default: &fn() -> U) -> U { + fn raise_default(&self, t: T, default: &fn() -> U) -> U { unsafe { match local_data_pop(self.key) { None => { diff --git a/src/libcore/dlist.rs b/src/libcore/dlist.rs index f1f4e558661..34a3c3e60af 100644 --- a/src/libcore/dlist.rs +++ b/src/libcore/dlist.rs @@ -148,7 +148,7 @@ priv impl DList { fail!(~"That node isn't on this dlist.") } } - fn make_mine(nobe: @mut DListNode) { + fn make_mine(&self, nobe: @mut DListNode) { if nobe.prev.is_some() || nobe.next.is_some() || nobe.linked { fail!(~"Cannot insert node that's already on a dlist!") } diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 7197de36404..2f87d05d8fe 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -83,7 +83,7 @@ pub pure fn unwrap(d: DVec) -> ~[A] { priv impl DVec { #[inline(always)] - pure fn check_not_borrowed() { + pure fn check_not_borrowed(&self) { unsafe { let data: *() = cast::reinterpret_cast(&self.data); if data.is_null() { @@ -93,7 +93,7 @@ priv impl DVec { } #[inline(always)] - fn give_back(data: ~[A]) { + fn give_back(&self, data: ~[A]) { unsafe { self.data = data; } @@ -120,7 +120,7 @@ pub impl DVec { } /// Reserves space for N elements - fn reserve(count: uint) { + fn reserve(&self, count: uint) { vec::reserve(&mut self.data, count) } @@ -130,26 +130,26 @@ pub impl DVec { * and return a new vector to replace it with. */ #[inline(always)] - fn swap(f: &fn(v: ~[A]) -> ~[A]) { + fn swap(&self, f: &fn(v: ~[A]) -> ~[A]) { self.check_out(|v| self.give_back(f(v))) } /// Returns the number of elements currently in the dvec #[inline(always)] - pure fn len() -> uint { + pure fn len(&self) -> uint { self.check_not_borrowed(); return self.data.len(); } /// Overwrite the current contents #[inline(always)] - fn set(w: ~[A]) { + fn set(&self, w: ~[A]) { self.check_not_borrowed(); self.data = w; } /// Remove and return the last element - fn pop() -> A { + fn pop(&self) -> A { do self.check_out |v| { let mut v = v; let result = v.pop(); @@ -159,7 +159,7 @@ pub impl DVec { } /// Insert a single item at the front of the list - fn unshift(t: A) { + fn unshift(&self, t: A) { unsafe { let mut data = cast::reinterpret_cast(&null::<()>()); data <-> self.data; @@ -172,13 +172,13 @@ pub impl DVec { /// Append a single item to the end of the list #[inline(always)] - fn push(t: A) { + fn push(&self, t: A) { self.check_not_borrowed(); self.data.push(t); } /// Remove and return the first element - fn shift() -> A { + fn shift(&self) -> A { do self.check_out |v| { let mut v = v; let result = v.shift(); @@ -188,7 +188,7 @@ pub impl DVec { } /// Reverse the elements in the list, in place - fn reverse() { + fn reverse(&self) { do self.check_out |v| { let mut v = v; vec::reverse(v); @@ -197,7 +197,7 @@ pub impl DVec { } /// Gives access to the vector as a slice with immutable contents - fn borrow(op: fn(x: &[A]) -> R) -> R { + fn borrow(&self, op: fn(x: &[A]) -> R) -> R { do self.check_out |v| { let result = op(v); self.give_back(v); @@ -206,7 +206,7 @@ pub impl DVec { } /// Gives access to the vector as a slice with mutable contents - fn borrow_mut(op: &fn(x: &mut [A]) -> R) -> R { + fn borrow_mut(&self, op: &fn(x: &mut [A]) -> R) -> R { do self.check_out |v| { let mut v = v; let result = op(v); @@ -222,12 +222,12 @@ pub impl DVec { * * Equivalent to `append_iter()` but potentially more efficient. */ - fn push_all(ts: &[const A]) { + fn push_all(&self, ts: &[const A]) { self.push_slice(ts, 0u, vec::len(ts)); } /// Appends elements from `from_idx` to `to_idx` (exclusive) - fn push_slice(ts: &[const A], from_idx: uint, to_idx: uint) { + fn push_slice(&self, ts: &[const A], from_idx: uint, to_idx: uint) { do self.swap |v| { let mut v = v; let new_len = vec::len(v) + to_idx - from_idx; @@ -271,7 +271,7 @@ pub impl DVec { * * See `unwrap()` if you do not wish to copy the contents. */ - pure fn get() -> ~[A] { + pure fn get(&self) -> ~[A] { unsafe { do self.check_out |v| { let w = copy v; @@ -283,13 +283,13 @@ pub impl DVec { /// Copy out an individual element #[inline(always)] - pure fn get_elt(idx: uint) -> A { + pure fn get_elt(&self, idx: uint) -> A { self.check_not_borrowed(); return self.data[idx]; } /// Overwrites the contents of the element at `idx` with `a` - fn set_elt(idx: uint, a: A) { + fn set_elt(&self, idx: uint, a: A) { self.check_not_borrowed(); self.data[idx] = a; } @@ -299,7 +299,7 @@ pub impl DVec { * growing the vector if necessary. New elements will be initialized * with `initval` */ - fn grow_set_elt(idx: uint, initval: &A, val: A) { + fn grow_set_elt(&self, idx: uint, initval: &A, val: A) { do self.swap |v| { let mut v = v; v.grow_set(idx, initval, val); @@ -309,7 +309,7 @@ pub impl DVec { /// Returns the last element, failing if the vector is empty #[inline(always)] - pure fn last() -> A { + pure fn last(&self) -> A { self.check_not_borrowed(); let length = self.len(); @@ -322,7 +322,7 @@ pub impl DVec { /// Iterates over the elements in reverse order #[inline(always)] - fn rev_each(f: fn(v: &A) -> bool) { + fn rev_each(&self, f: fn(v: &A) -> bool) { do self.swap |v| { // FIXME(#2263)---we should be able to write // `vec::rev_each(v, f);` but we cannot write now @@ -335,7 +335,7 @@ pub impl DVec { /// Iterates over the elements and indices in reverse order #[inline(always)] - fn rev_eachi(f: fn(uint, v: &A) -> bool) { + fn rev_eachi(&self, f: fn(uint, v: &A) -> bool) { do self.swap |v| { // FIXME(#2263)---we should be able to write // `vec::rev_eachi(v, f);` but we cannot write now diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index 4a1a1952907..39d86380bdc 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -51,32 +51,32 @@ pub trait Hash { * function and require most types to only implement the * IterBytes trait, that feeds SipHash. */ - pure fn hash_keyed(k0: u64, k1: u64) -> u64; + pure fn hash_keyed(&self, k0: u64, k1: u64) -> u64; } // When we have default methods, won't need this. pub trait HashUtil { - pure fn hash() -> u64; + pure fn hash(&self) -> u64; } impl HashUtil for A { #[inline(always)] - pure fn hash() -> u64 { self.hash_keyed(0,0) } + pure fn hash(&self) -> u64 { self.hash_keyed(0,0) } } /// Streaming hash-functions should implement this. pub trait Streaming { - fn input((&[const u8])); + fn input(&self, (&[const u8])); // These can be refactored some when we have default methods. - fn result_bytes() -> ~[u8]; + fn result_bytes(&self) -> ~[u8]; fn result_str() -> ~str; - fn result_u64() -> u64; - fn reset(); + fn result_u64(&self) -> u64; + fn reset(&self); } impl Hash for A { #[inline(always)] - pure fn hash_keyed(k0: u64, k1: u64) -> u64 { + pure fn hash_keyed(&self, k0: u64, k1: u64) -> u64 { unsafe { let s = &State(k0, k1); for self.iter_bytes(true) |bytes| { @@ -302,12 +302,12 @@ impl io::Writer for SipState { impl Streaming for &SipState { #[inline(always)] - fn input(buf: &[const u8]) { + fn input(&self, buf: &[const u8]) { self.write(buf); } #[inline(always)] - fn result_u64() -> u64 { + fn result_u64(&self) -> u64 { let mut v0 = self.v0; let mut v1 = self.v1; let mut v2 = self.v2; @@ -337,7 +337,7 @@ impl Streaming for &SipState { return (v0 ^ v1 ^ v2 ^ v3); } - fn result_bytes() -> ~[u8] { + fn result_bytes(&self) -> ~[u8] { let h = self.result_u64(); ~[(h >> 0) as u8, (h >> 8) as u8, @@ -350,6 +350,7 @@ impl Streaming for &SipState { ] } + // IMPLICIT SELF WARNING: fix me! fn result_str() -> ~str { let r = self.result_bytes(); let mut s = ~""; @@ -360,7 +361,7 @@ impl Streaming for &SipState { } #[inline(always)] - fn reset() { + fn reset(&self) { self.length = 0; self.v0 = self.k0 ^ 0x736f6d6570736575; self.v1 = self.k1 ^ 0x646f72616e646f6d; diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs index f888fbdb40c..e4b8d204dd7 100644 --- a/src/libcore/mutable.rs +++ b/src/libcore/mutable.rs @@ -44,7 +44,7 @@ pub fn unwrap(m: Mut) -> T { } pub impl Data { - fn borrow_mut(op: &fn(t: &mut T) -> R) -> R { + fn borrow_mut(&self, op: &fn(t: &mut T) -> R) -> R { match self.mode { Immutable => fail!(fmt!("%? currently immutable", self.value)), @@ -56,11 +56,11 @@ pub impl Data { } } - pure fn borrow_const(op: &fn(t: &const T) -> R) -> R { + pure fn borrow_const(&self, op: &fn(t: &const T) -> R) -> R { op(&const self.value) } - fn borrow_imm(op: &fn(t: &T) -> R) -> R { + fn borrow_imm(&self, op: &fn(t: &T) -> R) -> R { match self.mode { Mutable => fail!(fmt!("%? currently mutable", self.value)), diff --git a/src/libcore/path.rs b/src/libcore/path.rs index 8d528a11598..f621b140638 100644 --- a/src/libcore/path.rs +++ b/src/libcore/path.rs @@ -46,28 +46,28 @@ pub pure fn PosixPath(s: &str) -> PosixPath { pub trait GenericPath { static pure fn from_str(&str) -> Self; - pure fn dirname() -> ~str; - pure fn filename() -> Option<~str>; - pure fn filestem() -> Option<~str>; - pure fn filetype() -> Option<~str>; + pure fn dirname(&self) -> ~str; + pure fn filename(&self) -> Option<~str>; + pure fn filestem(&self) -> Option<~str>; + pure fn filetype(&self) -> Option<~str>; - pure fn with_dirname((&str)) -> Self; - pure fn with_filename((&str)) -> Self; - pure fn with_filestem((&str)) -> Self; - pure fn with_filetype((&str)) -> Self; + pure fn with_dirname(&self, (&str)) -> Self; + pure fn with_filename(&self, (&str)) -> Self; + pure fn with_filestem(&self, (&str)) -> Self; + pure fn with_filetype(&self, (&str)) -> Self; - pure fn dir_path() -> Self; - pure fn file_path() -> Self; + pure fn dir_path(&self) -> Self; + pure fn file_path(&self) -> Self; - pure fn push((&str)) -> Self; - pure fn push_rel((&Self)) -> Self; - pure fn push_many((&[~str])) -> Self; - pure fn pop() -> Self; + pure fn push(&self, (&str)) -> Self; + pure fn push_rel(&self, (&Self)) -> Self; + pure fn push_many(&self, (&[~str])) -> Self; + pure fn pop(&self) -> Self; - pure fn unsafe_join((&Self)) -> Self; - pure fn is_restricted() -> bool; + pure fn unsafe_join(&self, (&Self)) -> Self; + pure fn is_restricted(&self) -> bool; - pure fn normalize() -> Self; + pure fn normalize(&self) -> Self; } #[cfg(windows)] @@ -388,7 +388,7 @@ impl GenericPath for PosixPath { components: components } } - pure fn dirname() -> ~str { + pure fn dirname(&self) -> ~str { unsafe { let s = self.dir_path().to_str(); if s.len() == 0 { @@ -399,14 +399,14 @@ impl GenericPath for PosixPath { } } - pure fn filename() -> Option<~str> { + pure fn filename(&self) -> Option<~str> { match self.components.len() { 0 => None, n => Some(copy self.components[n - 1]) } } - pure fn filestem() -> Option<~str> { + pure fn filestem(&self) -> Option<~str> { match self.filename() { None => None, Some(ref f) => { @@ -418,7 +418,7 @@ impl GenericPath for PosixPath { } } - pure fn filetype() -> Option<~str> { + pure fn filetype(&self) -> Option<~str> { match self.filename() { None => None, Some(ref f) => { @@ -430,7 +430,7 @@ impl GenericPath for PosixPath { } } - pure fn with_dirname(d: &str) -> PosixPath { + pure fn with_dirname(&self, d: &str) -> PosixPath { let dpath = PosixPath(d); match self.filename() { Some(ref f) => dpath.push(*f), @@ -438,24 +438,24 @@ impl GenericPath for PosixPath { } } - pure fn with_filename(f: &str) -> PosixPath { + pure fn with_filename(&self, f: &str) -> PosixPath { unsafe { assert ! str::any(f, |c| windows::is_sep(c as u8)); self.dir_path().push(f) } } - pure fn with_filestem(s: &str) -> PosixPath { + pure fn with_filestem(&self, s: &str) -> PosixPath { match self.filetype() { None => self.with_filename(s), Some(ref t) => self.with_filename(str::from_slice(s) + *t) } } - pure fn with_filetype(t: &str) -> PosixPath { + pure fn with_filetype(&self, t: &str) -> PosixPath { if t.len() == 0 { match self.filestem() { - None => copy self, + None => copy *self, Some(ref s) => self.with_filename(*s) } } else { @@ -467,15 +467,15 @@ impl GenericPath for PosixPath { } } - pure fn dir_path() -> PosixPath { + pure fn dir_path(&self) -> PosixPath { if self.components.len() != 0 { self.pop() } else { - copy self + copy *self } } - pure fn file_path() -> PosixPath { + pure fn file_path(&self) -> PosixPath { let cs = match self.filename() { None => ~[], Some(ref f) => ~[copy *f] @@ -484,12 +484,12 @@ impl GenericPath for PosixPath { components: cs } } - pure fn push_rel(other: &PosixPath) -> PosixPath { + pure fn push_rel(&self, other: &PosixPath) -> PosixPath { assert !other.is_absolute; self.push_many(other.components) } - pure fn unsafe_join(other: &PosixPath) -> PosixPath { + pure fn unsafe_join(&self, other: &PosixPath) -> PosixPath { if other.is_absolute { PosixPath { is_absolute: true, components: copy other.components } @@ -498,11 +498,11 @@ impl GenericPath for PosixPath { } } - pure fn is_restricted() -> bool { + pure fn is_restricted(&self) -> bool { false } - pure fn push_many(cs: &[~str]) -> PosixPath { + pure fn push_many(&self, cs: &[~str]) -> PosixPath { let mut v = copy self.components; for cs.each |e| { let mut ss = str::split_nonempty( @@ -514,14 +514,14 @@ impl GenericPath for PosixPath { components: v } } - pure fn push(s: &str) -> PosixPath { + pure fn push(&self, s: &str) -> PosixPath { let mut v = copy self.components; let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8)); unsafe { v.push_all_move(ss); } - PosixPath { components: v, ..copy self } + PosixPath { components: v, ..copy *self } } - pure fn pop() -> PosixPath { + pure fn pop(&self) -> PosixPath { let mut cs = copy self.components; if cs.len() != 0 { unsafe { cs.pop(); } @@ -533,7 +533,7 @@ impl GenericPath for PosixPath { //..self } } - pure fn normalize() -> PosixPath { + pure fn normalize(&self) -> PosixPath { return PosixPath { is_absolute: self.is_absolute, components: normalize(self.components) @@ -600,7 +600,7 @@ impl GenericPath for WindowsPath { components: components } } - pure fn dirname() -> ~str { + pure fn dirname(&self) -> ~str { unsafe { let s = self.dir_path().to_str(); if s.len() == 0 { @@ -611,14 +611,14 @@ impl GenericPath for WindowsPath { } } - pure fn filename() -> Option<~str> { + pure fn filename(&self) -> Option<~str> { match self.components.len() { 0 => None, n => Some(copy self.components[n - 1]) } } - pure fn filestem() -> Option<~str> { + pure fn filestem(&self) -> Option<~str> { match self.filename() { None => None, Some(ref f) => { @@ -630,7 +630,7 @@ impl GenericPath for WindowsPath { } } - pure fn filetype() -> Option<~str> { + pure fn filetype(&self) -> Option<~str> { match self.filename() { None => None, Some(ref f) => { @@ -642,7 +642,7 @@ impl GenericPath for WindowsPath { } } - pure fn with_dirname(d: &str) -> WindowsPath { + pure fn with_dirname(&self, d: &str) -> WindowsPath { let dpath = WindowsPath(d); match self.filename() { Some(ref f) => dpath.push(*f), @@ -650,22 +650,22 @@ impl GenericPath for WindowsPath { } } - pure fn with_filename(f: &str) -> WindowsPath { + pure fn with_filename(&self, f: &str) -> WindowsPath { assert ! str::any(f, |c| windows::is_sep(c as u8)); self.dir_path().push(f) } - pure fn with_filestem(s: &str) -> WindowsPath { + pure fn with_filestem(&self, s: &str) -> WindowsPath { match self.filetype() { None => self.with_filename(s), Some(ref t) => self.with_filename(str::from_slice(s) + *t) } } - pure fn with_filetype(t: &str) -> WindowsPath { + pure fn with_filetype(&self, t: &str) -> WindowsPath { if t.len() == 0 { match self.filestem() { - None => copy self, + None => copy *self, Some(ref s) => self.with_filename(*s) } } else { @@ -678,15 +678,15 @@ impl GenericPath for WindowsPath { } } - pure fn dir_path() -> WindowsPath { + pure fn dir_path(&self) -> WindowsPath { if self.components.len() != 0 { self.pop() } else { - copy self + copy *self } } - pure fn file_path() -> WindowsPath { + pure fn file_path(&self) -> WindowsPath { let cs = match self.filename() { None => ~[], Some(ref f) => ~[copy *f] @@ -697,12 +697,12 @@ impl GenericPath for WindowsPath { components: cs } } - pure fn push_rel(other: &WindowsPath) -> WindowsPath { + pure fn push_rel(&self, other: &WindowsPath) -> WindowsPath { assert !other.is_absolute; self.push_many(other.components) } - pure fn unsafe_join(other: &WindowsPath) -> WindowsPath { + pure fn unsafe_join(&self, other: &WindowsPath) -> WindowsPath { /* rhs not absolute is simple push */ if !other.is_absolute { return self.push_many(other.components); @@ -744,7 +744,7 @@ impl GenericPath for WindowsPath { } } - pure fn is_restricted() -> bool { + pure fn is_restricted(&self) -> bool { match self.filestem() { Some(stem) => { match stem.to_lower() { @@ -757,7 +757,7 @@ impl GenericPath for WindowsPath { } } - pure fn push_many(cs: &[~str]) -> WindowsPath { + pure fn push_many(&self, cs: &[~str]) -> WindowsPath { let mut v = copy self.components; for cs.each |e| { let mut ss = str::split_nonempty( @@ -774,14 +774,14 @@ impl GenericPath for WindowsPath { } } - pure fn push(s: &str) -> WindowsPath { + pure fn push(&self, s: &str) -> WindowsPath { let mut v = copy self.components; let mut ss = str::split_nonempty(s, |c| windows::is_sep(c as u8)); unsafe { v.push_all_move(ss); } - return WindowsPath { components: v, ..copy self } + return WindowsPath { components: v, ..copy *self } } - pure fn pop() -> WindowsPath { + pure fn pop(&self) -> WindowsPath { let mut cs = copy self.components; if cs.len() != 0 { unsafe { cs.pop(); } @@ -794,7 +794,7 @@ impl GenericPath for WindowsPath { } } - pure fn normalize() -> WindowsPath { + pure fn normalize(&self) -> WindowsPath { return WindowsPath { host: copy self.host, device: match self.device { diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index e4fc9528f23..1bbd5b06776 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -160,14 +160,14 @@ pub fn PacketHeader() -> PacketHeader { pub impl PacketHeader { // Returns the old state. - unsafe fn mark_blocked(this: *rust_task) -> State { + unsafe fn mark_blocked(&self, this: *rust_task) -> State { rustrt::rust_task_ref(this); let old_task = swap_task(&mut self.blocked_task, this); assert old_task.is_null(); swap_state_acq(&mut self.state, Blocked) } - unsafe fn unblock() { + unsafe fn unblock(&self) { let old_task = swap_task(&mut self.blocked_task, ptr::null()); if !old_task.is_null() { unsafe { @@ -184,12 +184,12 @@ pub impl PacketHeader { // unsafe because this can do weird things to the space/time // continuum. It ends making multiple unique pointers to the same // thing. You'll proobably want to forget them when you're done. - unsafe fn buf_header() -> ~BufferHeader { + unsafe fn buf_header(&self) -> ~BufferHeader { assert self.buffer.is_not_null(); reinterpret_cast(&self.buffer) } - fn set_buffer(b: ~Buffer) { + fn set_buffer(&self, b: ~Buffer) { unsafe { self.buffer = reinterpret_cast(&b); } @@ -204,11 +204,11 @@ pub struct Packet { #[doc(hidden)] pub trait HasBuffer { - fn set_buffer(b: *libc::c_void); + fn set_buffer(&self, b: *libc::c_void); } impl HasBuffer for Packet { - fn set_buffer(b: *libc::c_void) { + fn set_buffer(&self, b: *libc::c_void) { self.header.buffer = b; } } @@ -717,11 +717,11 @@ pub fn select2( #[doc(hidden)] pub trait Selectable { - pure fn header() -> *PacketHeader; + pure fn header(&self) -> *PacketHeader; } impl Selectable for *PacketHeader { - pure fn header() -> *PacketHeader { self } + pure fn header(&self) -> *PacketHeader { *self } } /// Returns the index of an endpoint that is ready to receive. @@ -799,13 +799,13 @@ pub fn SendPacketBuffered(p: *Packet) } pub impl SendPacketBuffered { - fn unwrap() -> *Packet { + fn unwrap(&self) -> *Packet { let mut p = None; p <-> self.p; option::unwrap(p) } - pure fn header() -> *PacketHeader { + pure fn header(&self) -> *PacketHeader { match self.p { Some(packet) => unsafe { let packet = &*packet; @@ -817,7 +817,7 @@ pub impl SendPacketBuffered { } } - fn reuse_buffer() -> BufferResource { + fn reuse_buffer(&self) -> BufferResource { //error!("send reuse_buffer"); let mut tmp = None; tmp <-> self.buffer; @@ -856,13 +856,13 @@ impl ::ops::Drop for RecvPacketBuffered { } pub impl RecvPacketBuffered { - fn unwrap() -> *Packet { + fn unwrap(&self) -> *Packet { let mut p = None; p <-> self.p; option::unwrap(p) } - fn reuse_buffer() -> BufferResource { + fn reuse_buffer(&self) -> BufferResource { //error!("recv reuse_buffer"); let mut tmp = None; tmp <-> self.buffer; @@ -871,7 +871,7 @@ pub impl RecvPacketBuffered { } impl Selectable for RecvPacketBuffered { - pure fn header() -> *PacketHeader { + pure fn header(&self) -> *PacketHeader { match self.p { Some(packet) => unsafe { let packet = &*packet; diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index ecbce18e6da..1352615767e 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -175,39 +175,39 @@ pub pure fn ref_eq(thing: &a/T, other: &b/T) -> bool { } pub trait Ptr { - pure fn is_null() -> bool; - pure fn is_not_null() -> bool; - pure fn offset(count: uint) -> Self; + pure fn is_null(&self) -> bool; + pure fn is_not_null(&self) -> bool; + pure fn offset(&self, count: uint) -> Self; } /// Extension methods for immutable pointers impl Ptr for *T { /// Returns true if the pointer is equal to the null pointer. #[inline(always)] - pure fn is_null() -> bool { is_null(self) } + pure fn is_null(&self) -> bool { is_null(*self) } /// Returns true if the pointer is not equal to the null pointer. #[inline(always)] - pure fn is_not_null() -> bool { is_not_null(self) } + pure fn is_not_null(&self) -> bool { is_not_null(*self) } /// Calculates the offset from a pointer. #[inline(always)] - pure fn offset(count: uint) -> *T { offset(self, count) } + pure fn offset(&self, count: uint) -> *T { offset(*self, count) } } /// Extension methods for mutable pointers impl Ptr for *mut T { /// Returns true if the pointer is equal to the null pointer. #[inline(always)] - pure fn is_null() -> bool { is_null(self) } + pure fn is_null(&self) -> bool { is_null(*self) } /// Returns true if the pointer is not equal to the null pointer. #[inline(always)] - pure fn is_not_null() -> bool { is_not_null(self) } + pure fn is_not_null(&self) -> bool { is_not_null(*self) } /// Calculates the offset from a mutable pointer. #[inline(always)] - pure fn offset(count: uint) -> *mut T { mut_offset(self, count) } + pure fn offset(&self, count: uint) -> *mut T { mut_offset(*self, count) } } // Equality for pointers diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index d9c2b91fb97..377bf5bf4e7 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -131,7 +131,7 @@ extern mod rustrt { /// A random number generator pub trait Rng { /// Return the next random integer - fn next() -> u32; + fn next(&self) -> u32; } /// A value with a particular weight compared to other values @@ -143,12 +143,12 @@ pub struct Weighted { /// Extension methods for random number generators pub impl Rng { /// Return a random value for a Rand type - fn gen() -> T { - Rand::rand(self) + fn gen(&self) -> T { + Rand::rand(*self) } /// Return a random int - fn gen_int() -> int { + fn gen_int(&self) -> int { self.gen_i64() as int } @@ -156,33 +156,33 @@ pub impl Rng { * Return an int randomly chosen from the range [start, end), * failing if start >= end */ - fn gen_int_range(start: int, end: int) -> int { + fn gen_int_range(&self, start: int, end: int) -> int { assert start < end; start + int::abs(self.gen_int() % (end - start)) } /// Return a random i8 - fn gen_i8() -> i8 { + fn gen_i8(&self) -> i8 { self.next() as i8 } /// Return a random i16 - fn gen_i16() -> i16 { + fn gen_i16(&self) -> i16 { self.next() as i16 } /// Return a random i32 - fn gen_i32() -> i32 { + fn gen_i32(&self) -> i32 { self.next() as i32 } /// Return a random i64 - fn gen_i64() -> i64 { + fn gen_i64(&self) -> i64 { (self.next() as i64 << 32) | self.next() as i64 } /// Return a random uint - fn gen_uint() -> uint { + fn gen_uint(&self) -> uint { self.gen_u64() as uint } @@ -190,43 +190,43 @@ pub impl Rng { * Return a uint randomly chosen from the range [start, end), * failing if start >= end */ - fn gen_uint_range(start: uint, end: uint) -> uint { + fn gen_uint_range(&self, start: uint, end: uint) -> uint { assert start < end; start + (self.gen_uint() % (end - start)) } /// Return a random u8 - fn gen_u8() -> u8 { + fn gen_u8(&self) -> u8 { self.next() as u8 } /// Return a random u16 - fn gen_u16() -> u16 { + fn gen_u16(&self) -> u16 { self.next() as u16 } /// Return a random u32 - fn gen_u32() -> u32 { + fn gen_u32(&self) -> u32 { self.next() } /// Return a random u64 - fn gen_u64() -> u64 { + fn gen_u64(&self) -> u64 { (self.next() as u64 << 32) | self.next() as u64 } /// Return a random float in the interval [0,1] - fn gen_float() -> float { + fn gen_float(&self) -> float { self.gen_f64() as float } /// Return a random f32 in the interval [0,1] - fn gen_f32() -> f32 { + fn gen_f32(&self) -> f32 { self.gen_f64() as f32 } /// Return a random f64 in the interval [0,1] - fn gen_f64() -> f64 { + fn gen_f64(&self) -> f64 { let u1 = self.next() as f64; let u2 = self.next() as f64; let u3 = self.next() as f64; @@ -235,25 +235,25 @@ pub impl Rng { } /// Return a random char - fn gen_char() -> char { + fn gen_char(&self) -> char { self.next() as char } /** * Return a char randomly chosen from chars, failing if chars is empty */ - fn gen_char_from(chars: &str) -> char { + fn gen_char_from(&self, chars: &str) -> char { assert !chars.is_empty(); self.choose(str::chars(chars)) } /// Return a random bool - fn gen_bool() -> bool { + fn gen_bool(&self) -> bool { self.next() & 1u32 == 1u32 } /// Return a bool with a 1 in n chance of true - fn gen_weighted_bool(n: uint) -> bool { + fn gen_weighted_bool(&self, n: uint) -> bool { if n == 0u { true } else { @@ -264,7 +264,7 @@ pub impl Rng { /** * Return a random string of the specified length composed of A-Z,a-z,0-9 */ - fn gen_str(len: uint) -> ~str { + fn gen_str(&self, len: uint) -> ~str { let charset = ~"ABCDEFGHIJKLMNOPQRSTUVWXYZ\ abcdefghijklmnopqrstuvwxyz\ 0123456789"; @@ -278,19 +278,19 @@ pub impl Rng { } /// Return a random byte string of the specified length - fn gen_bytes(len: uint) -> ~[u8] { + fn gen_bytes(&self, len: uint) -> ~[u8] { do vec::from_fn(len) |_i| { self.gen_u8() } } /// Choose an item randomly, failing if values is empty - fn choose(values: &[T]) -> T { + fn choose(&self, values: &[T]) -> T { self.choose_option(values).get() } /// Choose Some(item) randomly, returning None if values is empty - fn choose_option(values: &[T]) -> Option { + fn choose_option(&self, values: &[T]) -> Option { if values.is_empty() { None } else { @@ -302,7 +302,7 @@ pub impl Rng { * Choose an item respecting the relative weights, failing if the sum of * the weights is 0 */ - fn choose_weighted(v : &[Weighted]) -> T { + fn choose_weighted(&self, v : &[Weighted]) -> T { self.choose_weighted_option(v).get() } @@ -310,7 +310,7 @@ pub impl Rng { * Choose Some(item) respecting the relative weights, returning none if * the sum of the weights is 0 */ - fn choose_weighted_option(v: &[Weighted]) -> Option { + fn choose_weighted_option(&self, v: &[Weighted]) -> Option { let mut total = 0u; for v.each |item| { total += item.weight; @@ -333,7 +333,7 @@ pub impl Rng { * Return a vec containing copies of the items, in order, where * the weight of the item determines how many copies there are */ - fn weighted_vec(v: &[Weighted]) -> ~[T] { + fn weighted_vec(&self, v: &[Weighted]) -> ~[T] { let mut r = ~[]; for v.each |item| { for uint::range(0u, item.weight) |_i| { @@ -344,14 +344,14 @@ pub impl Rng { } /// Shuffle a vec - fn shuffle(values: &[T]) -> ~[T] { + fn shuffle(&self, values: &[T]) -> ~[T] { let mut m = vec::from_slice(values); self.shuffle_mut(m); m } /// Shuffle a mutable vec in place - fn shuffle_mut(values: &mut [T]) { + fn shuffle_mut(&self, values: &mut [T]) { let mut i = values.len(); while i >= 2u { // invariant: elements with index >= i have been locked in place. @@ -382,7 +382,7 @@ fn RandRes(rng: *rust_rng) -> RandRes { } impl Rng for @RandRes { - fn next() -> u32 { + fn next(&self) -> u32 { unsafe { return rustrt::rand_next((*self).rng); } @@ -432,7 +432,7 @@ struct XorShiftState { } impl Rng for XorShiftState { - fn next() -> u32 { + fn next(&self) -> u32 { let x = self.x; let mut t = x ^ (x << 11); self.x = self.y; diff --git a/src/libcore/reflect.rs b/src/libcore/reflect.rs index 06ae4eb17a5..f29447ef53e 100644 --- a/src/libcore/reflect.rs +++ b/src/libcore/reflect.rs @@ -26,9 +26,9 @@ use vec; * then build a MovePtrAdaptor wrapped around your struct. */ pub trait MovePtr { - fn move_ptr(adjustment: fn(*c_void) -> *c_void); - fn push_ptr(); - fn pop_ptr(); + fn move_ptr(&self, adjustment: fn(*c_void) -> *c_void); + fn push_ptr(&self); + fn pop_ptr(&self); } /// Helper function for alignment calculation. @@ -47,26 +47,26 @@ pub fn MovePtrAdaptor(v: V) -> MovePtrAdaptor { pub impl MovePtrAdaptor { #[inline(always)] - fn bump(sz: uint) { + fn bump(&self, sz: uint) { do self.inner.move_ptr() |p| { ((p as uint) + sz) as *c_void }; } #[inline(always)] - fn align(a: uint) { + fn align(&self, a: uint) { do self.inner.move_ptr() |p| { align(p as uint, a) as *c_void }; } #[inline(always)] - fn align_to() { + fn align_to(&self) { self.align(sys::min_align_of::()); } #[inline(always)] - fn bump_past() { + fn bump_past(&self) { self.bump(sys::size_of::()); } } diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index af135339b2e..17d0cb4ea98 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -43,11 +43,11 @@ pub use managed::raw::BoxRepr; /// Helpers trait EscapedCharWriter { - fn write_escaped_char(ch: char); + fn write_escaped_char(&self, ch: char); } impl EscapedCharWriter for Writer { - fn write_escaped_char(ch: char) { + fn write_escaped_char(&self, ch: char) { match ch { '\t' => self.write_str("\\t"), '\r' => self.write_str("\\r"), @@ -68,68 +68,76 @@ impl EscapedCharWriter for Writer { /// Representations trait Repr { - fn write_repr(writer: @Writer); + fn write_repr(&self, writer: @Writer); } impl Repr for () { - fn write_repr(writer: @Writer) { writer.write_str("()"); } + fn write_repr(&self, writer: @Writer) { writer.write_str("()"); } } impl Repr for bool { - fn write_repr(writer: @Writer) { - writer.write_str(if self { "true" } else { "false" }) + fn write_repr(&self, writer: @Writer) { + writer.write_str(if *self { "true" } else { "false" }) } } impl Repr for int { - fn write_repr(writer: @Writer) { writer.write_int(self); } + fn write_repr(&self, writer: @Writer) { writer.write_int(*self); } } impl Repr for i8 { - fn write_repr(writer: @Writer) { writer.write_int(self as int); } + fn write_repr(&self, writer: @Writer) { writer.write_int(*self as int); } } impl Repr for i16 { - fn write_repr(writer: @Writer) { writer.write_int(self as int); } + fn write_repr(&self, writer: @Writer) { writer.write_int(*self as int); } } impl Repr for i32 { - fn write_repr(writer: @Writer) { writer.write_int(self as int); } + fn write_repr(&self, writer: @Writer) { writer.write_int(*self as int); } } impl Repr for i64 { // FIXME #4424: This can lose precision. - fn write_repr(writer: @Writer) { writer.write_int(self as int); } + fn write_repr(&self, writer: @Writer) { writer.write_int(*self as int); } } impl Repr for uint { - fn write_repr(writer: @Writer) { writer.write_uint(self); } + fn write_repr(&self, writer: @Writer) { writer.write_uint(*self); } } impl Repr for u8 { - fn write_repr(writer: @Writer) { writer.write_uint(self as uint); } + fn write_repr(&self, writer: @Writer) { + writer.write_uint(*self as uint); + } } impl Repr for u16 { - fn write_repr(writer: @Writer) { writer.write_uint(self as uint); } + fn write_repr(&self, writer: @Writer) { + writer.write_uint(*self as uint); + } } impl Repr for u32 { - fn write_repr(writer: @Writer) { writer.write_uint(self as uint); } + fn write_repr(&self, writer: @Writer) { + writer.write_uint(*self as uint); + } } impl Repr for u64 { // FIXME #4424: This can lose precision. - fn write_repr(writer: @Writer) { writer.write_uint(self as uint); } + fn write_repr(&self, writer: @Writer) { + writer.write_uint(*self as uint); + } } impl Repr for float { // FIXME #4423: This mallocs. - fn write_repr(writer: @Writer) { writer.write_str(self.to_str()); } + fn write_repr(&self, writer: @Writer) { writer.write_str(self.to_str()); } } impl Repr for f32 { // FIXME #4423 This mallocs. - fn write_repr(writer: @Writer) { writer.write_str(self.to_str()); } + fn write_repr(&self, writer: @Writer) { writer.write_str(self.to_str()); } } impl Repr for f64 { // FIXME #4423: This mallocs. - fn write_repr(writer: @Writer) { writer.write_str(self.to_str()); } + fn write_repr(&self, writer: @Writer) { writer.write_str(self.to_str()); } } impl Repr for char { - fn write_repr(writer: @Writer) { writer.write_char(self); } + fn write_repr(&self, writer: @Writer) { writer.write_char(*self); } } @@ -156,13 +164,13 @@ pub fn ReprVisitor(ptr: *c_void, writer: @Writer) -> ReprVisitor { impl MovePtr for ReprVisitor { #[inline(always)] - fn move_ptr(adjustment: fn(*c_void) -> *c_void) { + fn move_ptr(&self, adjustment: fn(*c_void) -> *c_void) { self.ptr = adjustment(self.ptr); } - fn push_ptr() { + fn push_ptr(&self) { self.ptr_stk.push(self.ptr); } - fn pop_ptr() { + fn pop_ptr(&self) { self.ptr = self.ptr_stk.pop(); } } @@ -172,7 +180,7 @@ pub impl ReprVisitor { // Various helpers for the TyVisitor impl #[inline(always)] - fn get(f: fn(&T)) -> bool { + fn get(&self, f: fn(&T)) -> bool { unsafe { f(transmute::<*c_void,&T>(copy self.ptr)); } @@ -180,24 +188,24 @@ pub impl ReprVisitor { } #[inline(always)] - fn bump(sz: uint) { + fn bump(&self, sz: uint) { do self.move_ptr() |p| { ((p as uint) + sz) as *c_void }; } #[inline(always)] - fn bump_past() { + fn bump_past(&self) { self.bump(sys::size_of::()); } #[inline(always)] - fn visit_inner(inner: *TyDesc) -> bool { + fn visit_inner(&self, inner: *TyDesc) -> bool { self.visit_ptr_inner(self.ptr, inner) } #[inline(always)] - fn visit_ptr_inner(ptr: *c_void, inner: *TyDesc) -> bool { + fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool { unsafe { let mut u = ReprVisitor(ptr, self.writer); let v = reflect::MovePtrAdaptor(u); @@ -207,13 +215,13 @@ pub impl ReprVisitor { } #[inline(always)] - fn write() -> bool { + fn write(&self) -> bool { do self.get |v:&T| { v.write_repr(self.writer); } } - fn write_escaped_slice(slice: &str) { + fn write_escaped_slice(&self, slice: &str) { self.writer.write_char('"'); for str::chars_each(slice) |ch| { self.writer.write_escaped_char(ch); @@ -221,7 +229,7 @@ pub impl ReprVisitor { self.writer.write_char('"'); } - fn write_mut_qualifier(mtbl: uint) { + fn write_mut_qualifier(&self, mtbl: uint) { if mtbl == 0 { self.writer.write_str("mut "); } else if mtbl == 1 { @@ -232,7 +240,7 @@ pub impl ReprVisitor { } } - fn write_vec_range(mtbl: uint, ptr: *u8, len: uint, + fn write_vec_range(&self, mtbl: uint, ptr: *u8, len: uint, inner: *TyDesc) -> bool { let mut p = ptr; let end = ptr::offset(p, len); @@ -253,7 +261,7 @@ pub impl ReprVisitor { true } - fn write_unboxed_vec_repr(mtbl: uint, v: &UnboxedVecRepr, + fn write_unboxed_vec_repr(&self, mtbl: uint, v: &UnboxedVecRepr, inner: *TyDesc) -> bool { self.write_vec_range(mtbl, ptr::to_unsafe_ptr(&v.data), v.fill, inner) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index f1e23f01e7b..950c9627ec6 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -2198,22 +2198,22 @@ pub mod raw { } pub trait Trimmable { - pure fn trim() -> Self; - pure fn trim_left() -> Self; - pure fn trim_right() -> Self; + pure fn trim(&self) -> Self; + pure fn trim_left(&self) -> Self; + pure fn trim_right(&self) -> Self; } /// Extension methods for strings impl Trimmable for ~str { /// Returns a string with leading and trailing whitespace removed #[inline] - pure fn trim() -> ~str { trim(self) } + pure fn trim(&self) -> ~str { trim(*self) } /// Returns a string with leading whitespace removed #[inline] - pure fn trim_left() -> ~str { trim_left(self) } + pure fn trim_left(&self) -> ~str { trim_left(*self) } /// Returns a string with trailing whitespace removed #[inline] - pure fn trim_right() -> ~str { trim_right(self) } + pure fn trim_right(&self) -> ~str { trim_right(*self) } } #[cfg(notest)] @@ -2233,35 +2233,35 @@ pub mod traits { pub mod traits {} pub trait StrSlice { - pure fn all(it: fn(char) -> bool) -> bool; - pure fn any(it: fn(char) -> bool) -> bool; - pure fn contains(needle: &a/str) -> bool; - pure fn contains_char(needle: char) -> bool; - pure fn each(it: fn(u8) -> bool); - pure fn eachi(it: fn(uint, u8) -> bool); - pure fn each_char(it: fn(char) -> bool); - pure fn each_chari(it: fn(uint, char) -> bool); - pure fn ends_with(needle: &str) -> bool; - pure fn is_empty() -> bool; - pure fn is_whitespace() -> bool; - pure fn is_alphanumeric() -> bool; - pure fn len() -> uint; - pure fn slice(begin: uint, end: uint) -> ~str; - pure fn split(sepfn: fn(char) -> bool) -> ~[~str]; - pure fn split_char(sep: char) -> ~[~str]; - pure fn split_str(sep: &a/str) -> ~[~str]; - pure fn starts_with(needle: &a/str) -> bool; - pure fn substr(begin: uint, n: uint) -> ~str; - pure fn to_lower() -> ~str; - pure fn to_upper() -> ~str; - pure fn escape_default() -> ~str; - pure fn escape_unicode() -> ~str; - pure fn trim() -> ~str; - pure fn trim_left() -> ~str; - pure fn trim_right() -> ~str; - pure fn to_owned() -> ~str; - pure fn to_managed() -> @str; - pure fn char_at(i: uint) -> char; + pure fn all(&self, it: fn(char) -> bool) -> bool; + pure fn any(&self, it: fn(char) -> bool) -> bool; + pure fn contains(&self, needle: &a/str) -> bool; + pure fn contains_char(&self, needle: char) -> bool; + pure fn each(&self, it: fn(u8) -> bool); + pure fn eachi(&self, it: fn(uint, u8) -> bool); + pure fn each_char(&self, it: fn(char) -> bool); + pure fn each_chari(&self, it: fn(uint, char) -> bool); + pure fn ends_with(&self, needle: &str) -> bool; + pure fn is_empty(&self) -> bool; + pure fn is_whitespace(&self) -> bool; + pure fn is_alphanumeric(&self) -> bool; + pure fn len(&self) -> uint; + pure fn slice(&self, begin: uint, end: uint) -> ~str; + pure fn split(&self, sepfn: fn(char) -> bool) -> ~[~str]; + pure fn split_char(&self, sep: char) -> ~[~str]; + pure fn split_str(&self, sep: &a/str) -> ~[~str]; + pure fn starts_with(&self, needle: &a/str) -> bool; + pure fn substr(&self, begin: uint, n: uint) -> ~str; + pure fn to_lower(&self) -> ~str; + pure fn to_upper(&self) -> ~str; + pure fn escape_default(&self) -> ~str; + pure fn escape_unicode(&self) -> ~str; + pure fn trim(&self) -> ~str; + pure fn trim_left(&self) -> ~str; + pure fn trim_right(&self) -> ~str; + pure fn to_owned(&self) -> ~str; + pure fn to_managed(&self) -> @str; + pure fn char_at(&self, i: uint) -> char; } /// Extension methods for strings @@ -2271,56 +2271,62 @@ impl StrSlice for &str { * contains no characters */ #[inline] - pure fn all(it: fn(char) -> bool) -> bool { all(self, it) } + pure fn all(&self, it: fn(char) -> bool) -> bool { all(*self, it) } /** * Return true if a predicate matches any character (and false if it * matches none or there are no characters) */ #[inline] - pure fn any(it: fn(char) -> bool) -> bool { any(self, it) } + pure fn any(&self, it: fn(char) -> bool) -> bool { any(*self, it) } /// Returns true if one string contains another #[inline] - pure fn contains(needle: &a/str) -> bool { contains(self, needle) } + pure fn contains(&self, needle: &a/str) -> bool { + contains(*self, needle) + } /// Returns true if a string contains a char #[inline] - pure fn contains_char(needle: char) -> bool { - contains_char(self, needle) + pure fn contains_char(&self, needle: char) -> bool { + contains_char(*self, needle) } /// Iterate over the bytes in a string #[inline] - pure fn each(it: fn(u8) -> bool) { each(self, it) } + pure fn each(&self, it: fn(u8) -> bool) { each(*self, it) } /// Iterate over the bytes in a string, with indices #[inline] - pure fn eachi(it: fn(uint, u8) -> bool) { eachi(self, it) } + pure fn eachi(&self, it: fn(uint, u8) -> bool) { eachi(*self, it) } /// Iterate over the chars in a string #[inline] - pure fn each_char(it: fn(char) -> bool) { each_char(self, it) } + pure fn each_char(&self, it: fn(char) -> bool) { each_char(*self, it) } /// Iterate over the chars in a string, with indices #[inline] - pure fn each_chari(it: fn(uint, char) -> bool) { each_chari(self, it) } + pure fn each_chari(&self, it: fn(uint, char) -> bool) { + each_chari(*self, it) + } /// Returns true if one string ends with another #[inline] - pure fn ends_with(needle: &str) -> bool { ends_with(self, needle) } + pure fn ends_with(&self, needle: &str) -> bool { + ends_with(*self, needle) + } /// Returns true if the string has length 0 #[inline] - pure fn is_empty() -> bool { is_empty(self) } + pure fn is_empty(&self) -> bool { is_empty(*self) } /** * Returns true if the string contains only whitespace * * Whitespace characters are determined by `char::is_whitespace` */ #[inline] - pure fn is_whitespace() -> bool { is_whitespace(self) } + pure fn is_whitespace(&self) -> bool { is_whitespace(*self) } /** * Returns true if the string contains only alphanumerics * * Alphanumeric characters are determined by `char::is_alphanumeric` */ #[inline] - pure fn is_alphanumeric() -> bool { is_alphanumeric(self) } + pure fn is_alphanumeric(&self) -> bool { is_alphanumeric(*self) } #[inline] /// Returns the size in bytes not counting the null terminator - pure fn len() -> uint { len(self) } + pure fn len(&self) -> uint { len(*self) } /** * Returns a slice of the given string from the byte range * [`begin`..`end`) @@ -2329,24 +2335,30 @@ impl StrSlice for &str { * beyond the last character of the string */ #[inline] - pure fn slice(begin: uint, end: uint) -> ~str { slice(self, begin, end) } + pure fn slice(&self, begin: uint, end: uint) -> ~str { + slice(*self, begin, end) + } /// Splits a string into substrings using a character function #[inline] - pure fn split(sepfn: fn(char) -> bool) -> ~[~str] { split(self, sepfn) } + pure fn split(&self, sepfn: fn(char) -> bool) -> ~[~str] { + split(*self, sepfn) + } /** * Splits a string into substrings at each occurrence of a given character */ #[inline] - pure fn split_char(sep: char) -> ~[~str] { split_char(self, sep) } + pure fn split_char(&self, sep: char) -> ~[~str] { split_char(*self, sep) } /** * Splits a string into a vector of the substrings separated by a given * string */ #[inline] - pure fn split_str(sep: &a/str) -> ~[~str] { split_str(self, sep) } + pure fn split_str(&self, sep: &a/str) -> ~[~str] { split_str(*self, sep) } /// Returns true if one string starts with another #[inline] - pure fn starts_with(needle: &a/str) -> bool { starts_with(self, needle) } + pure fn starts_with(&self, needle: &a/str) -> bool { + starts_with(*self, needle) + } /** * Take a substring of another. * @@ -2354,35 +2366,37 @@ impl StrSlice for &str { * `begin`. */ #[inline] - pure fn substr(begin: uint, n: uint) -> ~str { substr(self, begin, n) } + pure fn substr(&self, begin: uint, n: uint) -> ~str { + substr(*self, begin, n) + } /// Convert a string to lowercase #[inline] - pure fn to_lower() -> ~str { to_lower(self) } + pure fn to_lower(&self) -> ~str { to_lower(*self) } /// Convert a string to uppercase #[inline] - pure fn to_upper() -> ~str { to_upper(self) } + pure fn to_upper(&self) -> ~str { to_upper(*self) } /// Escape each char in `s` with char::escape_default. #[inline] - pure fn escape_default() -> ~str { escape_default(self) } + pure fn escape_default(&self) -> ~str { escape_default(*self) } /// Escape each char in `s` with char::escape_unicode. #[inline] - pure fn escape_unicode() -> ~str { escape_unicode(self) } + pure fn escape_unicode(&self) -> ~str { escape_unicode(*self) } /// Returns a string with leading and trailing whitespace removed #[inline] - pure fn trim() -> ~str { trim(self) } + pure fn trim(&self) -> ~str { trim(*self) } /// Returns a string with leading whitespace removed #[inline] - pure fn trim_left() -> ~str { trim_left(self) } + pure fn trim_left(&self) -> ~str { trim_left(*self) } /// Returns a string with trailing whitespace removed #[inline] - pure fn trim_right() -> ~str { trim_right(self) } + pure fn trim_right(&self) -> ~str { trim_right(*self) } #[inline] - pure fn to_owned() -> ~str { self.slice(0, self.len()) } + pure fn to_owned(&self) -> ~str { self.slice(0, self.len()) } #[inline] - pure fn to_managed() -> @str { + pure fn to_managed(&self) -> @str { let v = at_vec::from_fn(self.len() + 1, |i| { if i == self.len() { 0 } else { self[i] } }); @@ -2390,7 +2404,7 @@ impl StrSlice for &str { } #[inline] - pure fn char_at(i: uint) -> char { char_at(self, i) } + pure fn char_at(&self, i: uint) -> char { char_at(*self, i) } } pub trait OwnedStr { diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index 0835d4400ed..4a9d4056cab 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -212,7 +212,7 @@ pub fn task() -> TaskBuilder { #[doc(hidden)] // FIXME #3538 priv impl TaskBuilder { - fn consume() -> TaskBuilder { + fn consume(&self) -> TaskBuilder { if self.consumed { fail!(~"Cannot copy a task_builder"); // Fake move mode on self } @@ -237,7 +237,7 @@ pub impl TaskBuilder { * Decouple the child task's failure from the parent's. If either fails, * the other will not be killed. */ - fn unlinked() -> TaskBuilder { + fn unlinked(&self) -> TaskBuilder { let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { opts: TaskOpts { @@ -255,7 +255,7 @@ pub impl TaskBuilder { * child's failure will not kill the parent, but the parent's will kill * the child. */ - fn supervised() -> TaskBuilder { + fn supervised(&self) -> TaskBuilder { let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { opts: TaskOpts { @@ -272,7 +272,7 @@ pub impl TaskBuilder { * Link the child task's and parent task's failures. If either fails, the * other will be killed. */ - fn linked() -> TaskBuilder { + fn linked(&self) -> TaskBuilder { let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { opts: TaskOpts { @@ -303,7 +303,7 @@ pub impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - fn future_result(blk: fn(v: Port)) -> TaskBuilder { + fn future_result(&self, blk: fn(v: Port)) -> TaskBuilder { // FIXME (#3725): Once linked failure and notification are // handled in the library, I can imagine implementing this by just // registering an arbitrary number of task::on_exit handlers and @@ -331,7 +331,7 @@ pub impl TaskBuilder { } } /// Configure a custom scheduler mode for the task. - fn sched_mode(mode: SchedMode) -> TaskBuilder { + fn sched_mode(&self, mode: SchedMode) -> TaskBuilder { let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { opts: TaskOpts { @@ -357,7 +357,7 @@ pub impl TaskBuilder { * generator by applying the task body which results from the * existing body generator to the new body generator. */ - fn add_wrapper(wrapper: @fn(v: ~fn()) -> ~fn()) -> TaskBuilder { + fn add_wrapper(&self, wrapper: @fn(v: ~fn()) -> ~fn()) -> TaskBuilder { let prev_gen_body = self.gen_body; let notify_chan = replace(&mut self.opts.notify_chan, None); TaskBuilder { @@ -385,7 +385,7 @@ pub impl TaskBuilder { * When spawning into a new scheduler, the number of threads requested * must be greater than zero. */ - fn spawn(f: ~fn()) { + fn spawn(&self, f: ~fn()) { let notify_chan = replace(&mut self.opts.notify_chan, None); let x = self.consume(); let opts = TaskOpts { @@ -397,7 +397,7 @@ pub impl TaskBuilder { spawn::spawn_raw(opts, (x.gen_body)(f)); } /// Runs a task, while transfering ownership of one argument to the child. - fn spawn_with(arg: A, f: ~fn(v: A)) { + fn spawn_with(&self, arg: A, f: ~fn(v: A)) { let arg = Cell(arg); do self.spawn { f(arg.take()); @@ -417,7 +417,7 @@ pub impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - fn try(f: ~fn() -> T) -> Result { + fn try(&self, f: ~fn() -> T) -> Result { let (po, ch) = stream::(); let mut result = None; diff --git a/src/libcore/tuple.rs b/src/libcore/tuple.rs index dde7d718c13..faa2636ed4e 100644 --- a/src/libcore/tuple.rs +++ b/src/libcore/tuple.rs @@ -15,31 +15,31 @@ use kinds::Copy; use vec; pub trait CopyableTuple { - pure fn first() -> T; - pure fn second() -> U; - pure fn swap() -> (U, T); + pure fn first(&self) -> T; + pure fn second(&self) -> U; + pure fn swap(&self) -> (U, T); } impl CopyableTuple for (T, U) { /// Return the first element of self #[inline(always)] - pure fn first() -> T { - let (t, _) = self; + pure fn first(&self) -> T { + let (t, _) = *self; return t; } /// Return the second element of self #[inline(always)] - pure fn second() -> U { - let (_, u) = self; + pure fn second(&self) -> U { + let (_, u) = *self; return u; } /// Return the results of swapping the two elements of self #[inline(always)] - pure fn swap() -> (U, T) { - let (t, u) = self; + pure fn swap(&self) -> (U, T) { + let (t, u) = *self; return (u, t); } diff --git a/src/libcore/unstable/extfmt.rs b/src/libcore/unstable/extfmt.rs index 616d37a133a..bfbd1669341 100644 --- a/src/libcore/unstable/extfmt.rs +++ b/src/libcore/unstable/extfmt.rs @@ -143,7 +143,7 @@ pub mod ct { } pub impl Parsed { - static pure fn new(val: T, next: uint) -> Parsed { + static pure fn new(&self, val: T, next: uint) -> Parsed { Parsed {val: val, next: next} } } diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index 02875739eba..14a37ecbf52 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -26,35 +26,35 @@ pub struct DuplexStream { } impl GenericChan for DuplexStream { - fn send(x: T) { + fn send(&self, x: T) { self.chan.send(x) } } impl GenericSmartChan for DuplexStream { - fn try_send(x: T) -> bool { + fn try_send(&self, x: T) -> bool { self.chan.try_send(x) } } impl GenericPort for DuplexStream { - fn recv() -> U { + fn recv(&self) -> U { self.port.recv() } - fn try_recv() -> Option { + fn try_recv(&self) -> Option { self.port.try_recv() } } impl Peekable for DuplexStream { - pure fn peek() -> bool { + pure fn peek(&self) -> bool { self.port.peek() } } impl Selectable for DuplexStream { - pure fn header() -> *pipes::PacketHeader { + pure fn header(&self) -> *pipes::PacketHeader { self.port.header() } } diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 42f954f7c39..b89396436c5 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -259,13 +259,13 @@ pub trait ByteChan { const CONTINUE: [u8 * 4] = [0xAA, 0xBB, 0xCC, 0xDD]; impl,P:BytePort> GenericPort for FlatPort { - fn recv() -> T { + fn recv(&self) -> T { match self.try_recv() { Some(val) => val, None => fail!(~"port is closed") } } - fn try_recv() -> Option { + fn try_recv(&self) -> Option { let command = match self.byte_port.try_recv(CONTINUE.len()) { Some(c) => c, None => { @@ -304,7 +304,7 @@ impl,P:BytePort> GenericPort for FlatPort { } impl,C:ByteChan> GenericChan for FlatChan { - fn send(val: T) { + fn send(&self, val: T) { self.byte_chan.send(CONTINUE.to_vec()); let bytes = self.flattener.flatten(val); let len = bytes.len() as u64;