From 1e52eede31a1df3627bfa9f43b9d06c730895c01 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 31 May 2013 11:31:38 -0700 Subject: [PATCH 1/2] librustc: Don't require `pub extern` to make extern functions visible --- src/librustc/middle/privacy.rs | 2 +- src/test/run-pass/pub-extern-privacy.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/pub-extern-privacy.rs diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 5f88c25653d60..0f00e9d596e17 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -200,7 +200,7 @@ pub fn check_crate(tcx: ty::ctxt, f = |item_id| { match tcx.items.find(&item_id) { Some(&node_item(item, _)) => item.vis != public, - Some(&node_foreign_item(_, _, vis, _)) => vis != public, + Some(&node_foreign_item(*)) => false, Some(&node_method(method, impl_did, _)) => { match method.vis { private => true, diff --git a/src/test/run-pass/pub-extern-privacy.rs b/src/test/run-pass/pub-extern-privacy.rs new file mode 100644 index 0000000000000..2927279f6a29e --- /dev/null +++ b/src/test/run-pass/pub-extern-privacy.rs @@ -0,0 +1,14 @@ +use std::cast::transmute; + +mod a { + extern { + pub fn free(x: *u8); + } +} + +fn main() { + unsafe { + a::free(transmute(0)); + } +} + From 5fb254695b4db9af3d8e33577fae28ae9f7006c5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 31 May 2013 15:17:22 -0700 Subject: [PATCH 2/2] Remove all uses of `pub impl`. rs=style --- src/libextra/arc.rs | 74 +- src/libextra/arena.rs | 20 +- src/libextra/bitv.rs | 153 ++-- src/libextra/comm.rs | 14 +- src/libextra/deque.rs | 26 +- src/libextra/dlist.rs | 104 ++- src/libextra/ebml.rs | 49 +- src/libextra/flatpipes.rs | 40 +- src/libextra/future.rs | 8 +- src/libextra/json.rs | 8 +- src/libextra/net_tcp.rs | 6 +- src/libextra/net_url.rs | 23 +- src/libextra/num/bigint.rs | 8 +- src/libextra/priority_queue.rs | 39 +- src/libextra/rc.rs | 14 +- src/libextra/smallintmap.rs | 23 +- src/libextra/sync.rs | 75 +- src/libextra/task_pool.rs | 12 +- src/libextra/test.rs | 9 +- src/libextra/time.rs | 22 +- src/libextra/treemap.rs | 23 +- src/libextra/workcache.rs | 63 +- src/librustc/driver/session.rs | 86 +-- src/librustc/middle/astencode.rs | 10 +- src/librustc/middle/borrowck/check_loans.rs | 90 +-- .../middle/borrowck/gather_loans/mod.rs | 63 +- src/librustc/middle/borrowck/mod.rs | 110 +-- src/librustc/middle/lang_items.rs | 27 +- src/librustc/middle/liveness.rs | 235 ++++--- src/librustc/middle/mem_categorization.rs | 143 ++-- src/librustc/middle/moves.rs | 74 +- src/librustc/middle/region.rs | 94 +-- src/librustc/middle/resolve.rs | 656 +++++++++--------- src/librustc/middle/trans/cabi.rs | 42 +- src/librustc/middle/trans/closure.rs | 8 +- src/librustc/middle/trans/common.rs | 41 +- src/librustc/middle/trans/datum.rs | 188 ++--- src/librustc/middle/trans/expr.rs | 4 +- src/librustc/middle/trans/reflect.rs | 38 +- src/librustc/middle/trans/tvec.rs | 4 +- src/librustc/middle/ty.rs | 74 +- src/librustc/middle/typeck/check/method.rs | 155 ++--- src/librustc/middle/typeck/check/mod.rs | 170 ++--- src/librustc/middle/typeck/check/regionck.rs | 10 +- src/librustc/middle/typeck/check/vtable.rs | 4 +- src/librustc/middle/typeck/coherence.rs | 116 ++-- src/librustc/middle/typeck/infer/coercion.rs | 92 +-- src/librustc/middle/typeck/infer/lattice.rs | 78 +-- src/librustc/middle/typeck/infer/lub.rs | 9 +- src/librustc/middle/typeck/infer/mod.rs | 114 +-- .../middle/typeck/infer/region_inference.rs | 146 ++-- src/librustc/middle/typeck/infer/resolve.rs | 23 +- src/librustc/middle/typeck/infer/test.rs | 46 +- src/librustc/middle/typeck/infer/unify.rs | 56 +- src/librustc/util/enum_set.rs | 20 +- src/librustdoc/doc.rs | 26 +- src/librustdoc/prune_private_pass.rs | 10 +- src/librustdoc/sort_item_type_pass.rs | 2 +- src/librustpkg/rustpkg.rc | 13 +- src/librustpkg/util.rs | 8 +- src/libstd/cell.rs | 18 +- src/libstd/comm.rs | 24 +- src/libstd/condition.rs | 12 +- src/libstd/either.rs | 18 +- src/libstd/hashmap.rs | 50 +- src/libstd/option.rs | 58 +- src/libstd/path.rs | 32 +- src/libstd/pipes.rs | 24 +- src/libstd/rand.rs | 22 +- src/libstd/reflect.rs | 18 +- src/libstd/repr.rs | 32 +- src/libstd/result.rs | 34 +- src/libstd/rt/context.rs | 8 +- src/libstd/rt/sched.rs | 51 +- src/libstd/rt/stack.rs | 10 +- src/libstd/rt/thread.rs | 4 +- src/libstd/rt/uv/idle.rs | 15 +- src/libstd/rt/uv/mod.rs | 17 +- src/libstd/rt/uv/net.rs | 34 +- src/libstd/rt/uv/uvio.rs | 11 +- src/libstd/rt/uvio.rs | 10 +- src/libstd/rt/work_queue.rs | 12 +- src/libstd/run.rs | 43 +- src/libstd/str/ascii.rs | 14 +- src/libstd/task/mod.rs | 22 +- src/libstd/trie.rs | 24 +- src/libstd/unstable/extfmt.rs | 4 +- src/libstd/unstable/sync.rs | 10 +- src/libstd/util.rs | 4 +- src/libsyntax/abi.rs | 42 +- src/libsyntax/ast.rs | 8 +- src/libsyntax/ast_util.rs | 14 +- src/libsyntax/codemap.rs | 26 +- src/libsyntax/ext/base.rs | 51 +- src/libsyntax/ext/deriving/ty.rs | 59 +- src/libsyntax/ext/pipes/proto.rs | 60 +- src/libsyntax/parse/common.rs | 96 ++- src/libsyntax/parse/obsolete.rs | 27 +- src/libsyntax/parse/parser.rs | 219 +++--- src/libsyntax/parse/token.rs | 19 +- src/libsyntax/print/pp.rs | 43 +- src/libsyntax/util/interner.rs | 34 +- .../auxiliary/anon_trait_static_method_lib.rs | 4 +- src/test/auxiliary/cci_class_2.rs | 4 +- src/test/auxiliary/cci_class_3.rs | 6 +- src/test/auxiliary/cci_class_4.rs | 10 +- src/test/auxiliary/cci_class_5.rs | 4 +- src/test/auxiliary/cci_class_6.rs | 7 +- src/test/auxiliary/cci_class_cast.rs | 8 +- src/test/auxiliary/impl_privacy_xc_1.rs | 4 +- src/test/auxiliary/issue_2472_b.rs | 4 +- src/test/bench/core-set.rs | 6 +- src/test/bench/noise.rs | 18 +- src/test/bench/sudoku.rs | 2 +- src/test/compile-fail/assign-to-method.rs | 5 +- .../borrowck-auto-mut-ref-to-immut-var.rs | 4 +- .../compile-fail/borrowck-autoref-3261.rs | 5 +- ...borrowck-call-method-from-mut-aliasable.rs | 8 +- .../borrowck-insert-during-each.rs | 10 +- .../borrowck-loan-rcvr-overloaded-op.rs | 4 +- src/test/compile-fail/class-cast-to-trait.rs | 7 +- src/test/compile-fail/class-missing-self.rs | 2 +- src/test/compile-fail/issue-2356.rs | 4 +- src/test/compile-fail/issue-2766-a.rs | 2 +- src/test/compile-fail/issue-3021-b.rs | 4 +- src/test/compile-fail/issue-3080.rs | 4 +- src/test/compile-fail/issue-3707.rs | 6 +- src/test/compile-fail/issue-3763.rs | 2 +- .../compile-fail/mutable-class-fields-2.rs | 4 +- src/test/compile-fail/private-impl-method.rs | 2 +- src/test/compile-fail/private-method.rs | 2 +- src/test/compile-fail/regions-addr-of-self.rs | 6 +- .../regions-addr-of-upvar-self.rs | 4 +- .../compile-fail/regions-glb-free-free.rs | 4 +- .../compile-fail/trait-or-new-type-instead.rs | 4 +- .../use-after-move-self-based-on-type.rs | 6 +- src/test/compile-fail/use-after-move-self.rs | 6 +- src/test/run-pass/anon-trait-static-method.rs | 4 +- src/test/run-pass/auto-ref-newtype.rs | 4 +- .../autoderef-and-borrow-method-receiver.rs | 4 +- src/test/run-pass/borrowck-nested-calls.rs | 6 +- .../borrowck-wg-borrow-mut-to-imm-3.rs | 4 +- .../class-cast-to-trait-multiple-types.rs | 8 +- src/test/run-pass/class-cast-to-trait.rs | 6 +- src/test/run-pass/class-exports.rs | 4 +- .../class-impl-very-parameterized-trait.rs | 14 +- .../class-implement-trait-cross-crate.rs | 6 +- src/test/run-pass/class-implement-traits.rs | 6 +- src/test/run-pass/class-methods.rs | 6 +- src/test/run-pass/class-poly-methods.rs | 6 +- src/test/run-pass/class-separate-impl.rs | 8 +- src/test/run-pass/class-typarams.rs | 6 +- src/test/run-pass/classes-simple-method.rs | 4 +- src/test/run-pass/classes.rs | 8 +- .../run-pass/coerce-reborrow-imm-ptr-rcvr.rs | 4 +- .../run-pass/coerce-reborrow-mut-ptr-rcvr.rs | 4 +- src/test/run-pass/const-enum-byref-self.rs | 4 +- src/test/run-pass/explicit-self-closures.rs | 6 +- src/test/run-pass/explicit-self-generic.rs | 4 +- src/test/run-pass/explicit-self.rs | 18 +- src/test/run-pass/impl-implicit-trait.rs | 8 +- src/test/run-pass/issue-2311-2.rs | 4 +- src/test/run-pass/issue-2312.rs | 4 +- src/test/run-pass/issue-2445-b.rs | 8 +- src/test/run-pass/issue-2445.rs | 8 +- src/test/run-pass/issue-2487-a.rs | 4 +- src/test/run-pass/issue-2502.rs | 4 +- src/test/run-pass/issue-2718.rs | 8 +- src/test/run-pass/issue-3220.rs | 5 +- src/test/run-pass/issue-3447.rs | 4 +- src/test/run-pass/issue-3753.rs | 2 +- src/test/run-pass/issue-3860.rs | 4 +- src/test/run-pass/issue-3904.rs | 4 +- src/test/run-pass/max-min-classes.rs | 4 +- src/test/run-pass/move-self.rs | 6 +- src/test/run-pass/nested-class.rs | 4 +- src/test/run-pass/private-class-field.rs | 4 +- src/test/run-pass/private-method.rs | 6 +- src/test/run-pass/reflect-visit-data.rs | 16 +- src/test/run-pass/regions-expl-self.rs | 6 +- src/test/run-pass/resource-destruct.rs | 4 +- 181 files changed, 2890 insertions(+), 2784 deletions(-) diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index 1de2003aa99d5..f4259afcaa3c1 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -56,10 +56,10 @@ pub struct Condvar<'self> { cond: &'self sync::Condvar<'self> } -pub impl<'self> Condvar<'self> { +impl<'self> Condvar<'self> { /// Atomically exit the associated ARC and block until a signal is sent. #[inline(always)] - fn wait(&self) { self.wait_on(0) } + pub fn wait(&self) { self.wait_on(0) } /** * Atomically exit the associated ARC and block on a specified condvar @@ -68,7 +68,7 @@ pub impl<'self> Condvar<'self> { * wait() is equivalent to wait_on(0). */ #[inline(always)] - fn wait_on(&self, condvar_id: uint) { + pub fn wait_on(&self, condvar_id: uint) { assert!(!*self.failed); self.cond.wait_on(condvar_id); // This is why we need to wrap sync::condvar. @@ -77,28 +77,28 @@ pub impl<'self> Condvar<'self> { /// Wake up a blocked task. Returns false if there was no blocked task. #[inline(always)] - fn signal(&self) -> bool { self.signal_on(0) } + pub fn signal(&self) -> bool { self.signal_on(0) } /** * Wake up a blocked task on a specified condvar (as * sync::cond.signal_on). Returns false if there was no blocked task. */ #[inline(always)] - fn signal_on(&self, condvar_id: uint) -> bool { + pub fn signal_on(&self, condvar_id: uint) -> bool { assert!(!*self.failed); self.cond.signal_on(condvar_id) } /// Wake up all blocked tasks. Returns the number of tasks woken. #[inline(always)] - fn broadcast(&self) -> uint { self.broadcast_on(0) } + pub fn broadcast(&self) -> uint { self.broadcast_on(0) } /** * Wake up all blocked tasks on a specified condvar (as * sync::cond.broadcast_on). Returns Returns the number of tasks woken. */ #[inline(always)] - fn broadcast_on(&self, condvar_id: uint) -> uint { + pub fn broadcast_on(&self, condvar_id: uint) -> uint { assert!(!*self.failed); self.cond.broadcast_on(condvar_id) } @@ -120,8 +120,8 @@ pub fn ARC(data: T) -> ARC { * Access the underlying data in an atomically reference counted * wrapper. */ -pub impl ARC { - fn get<'a>(&'a self) -> &'a T { +impl ARC { + pub fn get<'a>(&'a self) -> &'a T { unsafe { &*self.x.get_immut() } } } @@ -173,7 +173,7 @@ impl Clone for MutexARC { } } -pub impl MutexARC { +impl MutexARC { /** * Access the underlying mutable data with mutual exclusion from other @@ -199,7 +199,7 @@ pub impl MutexARC { * blocked on the mutex) will also fail immediately. */ #[inline(always)] - unsafe fn access(&self, blk: &fn(x: &mut T) -> U) -> U { + pub unsafe fn access(&self, blk: &fn(x: &mut T) -> U) -> U { unsafe { let state = self.x.get(); // Borrowck would complain about this if the function were @@ -214,10 +214,10 @@ pub impl MutexARC { /// As access(), but with a condvar, as sync::mutex.lock_cond(). #[inline(always)] - unsafe fn access_cond<'x, 'c, U>( - &self, - blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) -> U - { + pub unsafe fn access_cond<'x, 'c, U>(&self, + blk: &fn(x: &'x mut T, + c: &'c Condvar) -> U) + -> U { let state = self.x.get(); do (&(*state).lock).lock_cond |cond| { check_poison(true, (*state).failed); @@ -302,16 +302,18 @@ pub fn rw_arc_with_condvars( RWARC { x: UnsafeAtomicRcBox::new(data), cant_nest: () } } -pub impl RWARC { +impl RWARC { /// Duplicate a rwlock-protected ARC, as arc::clone. - fn clone(&self) -> RWARC { - RWARC { x: self.x.clone(), - cant_nest: () } + pub fn clone(&self) -> RWARC { + RWARC { + x: self.x.clone(), + cant_nest: (), + } } } -pub impl RWARC { +impl RWARC { /** * Access the underlying data mutably. Locks the rwlock in write mode; * other readers and writers will block. @@ -323,7 +325,7 @@ pub impl RWARC { * poison the ARC, so subsequent readers and writers will both also fail. */ #[inline(always)] - fn write(&self, blk: &fn(x: &mut T) -> U) -> U { + pub fn write(&self, blk: &fn(x: &mut T) -> U) -> U { unsafe { let state = self.x.get(); do (*borrow_rwlock(state)).write { @@ -333,11 +335,12 @@ pub impl RWARC { } } } + /// As write(), but with a condvar, as sync::rwlock.write_cond(). #[inline(always)] - fn write_cond<'x, 'c, U>(&self, - blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) - -> U { + pub fn write_cond<'x, 'c, U>(&self, + blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) + -> U { unsafe { let state = self.x.get(); do (*borrow_rwlock(state)).write_cond |cond| { @@ -350,6 +353,7 @@ pub impl RWARC { } } } + /** * Access the underlying data immutably. May run concurrently with other * reading tasks. @@ -359,7 +363,7 @@ pub impl RWARC { * Failing will unlock the ARC while unwinding. However, unlike all other * access modes, this will not poison the ARC. */ - fn read(&self, blk: &fn(x: &T) -> U) -> U { + pub fn read(&self, blk: &fn(x: &T) -> U) -> U { unsafe { let state = self.x.get(); do (*state).lock.read { @@ -389,7 +393,7 @@ pub impl RWARC { * } * ~~~ */ - fn write_downgrade(&self, blk: &fn(v: RWWriteMode) -> U) -> U { + pub fn write_downgrade(&self, blk: &fn(v: RWWriteMode) -> U) -> U { unsafe { let state = self.x.get(); do (*borrow_rwlock(state)).write_downgrade |write_mode| { @@ -404,7 +408,8 @@ pub impl RWARC { } /// To be called inside of the write_downgrade block. - fn downgrade<'a>(&self, token: RWWriteMode<'a, T>) -> RWReadMode<'a, T> { + pub fn downgrade<'a>(&self, token: RWWriteMode<'a, T>) + -> RWReadMode<'a, T> { unsafe { // The rwlock should assert that the token belongs to us for us. let state = self.x.get(); @@ -451,9 +456,9 @@ pub struct RWReadMode<'self, T> { token: sync::RWlockReadMode<'self>, } -pub impl<'self, T:Const + Owned> RWWriteMode<'self, T> { +impl<'self, T:Const + Owned> RWWriteMode<'self, T> { /// Access the pre-downgrade RWARC in write mode. - fn write(&mut self, blk: &fn(x: &mut T) -> U) -> U { + pub fn write(&mut self, blk: &fn(x: &mut T) -> U) -> U { match *self { RWWriteMode { data: &ref mut data, @@ -466,10 +471,11 @@ pub impl<'self, T:Const + Owned> RWWriteMode<'self, T> { } } } + /// Access the pre-downgrade RWARC in write mode with a condvar. - fn write_cond<'x, 'c, U>(&mut self, - blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) - -> U { + pub fn write_cond<'x, 'c, U>(&mut self, + blk: &fn(x: &'x mut T, c: &'c Condvar) -> U) + -> U { match *self { RWWriteMode { data: &ref mut data, @@ -491,9 +497,9 @@ pub impl<'self, T:Const + Owned> RWWriteMode<'self, T> { } } -pub impl<'self, T:Const + Owned> RWReadMode<'self, T> { +impl<'self, T:Const + Owned> RWReadMode<'self, T> { /// Access the post-downgrade rwlock in read mode. - fn read(&self, blk: &fn(x: &T) -> U) -> U { + pub fn read(&self, blk: &fn(x: &T) -> U) -> U { match *self { RWReadMode { data: data, diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index 7cd63cd03b1aa..57c2152490fb6 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -166,9 +166,9 @@ unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) { (transmute(p & !1), p & 1 == 1) } -pub impl Arena { +impl Arena { // Functions for the POD part of the arena - priv fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 { + fn alloc_pod_grow(&mut self, n_bytes: uint, align: uint) -> *u8 { // Allocate a new chunk. let chunk_size = at_vec::capacity(self.pod_head.data); let new_min_chunk_size = uint::max(n_bytes, chunk_size); @@ -180,7 +180,7 @@ pub impl Arena { } #[inline(always)] - priv fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 { + fn alloc_pod_inner(&mut self, n_bytes: uint, align: uint) -> *u8 { unsafe { // XXX: Borrow check let head = transmute_mut_region(&mut self.pod_head); @@ -200,7 +200,7 @@ pub impl Arena { } #[inline(always)] - priv fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { + fn alloc_pod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { unsafe { let tydesc = sys::get_type_desc::(); let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align); @@ -211,8 +211,8 @@ pub impl Arena { } // Functions for the non-POD part of the arena - priv fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint) - -> (*u8, *u8) { + fn alloc_nonpod_grow(&mut self, n_bytes: uint, align: uint) + -> (*u8, *u8) { // Allocate a new chunk. let chunk_size = at_vec::capacity(self.head.data); let new_min_chunk_size = uint::max(n_bytes, chunk_size); @@ -224,8 +224,8 @@ pub impl Arena { } #[inline(always)] - priv fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint) - -> (*u8, *u8) { + fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint) + -> (*u8, *u8) { unsafe { let head = transmute_mut_region(&mut self.head); @@ -247,7 +247,7 @@ pub impl Arena { } #[inline(always)] - priv fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { + fn alloc_nonpod<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { unsafe { let tydesc = sys::get_type_desc::(); let (ty_ptr, ptr) = @@ -269,7 +269,7 @@ pub impl Arena { // The external interface #[inline(always)] - fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { + pub fn alloc<'a, T>(&'a mut self, op: &fn() -> T) -> &'a T { unsafe { // XXX: Borrow check let this = transmute_mut_region(self); diff --git a/src/libextra/bitv.rs b/src/libextra/bitv.rs index 0891d23081094..e3a15f76c786b 100644 --- a/src/libextra/bitv.rs +++ b/src/libextra/bitv.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(missing_doc)]; + use core::prelude::*; use core::cmp; @@ -26,14 +28,17 @@ fn small_mask(nbits: uint) -> uint { (1 << nbits) - 1 } -pub impl SmallBitv { - fn new(bits: uint) -> SmallBitv { +impl SmallBitv { + pub fn new(bits: uint) -> SmallBitv { SmallBitv {bits: bits} } #[inline(always)] - fn bits_op(&mut self, right_bits: uint, nbits: uint, - f: &fn(uint, uint) -> uint) -> bool { + pub fn bits_op(&mut self, + right_bits: uint, + nbits: uint, + f: &fn(uint, uint) -> uint) + -> bool { let mask = small_mask(nbits); let old_b: uint = self.bits; let new_b = f(old_b, right_bits); @@ -42,32 +47,32 @@ pub impl SmallBitv { } #[inline(always)] - fn union(&mut self, s: &SmallBitv, nbits: uint) -> bool { + pub fn union(&mut self, s: &SmallBitv, nbits: uint) -> bool { self.bits_op(s.bits, nbits, |u1, u2| u1 | u2) } #[inline(always)] - fn intersect(&mut self, s: &SmallBitv, nbits: uint) -> bool { + pub fn intersect(&mut self, s: &SmallBitv, nbits: uint) -> bool { self.bits_op(s.bits, nbits, |u1, u2| u1 & u2) } #[inline(always)] - fn become(&mut self, s: &SmallBitv, nbits: uint) -> bool { + pub fn become(&mut self, s: &SmallBitv, nbits: uint) -> bool { self.bits_op(s.bits, nbits, |_u1, u2| u2) } #[inline(always)] - fn difference(&mut self, s: &SmallBitv, nbits: uint) -> bool { + pub fn difference(&mut self, s: &SmallBitv, nbits: uint) -> bool { self.bits_op(s.bits, nbits, |u1, u2| u1 & !u2) } #[inline(always)] - fn get(&self, i: uint) -> bool { + pub fn get(&self, i: uint) -> bool { (self.bits & (1 << i)) != 0 } #[inline(always)] - fn set(&mut self, i: uint, x: bool) { + pub fn set(&mut self, i: uint, x: bool) { if x { self.bits |= 1< bool { + pub fn equals(&self, b: &SmallBitv, nbits: uint) -> bool { let mask = small_mask(nbits); mask & self.bits == mask & b.bits } #[inline(always)] - fn clear(&mut self) { self.bits = 0; } + pub fn clear(&mut self) { self.bits = 0; } #[inline(always)] - fn set_all(&mut self) { self.bits = !0; } + pub fn set_all(&mut self) { self.bits = !0; } #[inline(always)] - fn is_true(&self, nbits: uint) -> bool { + pub fn is_true(&self, nbits: uint) -> bool { small_mask(nbits) & !self.bits == 0 } #[inline(always)] - fn is_false(&self, nbits: uint) -> bool { + pub fn is_false(&self, nbits: uint) -> bool { small_mask(nbits) & self.bits == 0 } #[inline(always)] - fn invert(&mut self) { self.bits = !self.bits; } - + pub fn invert(&mut self) { self.bits = !self.bits; } } struct BigBitv { @@ -123,14 +127,17 @@ fn big_mask(nbits: uint, elem: uint) -> uint { } } -pub impl BigBitv { - fn new(storage: ~[uint]) -> BigBitv { +impl BigBitv { + pub fn new(storage: ~[uint]) -> BigBitv { BigBitv {storage: storage} } #[inline(always)] - fn process(&mut self, b: &BigBitv, nbits: uint, - op: &fn(uint, uint) -> uint) -> bool { + pub fn process(&mut self, + b: &BigBitv, + nbits: uint, + op: &fn(uint, uint) -> uint) + -> bool { let len = b.storage.len(); assert_eq!(self.storage.len(), len); let mut changed = false; @@ -148,35 +155,35 @@ pub impl BigBitv { } #[inline(always)] - fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool { + pub fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool { uint::range(0, self.storage.len(), |i| op(&mut self.storage[i])) } #[inline(always)] - fn invert(&mut self) { for self.each_storage |w| { *w = !*w } } + pub fn invert(&mut self) { for self.each_storage |w| { *w = !*w } } #[inline(always)] - fn union(&mut self, b: &BigBitv, nbits: uint) -> bool { + pub fn union(&mut self, b: &BigBitv, nbits: uint) -> bool { self.process(b, nbits, |w1, w2| w1 | w2) } #[inline(always)] - fn intersect(&mut self, b: &BigBitv, nbits: uint) -> bool { + pub fn intersect(&mut self, b: &BigBitv, nbits: uint) -> bool { self.process(b, nbits, |w1, w2| w1 & w2) } #[inline(always)] - fn become(&mut self, b: &BigBitv, nbits: uint) -> bool { + pub fn become(&mut self, b: &BigBitv, nbits: uint) -> bool { self.process(b, nbits, |_, w| w) } #[inline(always)] - fn difference(&mut self, b: &BigBitv, nbits: uint) -> bool { + pub fn difference(&mut self, b: &BigBitv, nbits: uint) -> bool { self.process(b, nbits, |w1, w2| w1 & !w2) } #[inline(always)] - fn get(&self, i: uint) -> bool { + pub fn get(&self, i: uint) -> bool { let w = i / uint::bits; let b = i % uint::bits; let x = 1 & self.storage[w] >> b; @@ -184,7 +191,7 @@ pub impl BigBitv { } #[inline(always)] - fn set(&mut self, i: uint, x: bool) { + pub fn set(&mut self, i: uint, x: bool) { let w = i / uint::bits; let b = i % uint::bits; let flag = 1 << b; @@ -193,7 +200,7 @@ pub impl BigBitv { } #[inline(always)] - fn equals(&self, b: &BigBitv, nbits: uint) -> bool { + pub fn equals(&self, b: &BigBitv, nbits: uint) -> bool { let len = b.storage.len(); for uint::iterate(0, len) |i| { let mask = big_mask(nbits, i); @@ -203,7 +210,6 @@ pub impl BigBitv { } return true; } - } enum BitvVariant { Big(~BigBitv), Small(~SmallBitv) } @@ -222,8 +228,7 @@ fn die() -> ! { fail!("Tried to do operation on bit vectors with different sizes"); } -priv impl Bitv { - +impl Bitv { #[inline(always)] fn do_op(&mut self, op: Op, other: &Bitv) -> bool { if self.nbits != other.nbits { @@ -253,8 +258,8 @@ priv impl Bitv { } -pub impl Bitv { - fn new(nbits: uint, init: bool) -> Bitv { +impl Bitv { + pub fn new(nbits: uint, init: bool) -> Bitv { let rep = if nbits <= uint::bits { Small(~SmallBitv::new(if init {!0} else {0})) } @@ -275,7 +280,7 @@ pub impl Bitv { * the same length. Returns 'true' if `self` changed. */ #[inline(always)] - fn union(&mut self, v1: &Bitv) -> bool { self.do_op(Union, v1) } + pub fn union(&mut self, v1: &Bitv) -> bool { self.do_op(Union, v1) } /** * Calculates the intersection of two bitvectors @@ -284,7 +289,9 @@ pub impl Bitv { * must be the same length. Returns 'true' if `self` changed. */ #[inline(always)] - fn intersect(&mut self, v1: &Bitv) -> bool { self.do_op(Intersect, v1) } + pub fn intersect(&mut self, v1: &Bitv) -> bool { + self.do_op(Intersect, v1) + } /** * Assigns the value of `v1` to `self` @@ -293,16 +300,16 @@ pub impl Bitv { * changed */ #[inline(always)] - fn assign(&mut self, v: &Bitv) -> bool { self.do_op(Assign, v) } + pub fn assign(&mut self, v: &Bitv) -> bool { self.do_op(Assign, v) } /// Retrieve the value at index `i` #[inline(always)] - fn get(&self, i: uint) -> bool { - assert!((i < self.nbits)); - match self.rep { - Big(ref b) => b.get(i), - Small(ref s) => s.get(i) - } + pub fn get(&self, i: uint) -> bool { + assert!((i < self.nbits)); + match self.rep { + Big(ref b) => b.get(i), + Small(ref s) => s.get(i) + } } /** @@ -311,7 +318,7 @@ pub impl Bitv { * `i` must be less than the length of the bitvector. */ #[inline(always)] - fn set(&mut self, i: uint, x: bool) { + pub fn set(&mut self, i: uint, x: bool) { assert!((i < self.nbits)); match self.rep { Big(ref mut b) => b.set(i, x), @@ -326,7 +333,7 @@ pub impl Bitv { * bitvectors contain identical elements. */ #[inline(always)] - fn equal(&self, v1: &Bitv) -> bool { + pub fn equal(&self, v1: &Bitv) -> bool { if self.nbits != v1.nbits { return false; } match self.rep { Small(ref b) => match v1.rep { @@ -342,7 +349,7 @@ pub impl Bitv { /// Set all bits to 0 #[inline(always)] - fn clear(&mut self) { + pub fn clear(&mut self) { match self.rep { Small(ref mut b) => b.clear(), Big(ref mut s) => for s.each_storage() |w| { *w = 0u } @@ -351,7 +358,7 @@ pub impl Bitv { /// Set all bits to 1 #[inline(always)] - fn set_all(&mut self) { + pub fn set_all(&mut self) { match self.rep { Small(ref mut b) => b.set_all(), Big(ref mut s) => for s.each_storage() |w| { *w = !0u } } @@ -359,7 +366,7 @@ pub impl Bitv { /// Invert all bits #[inline(always)] - fn invert(&mut self) { + pub fn invert(&mut self) { match self.rep { Small(ref mut b) => b.invert(), Big(ref mut s) => for s.each_storage() |w| { *w = !*w } } @@ -375,11 +382,13 @@ pub impl Bitv { * Returns `true` if `v0` was changed. */ #[inline(always)] - fn difference(&mut self, v: &Bitv) -> bool { self.do_op(Difference, v) } + pub fn difference(&mut self, v: &Bitv) -> bool { + self.do_op(Difference, v) + } /// Returns true if all bits are 1 #[inline(always)] - fn is_true(&self) -> bool { + pub fn is_true(&self) -> bool { match self.rep { Small(ref b) => b.is_true(self.nbits), _ => { @@ -390,7 +399,7 @@ pub impl Bitv { } #[inline(always)] - fn each(&self, f: &fn(bool) -> bool) -> bool { + pub fn each(&self, f: &fn(bool) -> bool) -> bool { let mut i = 0; while i < self.nbits { if !f(self.get(i)) { return false; } @@ -400,7 +409,7 @@ pub impl Bitv { } /// Returns true if all bits are 0 - fn is_false(&self) -> bool { + pub fn is_false(&self) -> bool { match self.rep { Small(ref b) => b.is_false(self.nbits), Big(_) => { @@ -410,7 +419,7 @@ pub impl Bitv { } } - fn init_to_vec(&self, i: uint) -> uint { + pub fn init_to_vec(&self, i: uint) -> uint { return if self.get(i) { 1 } else { 0 }; } @@ -419,7 +428,7 @@ pub impl Bitv { * * Each uint in the resulting vector has either value 0u or 1u. */ - fn to_vec(&self) -> ~[uint] { + pub fn to_vec(&self) -> ~[uint] { vec::from_fn(self.nbits, |x| self.init_to_vec(x)) } @@ -429,8 +438,7 @@ pub impl Bitv { * size of the bitv is not a multiple of 8 then trailing bits * will be filled-in with false/0 */ - fn to_bytes(&self) -> ~[u8] { - + pub fn to_bytes(&self) -> ~[u8] { fn bit (bitv: &Bitv, byte: uint, bit: uint) -> u8 { let offset = byte * 8 + bit; if offset >= bitv.nbits { @@ -457,7 +465,7 @@ pub impl Bitv { /** * Transform self into a [bool] by turning each bit into a bool */ - fn to_bools(&self) -> ~[bool] { + pub fn to_bools(&self) -> ~[bool] { vec::from_fn(self.nbits, |i| self[i]) } @@ -467,7 +475,7 @@ pub impl Bitv { * The resulting string has the same length as `self`, and each * character is either '0' or '1'. */ - fn to_str(&self) -> ~str { + pub fn to_str(&self) -> ~str { let mut rs = ~""; for self.each() |i| { if i { rs += "1"; } else { rs += "0"; } }; rs @@ -480,7 +488,7 @@ pub impl Bitv { * The uint vector is expected to only contain the values 0u and 1u. Both * the bitvector and vector must have the same length */ - fn eq_vec(&self, v: ~[uint]) -> bool { + pub fn eq_vec(&self, v: ~[uint]) -> bool { assert_eq!(self.nbits, v.len()); let mut i = 0; while i < self.nbits { @@ -492,7 +500,7 @@ pub impl Bitv { true } - fn ones(&self, f: &fn(uint) -> bool) -> bool { + pub fn ones(&self, f: &fn(uint) -> bool) -> bool { uint::range(0, self.nbits, |i| !self.get(i) || f(i)) } @@ -514,7 +522,6 @@ impl Clone for Bitv { } } } - } /** @@ -585,14 +592,14 @@ pub struct BitvSet { priv bitv: BigBitv } -pub impl BitvSet { +impl BitvSet { /// Creates a new bit vector set with initially no contents - fn new() -> BitvSet { + pub fn new() -> BitvSet { BitvSet{ size: 0, bitv: BigBitv::new(~[0]) } } /// Creates a new bit vector set from the given bit vector - fn from_bitv(bitv: Bitv) -> BitvSet { + pub fn from_bitv(bitv: Bitv) -> BitvSet { let mut size = 0; for bitv.ones |_| { size += 1; @@ -607,17 +614,17 @@ pub impl BitvSet { /// Returns the capacity in bits for this bit vector. Inserting any /// element less than this amount will not trigger a resizing. - fn capacity(&self) -> uint { self.bitv.storage.len() * uint::bits } + pub fn capacity(&self) -> uint { self.bitv.storage.len() * uint::bits } /// Consumes this set to return the underlying bit vector - fn unwrap(self) -> Bitv { + pub fn unwrap(self) -> Bitv { let cap = self.capacity(); let BitvSet{bitv, _} = self; return Bitv{ nbits:cap, rep: Big(~bitv) }; } #[inline(always)] - priv fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) { + fn other_op(&mut self, other: &BitvSet, f: &fn(uint, uint) -> uint) { fn nbits(mut w: uint) -> uint { let mut bits = 0; for uint::bits.times { @@ -641,22 +648,22 @@ pub impl BitvSet { } /// Union in-place with the specified other bit vector - fn union_with(&mut self, other: &BitvSet) { + pub fn union_with(&mut self, other: &BitvSet) { self.other_op(other, |w1, w2| w1 | w2); } /// Intersect in-place with the specified other bit vector - fn intersect_with(&mut self, other: &BitvSet) { + pub fn intersect_with(&mut self, other: &BitvSet) { self.other_op(other, |w1, w2| w1 & w2); } /// Difference in-place with the specified other bit vector - fn difference_with(&mut self, other: &BitvSet) { + pub fn difference_with(&mut self, other: &BitvSet) { self.other_op(other, |w1, w2| w1 & !w2); } /// Symmetric difference in-place with the specified other bit vector - fn symmetric_difference_with(&mut self, other: &BitvSet) { + pub fn symmetric_difference_with(&mut self, other: &BitvSet) { self.other_op(other, |w1, w2| w1 ^ w2); } } @@ -810,7 +817,7 @@ impl Set for BitvSet { } } -priv impl BitvSet { +impl BitvSet { /// Visits each of the words that the two bit vectors (self and other) /// both have in common. The three yielded arguments are (bit location, /// w1, w2) where the bit location is the number of bits offset so far, diff --git a/src/libextra/comm.rs b/src/libextra/comm.rs index 1ef61926c9200..1001d4f6ac9ed 100644 --- a/src/libextra/comm.rs +++ b/src/libextra/comm.rs @@ -14,6 +14,8 @@ Higher level communication abstractions. */ +#[allow(missing_doc)]; + use core::prelude::*; use core::comm::{GenericChan, GenericSmartChan, GenericPort}; @@ -28,20 +30,20 @@ pub struct DuplexStream { } // Allow these methods to be used without import: -pub impl DuplexStream { - fn send(&self, x: T) { +impl DuplexStream { + pub fn send(&self, x: T) { self.chan.send(x) } - fn try_send(&self, x: T) -> bool { + pub fn try_send(&self, x: T) -> bool { self.chan.try_send(x) } - fn recv(&self, ) -> U { + pub fn recv(&self, ) -> U { self.port.recv() } - fn try_recv(&self) -> Option { + pub fn try_recv(&self) -> Option { self.port.try_recv() } - fn peek(&self) -> bool { + pub fn peek(&self) -> bool { self.port.peek() } } diff --git a/src/libextra/deque.rs b/src/libextra/deque.rs index 08dc2436c9339..a8accc50eab01 100644 --- a/src/libextra/deque.rs +++ b/src/libextra/deque.rs @@ -44,9 +44,9 @@ impl Mutable for Deque { } } -pub impl Deque { +impl Deque { /// Create an empty Deque - fn new() -> Deque { + pub fn new() -> Deque { Deque{nelts: 0, lo: 0, hi: 0, elts: vec::from_fn(initial_capacity, |_| None)} } @@ -54,35 +54,35 @@ pub impl Deque { /// Return a reference to the first element in the deque /// /// Fails if the deque is empty - fn peek_front<'a>(&'a self) -> &'a T { get(self.elts, self.lo) } + pub fn peek_front<'a>(&'a self) -> &'a T { get(self.elts, self.lo) } /// Return a reference to the last element in the deque /// /// Fails if the deque is empty - fn peek_back<'a>(&'a self) -> &'a T { get(self.elts, self.hi - 1u) } + pub fn peek_back<'a>(&'a self) -> &'a T { get(self.elts, self.hi - 1u) } /// Retrieve an element in the deque by index /// /// Fails if there is no element with the given index - fn get<'a>(&'a self, i: int) -> &'a T { + pub fn get<'a>(&'a self, i: int) -> &'a T { let idx = (self.lo + (i as uint)) % self.elts.len(); get(self.elts, idx) } /// Iterate over the elements in the deque - fn each(&self, f: &fn(&T) -> bool) -> bool { + pub fn each(&self, f: &fn(&T) -> bool) -> bool { self.eachi(|_i, e| f(e)) } /// Iterate over the elements in the deque by index - fn eachi(&self, f: &fn(uint, &T) -> bool) -> bool { + pub fn eachi(&self, f: &fn(uint, &T) -> bool) -> bool { uint::range(0, self.nelts, |i| f(i, self.get(i as int))) } /// Remove and return the first element in the deque /// /// Fails if the deque is empty - fn pop_front(&mut self) -> T { + pub fn pop_front(&mut self) -> T { let result = self.elts[self.lo].swap_unwrap(); self.lo = (self.lo + 1u) % self.elts.len(); self.nelts -= 1u; @@ -92,7 +92,7 @@ pub impl Deque { /// Remove and return the last element in the deque /// /// Fails if the deque is empty - fn pop_back(&mut self) -> T { + pub fn pop_back(&mut self) -> T { if self.hi == 0u { self.hi = self.elts.len() - 1u; } else { self.hi -= 1u; } @@ -103,7 +103,7 @@ pub impl Deque { } /// Prepend an element to the deque - fn add_front(&mut self, t: T) { + pub fn add_front(&mut self, t: T) { let oldlo = self.lo; if self.lo == 0u { self.lo = self.elts.len() - 1u; @@ -118,7 +118,7 @@ pub impl Deque { } /// Append an element to the deque - fn add_back(&mut self, t: T) { + pub fn add_back(&mut self, t: T) { if self.lo == self.hi && self.nelts != 0u { self.elts = grow(self.nelts, self.lo, self.elts); self.lo = 0u; @@ -136,7 +136,7 @@ pub impl Deque { /// # Arguments /// /// * n - The number of elements to reserve space for - fn reserve(&mut self, n: uint) { + pub fn reserve(&mut self, n: uint) { vec::reserve(&mut self.elts, n); } @@ -150,7 +150,7 @@ pub impl Deque { /// # Arguments /// /// * n - The number of elements to reserve space for - fn reserve_at_least(&mut self, n: uint) { + pub fn reserve_at_least(&mut self, n: uint) { vec::reserve_at_least(&mut self.elts, n); } } diff --git a/src/libextra/dlist.rs b/src/libextra/dlist.rs index 5581c6d5ac9d9..52e2b75d6b6d3 100644 --- a/src/libextra/dlist.rs +++ b/src/libextra/dlist.rs @@ -41,7 +41,7 @@ pub struct DList { tl: DListLink, } -priv impl DListNode { +impl DListNode { fn assert_links(@mut self) { match self.next { Some(neighbour) => match neighbour.prev { @@ -64,26 +64,26 @@ priv impl DListNode { } } -pub impl DListNode { +impl DListNode { /// Get the next node in the list, if there is one. - fn next_link(@mut self) -> DListLink { + pub fn next_link(@mut self) -> DListLink { self.assert_links(); self.next } /// Get the next node in the list, failing if there isn't one. - fn next_node(@mut self) -> @mut DListNode { + pub fn next_node(@mut self) -> @mut DListNode { match self.next_link() { Some(nobe) => nobe, None => fail!("This dlist node has no next neighbour.") } } /// Get the previous node in the list, if there is one. - fn prev_link(@mut self) -> DListLink { + pub fn prev_link(@mut self) -> DListLink { self.assert_links(); self.prev } /// Get the previous node in the list, failing if there isn't one. - fn prev_node(@mut self) -> @mut DListNode { + pub fn prev_node(@mut self) -> @mut DListNode { match self.prev_link() { Some(nobe) => nobe, None => fail!("This dlist node has no previous neighbour.") @@ -126,7 +126,7 @@ pub fn concat(lists: @mut DList<@mut DList>) -> @mut DList { result } -priv impl DList { +impl DList { fn new_link(data: T) -> DListLink { Some(@mut DListNode { data: data, @@ -211,34 +211,34 @@ priv impl DList { } } -pub impl DList { +impl DList { /// Get the size of the list. O(1). - fn len(@mut self) -> uint { self.size } + pub fn len(@mut self) -> uint { self.size } /// Returns true if the list is empty. O(1). - fn is_empty(@mut self) -> bool { self.len() == 0 } + pub fn is_empty(@mut self) -> bool { self.len() == 0 } /// Add data to the head of the list. O(1). - fn push_head(@mut self, data: T) { + pub fn push_head(@mut self, data: T) { self.add_head(DList::new_link(data)); } /** * Add data to the head of the list, and get the new containing * node. O(1). */ - fn push_head_n(@mut self, data: T) -> @mut DListNode { + pub fn push_head_n(@mut self, data: T) -> @mut DListNode { let nobe = DList::new_link(data); self.add_head(nobe); nobe.get() } /// Add data to the tail of the list. O(1). - fn push(@mut self, data: T) { + pub fn push(@mut self, data: T) { self.add_tail(DList::new_link(data)); } /** * Add data to the tail of the list, and get the new containing * node. O(1). */ - fn push_n(@mut self, data: T) -> @mut DListNode { + pub fn push_n(@mut self, data: T) -> @mut DListNode { let nobe = DList::new_link(data); self.add_tail(nobe); nobe.get() @@ -247,16 +247,16 @@ pub impl DList { * Insert data into the middle of the list, left of the given node. * O(1). */ - fn insert_before(@mut self, data: T, neighbour: @mut DListNode) { + pub fn insert_before(@mut self, data: T, neighbour: @mut DListNode) { self.insert_left(DList::new_link(data), neighbour); } /** * Insert an existing node in the middle of the list, left of the * given node. O(1). */ - fn insert_n_before(@mut self, - nobe: @mut DListNode, - neighbour: @mut DListNode) { + pub fn insert_n_before(@mut self, + nobe: @mut DListNode, + neighbour: @mut DListNode) { self.make_mine(nobe); self.insert_left(Some(nobe), neighbour); } @@ -264,11 +264,10 @@ pub impl DList { * Insert data in the middle of the list, left of the given node, * and get its containing node. O(1). */ - fn insert_before_n( - @mut self, - data: T, - neighbour: @mut DListNode - ) -> @mut DListNode { + pub fn insert_before_n(@mut self, + data: T, + neighbour: @mut DListNode) + -> @mut DListNode { let nobe = DList::new_link(data); self.insert_left(nobe, neighbour); nobe.get() @@ -277,16 +276,16 @@ pub impl DList { * Insert data into the middle of the list, right of the given node. * O(1). */ - fn insert_after(@mut self, data: T, neighbour: @mut DListNode) { + pub fn insert_after(@mut self, data: T, neighbour: @mut DListNode) { self.insert_right(neighbour, DList::new_link(data)); } /** * Insert an existing node in the middle of the list, right of the * given node. O(1). */ - fn insert_n_after(@mut self, - nobe: @mut DListNode, - neighbour: @mut DListNode) { + pub fn insert_n_after(@mut self, + nobe: @mut DListNode, + neighbour: @mut DListNode) { self.make_mine(nobe); self.insert_right(neighbour, Some(nobe)); } @@ -294,42 +293,41 @@ pub impl DList { * Insert data in the middle of the list, right of the given node, * and get its containing node. O(1). */ - fn insert_after_n( - @mut self, - data: T, - neighbour: @mut DListNode - ) -> @mut DListNode { + pub fn insert_after_n(@mut self, + data: T, + neighbour: @mut DListNode) + -> @mut DListNode { let nobe = DList::new_link(data); self.insert_right(neighbour, nobe); nobe.get() } /// Remove a node from the head of the list. O(1). - fn pop_n(@mut self) -> DListLink { + pub fn pop_n(@mut self) -> DListLink { let hd = self.peek_n(); hd.map(|nobe| self.unlink(*nobe)); hd } /// Remove a node from the tail of the list. O(1). - fn pop_tail_n(@mut self) -> DListLink { + pub fn pop_tail_n(@mut self) -> DListLink { let tl = self.peek_tail_n(); tl.map(|nobe| self.unlink(*nobe)); tl } /// Get the node at the list's head. O(1). - fn peek_n(@mut self) -> DListLink { self.hd } + pub fn peek_n(@mut self) -> DListLink { self.hd } /// Get the node at the list's tail. O(1). - fn peek_tail_n(@mut self) -> DListLink { self.tl } + pub fn peek_tail_n(@mut self) -> DListLink { self.tl } /// Get the node at the list's head, failing if empty. O(1). - fn head_n(@mut self) -> @mut DListNode { + pub fn head_n(@mut self) -> @mut DListNode { match self.hd { Some(nobe) => nobe, None => fail!("Attempted to get the head of an empty dlist.") } } /// Get the node at the list's tail, failing if empty. O(1). - fn tail_n(@mut self) -> @mut DListNode { + pub fn tail_n(@mut self) -> @mut DListNode { match self.tl { Some(nobe) => nobe, None => fail!("Attempted to get the tail of an empty dlist.") @@ -337,13 +335,13 @@ pub impl DList { } /// Remove a node from anywhere in the list. O(1). - fn remove(@mut self, nobe: @mut DListNode) { self.unlink(nobe); } + pub fn remove(@mut self, nobe: @mut DListNode) { self.unlink(nobe); } /** * Empty another list onto the end of this list, joining this list's tail * to the other list's head. O(1). */ - fn append(@mut self, them: @mut DList) { + pub fn append(@mut self, them: @mut DList) { if managed::mut_ptr_eq(self, them) { fail!("Cannot append a dlist to itself!") } @@ -360,7 +358,7 @@ pub impl DList { * Empty another list onto the start of this list, joining the other * list's tail to this list's head. O(1). */ - fn prepend(@mut self, them: @mut DList) { + pub fn prepend(@mut self, them: @mut DList) { if managed::mut_ptr_eq(self, them) { fail!("Cannot prepend a dlist to itself!") } @@ -375,7 +373,7 @@ pub impl DList { } /// Reverse the list's elements in place. O(n). - fn reverse(@mut self) { + pub fn reverse(@mut self) { do self.hd.while_some |nobe| { let next_nobe = nobe.next; self.remove(nobe); @@ -389,7 +387,7 @@ pub impl DList { * Remove everything from the list. This is important because the cyclic * links won't otherwise be automatically refcounted-collected. O(n). */ - fn clear(@mut self) { + pub fn clear(@mut self) { // Cute as it would be to simply detach the list and proclaim "O(1)!", // the GC would still be a hidden O(n). Better to be honest about it. while !self.is_empty() { @@ -398,7 +396,7 @@ pub impl DList { } /// Iterate over nodes. - fn each_node(@mut self, f: &fn(@mut DListNode) -> bool) -> bool { + pub fn each_node(@mut self, f: &fn(@mut DListNode) -> bool) -> bool { let mut link = self.peek_n(); while link.is_some() { let nobe = link.get(); @@ -409,7 +407,7 @@ pub impl DList { } /// Check data structure integrity. O(n). - fn assert_consistent(@mut self) { + pub fn assert_consistent(@mut self) { if self.hd.is_none() || self.tl.is_none() { assert!(self.hd.is_none() && self.tl.is_none()); } @@ -459,35 +457,35 @@ pub impl DList { } } -pub impl DList { +impl DList { /// Remove data from the head of the list. O(1). - fn pop(@mut self) -> Option { + pub fn pop(@mut self) -> Option { self.pop_n().map(|nobe| nobe.data) } /// Remove data from the tail of the list. O(1). - fn pop_tail(@mut self) -> Option { + pub fn pop_tail(@mut self) -> Option { self.pop_tail_n().map(|nobe| nobe.data) } /// Get data at the list's head. O(1). - fn peek(@mut self) -> Option { + pub fn peek(@mut self) -> Option { self.peek_n().map(|nobe| nobe.data) } /// Get data at the list's tail. O(1). - fn peek_tail(@mut self) -> Option { + pub fn peek_tail(@mut self) -> Option { self.peek_tail_n().map (|nobe| nobe.data) } /// Get data at the list's head, failing if empty. O(1). - fn head(@mut self) -> T { self.head_n().data } + pub fn head(@mut self) -> T { self.head_n().data } /// Get data at the list's tail, failing if empty. O(1). - fn tail(@mut self) -> T { self.tail_n().data } + pub fn tail(@mut self) -> T { self.tail_n().data } /// Get the elements of the list as a vector. O(n). - fn to_vec(@mut self) -> ~[T] { + pub fn to_vec(@mut self) -> ~[T] { let mut v = vec::with_capacity(self.size); for old_iter::eachi(&self) |index,data| { v[index] = *data; diff --git a/src/libextra/ebml.rs b/src/libextra/ebml.rs index 641f01dfb0b6e..47b0b4f6c974b 100644 --- a/src/libextra/ebml.rs +++ b/src/libextra/ebml.rs @@ -89,8 +89,8 @@ pub mod reader { // ebml reading - pub impl Doc { - fn get(&self, tag: uint) -> Doc { + impl Doc { + pub fn get(&self, tag: uint) -> Doc { get_doc(*self, tag) } } @@ -286,7 +286,7 @@ pub mod reader { } } - priv impl Decoder { + impl Decoder { fn _check_label(&mut self, lbl: &str) { if self.pos < self.parent.end { let TaggedDoc { tag: r_tag, doc: r_doc } = @@ -343,8 +343,9 @@ pub mod reader { } } - pub impl Decoder { - fn read_opaque(&mut self, op: &fn(&mut Decoder, Doc) -> R) -> R { + impl Decoder { + pub fn read_opaque(&mut self, op: &fn(&mut Decoder, Doc) -> R) + -> R { let doc = self.next_doc(EsOpaque); let (old_parent, old_pos) = (self.parent, self.pos); @@ -638,8 +639,8 @@ pub mod writer { } // FIXME (#2741): Provide a function to write the standard ebml header. - pub impl Encoder { - fn start_tag(&mut self, tag_id: uint) { + impl Encoder { + pub fn start_tag(&mut self, tag_id: uint) { debug!("Start tag %u", tag_id); // Write the enum ID: @@ -651,7 +652,7 @@ pub mod writer { self.writer.write(zeroes); } - fn end_tag(&mut self) { + pub fn end_tag(&mut self) { let last_size_pos = self.size_positions.pop(); let cur_pos = self.writer.tell(); self.writer.seek(last_size_pos as int, io::SeekSet); @@ -662,72 +663,72 @@ pub mod writer { debug!("End tag (size = %u)", size); } - fn wr_tag(&mut self, tag_id: uint, blk: &fn()) { + pub fn wr_tag(&mut self, tag_id: uint, blk: &fn()) { self.start_tag(tag_id); blk(); self.end_tag(); } - fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) { + pub fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) { write_vuint(self.writer, tag_id); write_vuint(self.writer, b.len()); self.writer.write(b); } - fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) { + pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) { do io::u64_to_be_bytes(v, 8u) |v| { self.wr_tagged_bytes(tag_id, v); } } - fn wr_tagged_u32(&mut self, tag_id: uint, v: u32) { + pub fn wr_tagged_u32(&mut self, tag_id: uint, v: u32) { do io::u64_to_be_bytes(v as u64, 4u) |v| { self.wr_tagged_bytes(tag_id, v); } } - fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) { + pub fn wr_tagged_u16(&mut self, tag_id: uint, v: u16) { do io::u64_to_be_bytes(v as u64, 2u) |v| { self.wr_tagged_bytes(tag_id, v); } } - fn wr_tagged_u8(&mut self, tag_id: uint, v: u8) { + pub fn wr_tagged_u8(&mut self, tag_id: uint, v: u8) { self.wr_tagged_bytes(tag_id, &[v]); } - fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) { + pub fn wr_tagged_i64(&mut self, tag_id: uint, v: i64) { do io::u64_to_be_bytes(v as u64, 8u) |v| { self.wr_tagged_bytes(tag_id, v); } } - fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) { + pub fn wr_tagged_i32(&mut self, tag_id: uint, v: i32) { do io::u64_to_be_bytes(v as u64, 4u) |v| { self.wr_tagged_bytes(tag_id, v); } } - fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) { + pub fn wr_tagged_i16(&mut self, tag_id: uint, v: i16) { do io::u64_to_be_bytes(v as u64, 2u) |v| { self.wr_tagged_bytes(tag_id, v); } } - fn wr_tagged_i8(&mut self, tag_id: uint, v: i8) { + pub fn wr_tagged_i8(&mut self, tag_id: uint, v: i8) { self.wr_tagged_bytes(tag_id, &[v as u8]); } - fn wr_tagged_str(&mut self, tag_id: uint, v: &str) { + pub fn wr_tagged_str(&mut self, tag_id: uint, v: &str) { str::byte_slice(v, |b| self.wr_tagged_bytes(tag_id, b)); } - fn wr_bytes(&mut self, b: &[u8]) { + pub fn wr_bytes(&mut self, b: &[u8]) { debug!("Write %u bytes", b.len()); self.writer.write(b); } - fn wr_str(&mut self, s: &str) { + pub fn wr_str(&mut self, s: &str) { debug!("Write str: %?", s); self.writer.write(str::to_bytes(s)); } @@ -740,7 +741,7 @@ pub mod writer { // Totally lame approach. static debug: bool = true; - priv impl Encoder { + impl Encoder { // used internally to emit things like the vector length and so on fn _emit_tagged_uint(&mut self, t: EbmlEncoderTag, v: uint) { assert!(v <= 0xFFFF_FFFF_u); @@ -758,8 +759,8 @@ pub mod writer { } } - pub impl Encoder { - fn emit_opaque(&mut self, f: &fn(&mut Encoder)) { + impl Encoder { + pub fn emit_opaque(&mut self, f: &fn(&mut Encoder)) { self.start_tag(EsOpaque as uint); f(self); self.end_tag(); diff --git a/src/libextra/flatpipes.rs b/src/libextra/flatpipes.rs index 2f5a43d8e84dd..31218ca9a0a54 100644 --- a/src/libextra/flatpipes.rs +++ b/src/libextra/flatpipes.rs @@ -317,8 +317,8 @@ impl,C:ByteChan> GenericChan for FlatChan { } } -pub impl,P:BytePort> FlatPort { - fn new(u: U, p: P) -> FlatPort { +impl,P:BytePort> FlatPort { + pub fn new(u: U, p: P) -> FlatPort { FlatPort { unflattener: u, byte_port: p @@ -326,8 +326,8 @@ pub impl,P:BytePort> FlatPort { } } -pub impl,C:ByteChan> FlatChan { - fn new(f: F, c: C) -> FlatChan { +impl,C:ByteChan> FlatChan { + pub fn new(f: F, c: C) -> FlatChan { FlatChan { flattener: f, byte_chan: c @@ -380,16 +380,16 @@ pub mod flatteners { } } - pub impl PodUnflattener { - fn new() -> PodUnflattener { + impl PodUnflattener { + pub fn new() -> PodUnflattener { PodUnflattener { bogus: () } } } - pub impl PodFlattener { - fn new() -> PodFlattener { + impl PodFlattener { + pub fn new() -> PodFlattener { PodFlattener { bogus: () } @@ -423,8 +423,8 @@ pub mod flatteners { } } - pub impl> DeserializingUnflattener { - fn new(deserialize_buffer: DeserializeBuffer) + impl> DeserializingUnflattener { + pub fn new(deserialize_buffer: DeserializeBuffer) -> DeserializingUnflattener { DeserializingUnflattener { deserialize_buffer: deserialize_buffer @@ -432,8 +432,8 @@ pub mod flatteners { } } - pub impl> SerializingFlattener { - fn new(serialize_value: SerializeValue) + impl> SerializingFlattener { + pub fn new(serialize_value: SerializeValue) -> SerializingFlattener { SerializingFlattener { serialize_value: serialize_value @@ -554,16 +554,16 @@ pub mod bytepipes { } } - pub impl ReaderBytePort { - fn new(r: R) -> ReaderBytePort { + impl ReaderBytePort { + pub fn new(r: R) -> ReaderBytePort { ReaderBytePort { reader: r } } } - pub impl WriterByteChan { - fn new(w: W) -> WriterByteChan { + impl WriterByteChan { + pub fn new(w: W) -> WriterByteChan { WriterByteChan { writer: w } @@ -619,8 +619,8 @@ pub mod bytepipes { } } - pub impl PipeBytePort { - fn new(p: Port<~[u8]>) -> PipeBytePort { + impl PipeBytePort { + pub fn new(p: Port<~[u8]>) -> PipeBytePort { PipeBytePort { port: p, buf: @mut ~[] @@ -628,8 +628,8 @@ pub mod bytepipes { } } - pub impl PipeByteChan { - fn new(c: Chan<~[u8]>) -> PipeByteChan { + impl PipeByteChan { + pub fn new(c: Chan<~[u8]>) -> PipeByteChan { PipeByteChan { chan: c } diff --git a/src/libextra/future.rs b/src/libextra/future.rs index 4d3a757e80ed4..25a3259c69654 100644 --- a/src/libextra/future.rs +++ b/src/libextra/future.rs @@ -54,15 +54,15 @@ priv enum FutureState { } /// Methods on the `future` type -pub impl Future { - fn get(&mut self) -> A { +impl Future { + pub fn get(&mut self) -> A { //! Get the value of the future. *(self.get_ref()) } } -pub impl Future { - fn get_ref<'a>(&'a mut self) -> &'a A { +impl Future { + pub fn get_ref<'a>(&'a mut self) -> &'a A { /*! * Executes the future's closure and then returns a borrowed * pointer to the result. The borrowed pointer lasts as long as diff --git a/src/libextra/json.rs b/src/libextra/json.rs index d69548c6f9d2d..22abe0edbb94e 100644 --- a/src/libextra/json.rs +++ b/src/libextra/json.rs @@ -10,7 +10,9 @@ // Rust JSON serialization library // Copyright (c) 2011 Google Inc. + #[forbid(non_camel_case_types)]; +#[allow(missing_doc)]; //! json serialization @@ -497,8 +499,8 @@ pub fn Parser(rdr: @io::Reader) -> Parser { } } -pub impl Parser { - fn parse(&mut self) -> Result { +impl Parser { + pub fn parse(&mut self) -> Result { match self.parse_value() { Ok(value) => { // Skip trailing whitespaces. @@ -515,7 +517,7 @@ pub impl Parser { } } -priv impl Parser { +impl Parser { fn eof(&self) -> bool { self.ch == -1 as char } fn bump(&mut self) { diff --git a/src/libextra/net_tcp.rs b/src/libextra/net_tcp.rs index d658ad6551f24..960319b9c3f99 100644 --- a/src/libextra/net_tcp.rs +++ b/src/libextra/net_tcp.rs @@ -826,7 +826,7 @@ pub fn socket_buf(sock: TcpSocket) -> TcpSocketBuf { } /// Convenience methods extending `net::tcp::TcpSocket` -pub impl TcpSocket { +impl TcpSocket { pub fn read_start(&self) -> result::Result<@Port< result::Result<~[u8], TcpErrData>>, TcpErrData> { read_start(self) @@ -835,11 +835,11 @@ pub impl TcpSocket { result::Result<(), TcpErrData> { read_stop(self) } - fn read(&self, timeout_msecs: uint) -> + pub fn read(&self, timeout_msecs: uint) -> result::Result<~[u8], TcpErrData> { read(self, timeout_msecs) } - fn read_future(&self, timeout_msecs: uint) -> + pub fn read_future(&self, timeout_msecs: uint) -> future::Future> { read_future(self, timeout_msecs) } diff --git a/src/libextra/net_url.rs b/src/libextra/net_url.rs index 80957a8c8ef96..58930692965dd 100644 --- a/src/libextra/net_url.rs +++ b/src/libextra/net_url.rs @@ -41,16 +41,15 @@ struct UserInfo { pub type Query = ~[(~str, ~str)]; -pub impl Url { - fn new( - scheme: ~str, - user: Option, - host: ~str, - port: Option<~str>, - path: ~str, - query: Query, - fragment: Option<~str> - ) -> Url { +impl Url { + pub fn new(scheme: ~str, + user: Option, + host: ~str, + port: Option<~str>, + path: ~str, + query: Query, + fragment: Option<~str>) + -> Url { Url { scheme: scheme, user: user, @@ -63,8 +62,8 @@ pub impl Url { } } -pub impl UserInfo { - fn new(user: ~str, pass: Option<~str>) -> UserInfo { +impl UserInfo { + pub fn new(user: ~str, pass: Option<~str>) -> UserInfo { UserInfo { user: user, pass: pass } } } diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index adbaf89e16c47..82f706e8f3f38 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -16,6 +16,8 @@ A BigUint is represented as an array of BigDigits. A BigInt is a combination of BigUint and Sign. */ +#[allow(missing_doc)]; + use core::prelude::*; use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater}; @@ -1095,9 +1097,8 @@ impl FromStrRadix for BigInt { } } -pub impl BigInt { +impl BigInt { /// Creates and initializes an BigInt. - pub fn new(sign: Sign, v: ~[BigDigit]) -> BigInt { BigInt::from_biguint(sign, BigUint::new(v)) } @@ -1139,8 +1140,7 @@ pub impl BigInt { .map_consume(|bu| BigInt::from_biguint(sign, bu)); } - - fn to_uint(&self) -> uint { + pub fn to_uint(&self) -> uint { match self.sign { Plus => self.data.to_uint(), Zero => 0, diff --git a/src/libextra/priority_queue.rs b/src/libextra/priority_queue.rs index 49fbf06406f4e..b58f90beb3122 100644 --- a/src/libextra/priority_queue.rs +++ b/src/libextra/priority_queue.rs @@ -10,6 +10,8 @@ //! A priority queue implemented with a binary heap +#[allow(missing_doc)]; + use core::prelude::*; use core::old_iter::BaseIter; @@ -44,26 +46,26 @@ impl Mutable for PriorityQueue { fn clear(&mut self) { self.data.truncate(0) } } -pub impl PriorityQueue { +impl PriorityQueue { /// Returns the greatest item in the queue - fails if empty - fn top<'a>(&'a self) -> &'a T { &self.data[0] } + pub fn top<'a>(&'a self) -> &'a T { &self.data[0] } /// Returns the greatest item in the queue - None if empty - fn maybe_top<'a>(&'a self) -> Option<&'a T> { + pub fn maybe_top<'a>(&'a self) -> Option<&'a T> { if self.is_empty() { None } else { Some(self.top()) } } /// Returns the number of elements the queue can hold without reallocating - fn capacity(&self) -> uint { vec::capacity(&self.data) } + pub fn capacity(&self) -> uint { vec::capacity(&self.data) } - fn reserve(&mut self, n: uint) { vec::reserve(&mut self.data, n) } + pub fn reserve(&mut self, n: uint) { vec::reserve(&mut self.data, n) } - fn reserve_at_least(&mut self, n: uint) { + pub fn reserve_at_least(&mut self, n: uint) { vec::reserve_at_least(&mut self.data, n) } /// Pop the greatest item from the queue - fails if empty - fn pop(&mut self) -> T { + pub fn pop(&mut self) -> T { let mut item = self.data.pop(); if !self.is_empty() { swap(&mut item, &mut self.data[0]); @@ -73,19 +75,19 @@ pub impl PriorityQueue { } /// Pop the greatest item from the queue - None if empty - fn maybe_pop(&mut self) -> Option { + pub fn maybe_pop(&mut self) -> Option { if self.is_empty() { None } else { Some(self.pop()) } } /// Push an item onto the queue - fn push(&mut self, item: T) { + pub fn push(&mut self, item: T) { self.data.push(item); let new_len = self.len() - 1; self.siftup(0, new_len); } /// Optimized version of a push followed by a pop - fn push_pop(&mut self, mut item: T) -> T { + pub fn push_pop(&mut self, mut item: T) -> T { if !self.is_empty() && self.data[0] > item { swap(&mut item, &mut self.data[0]); self.siftdown(0); @@ -94,18 +96,18 @@ pub impl PriorityQueue { } /// Optimized version of a pop followed by a push - fails if empty - fn replace(&mut self, mut item: T) -> T { + pub fn replace(&mut self, mut item: T) -> T { swap(&mut item, &mut self.data[0]); self.siftdown(0); item } /// Consume the PriorityQueue and return the underlying vector - fn to_vec(self) -> ~[T] { let PriorityQueue{data: v} = self; v } + pub fn to_vec(self) -> ~[T] { let PriorityQueue{data: v} = self; v } /// Consume the PriorityQueue and return a vector in sorted /// (ascending) order - fn to_sorted_vec(self) -> ~[T] { + pub fn to_sorted_vec(self) -> ~[T] { let mut q = self; let mut end = q.len(); while end > 1 { @@ -117,10 +119,10 @@ pub impl PriorityQueue { } /// Create an empty PriorityQueue - fn new() -> PriorityQueue { PriorityQueue{data: ~[],} } + pub fn new() -> PriorityQueue { PriorityQueue{data: ~[],} } /// Create a PriorityQueue from a vector (heapify) - fn from_vec(xs: ~[T]) -> PriorityQueue { + pub fn from_vec(xs: ~[T]) -> PriorityQueue { let mut q = PriorityQueue{data: xs,}; let mut n = q.len() / 2; while n > 0 { @@ -135,8 +137,7 @@ pub impl PriorityQueue { // zeroed element), shift along the others and move it back into the // vector over the junk element. This reduces the constant factor // compared to using swaps, which involves twice as many moves. - - priv fn siftup(&mut self, start: uint, mut pos: uint) { + fn siftup(&mut self, start: uint, mut pos: uint) { unsafe { let new = replace(&mut self.data[pos], init()); @@ -154,7 +155,7 @@ pub impl PriorityQueue { } } - priv fn siftdown_range(&mut self, mut pos: uint, end: uint) { + fn siftdown_range(&mut self, mut pos: uint, end: uint) { unsafe { let start = pos; let new = replace(&mut self.data[pos], init()); @@ -176,7 +177,7 @@ pub impl PriorityQueue { } } - priv fn siftdown(&mut self, pos: uint) { + fn siftdown(&mut self, pos: uint) { let len = self.len(); self.siftdown_range(pos, len); } diff --git a/src/libextra/rc.rs b/src/libextra/rc.rs index 8cd1c893bb6f0..1ec72f2ea9f65 100644 --- a/src/libextra/rc.rs +++ b/src/libextra/rc.rs @@ -40,7 +40,7 @@ pub struct Rc { priv ptr: *mut RcBox, } -priv impl Rc { +impl Rc { unsafe fn new(value: T) -> Rc { let ptr = malloc(sys::size_of::>() as size_t) as *mut RcBox; assert!(!ptr::is_null(ptr)); @@ -59,9 +59,9 @@ pub fn rc_from_const(value: T) -> Rc { unsafe { Rc::new(value) } } -pub impl Rc { +impl Rc { #[inline(always)] - fn borrow<'r>(&'r self) -> &'r T { + pub fn borrow<'r>(&'r self) -> &'r T { unsafe { cast::copy_lifetime(self, &(*self.ptr).value) } } } @@ -170,7 +170,7 @@ pub struct RcMut { priv ptr: *mut RcMutBox, } -priv impl RcMut { +impl RcMut { unsafe fn new(value: T) -> RcMut { let ptr = malloc(sys::size_of::>() as size_t) as *mut RcMutBox; assert!(!ptr::is_null(ptr)); @@ -189,10 +189,10 @@ pub fn rc_mut_from_const(value: T) -> RcMut { unsafe { RcMut::new(value) } } -pub impl RcMut { +impl RcMut { /// Fails if there is already a mutable borrow of the box #[inline] - fn with_borrow(&self, f: &fn(&T) -> U) -> U { + pub fn with_borrow(&self, f: &fn(&T) -> U) -> U { unsafe { assert!((*self.ptr).borrow != Mutable); let previous = (*self.ptr).borrow; @@ -205,7 +205,7 @@ pub impl RcMut { /// Fails if there is already a mutable or immutable borrow of the box #[inline] - fn with_mut_borrow(&self, f: &fn(&mut T) -> U) -> U { + pub fn with_mut_borrow(&self, f: &fn(&mut T) -> U) -> U { unsafe { assert_eq!((*self.ptr).borrow, Nothing); (*self.ptr).borrow = Mutable; diff --git a/src/libextra/smallintmap.rs b/src/libextra/smallintmap.rs index 98392fc41e1bc..7f566bc16e732 100644 --- a/src/libextra/smallintmap.rs +++ b/src/libextra/smallintmap.rs @@ -13,6 +13,8 @@ * are O(highest integer key). */ +#[allow(missing_doc)]; + use core::prelude::*; use core::cmp; @@ -152,12 +154,12 @@ impl Map for SmallIntMap { } } -pub impl SmallIntMap { +impl SmallIntMap { /// Create an empty SmallIntMap - fn new() -> SmallIntMap { SmallIntMap{v: ~[]} } + pub fn new() -> SmallIntMap { SmallIntMap{v: ~[]} } /// Visit all key-value pairs in reverse order - fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool { + pub fn each_reverse<'a>(&'a self, it: &fn(uint, &'a V) -> bool) -> bool { for uint::range_rev(self.v.len(), 0) |i| { match self.v[i - 1] { Some(ref elt) => if !it(i - 1, elt) { return false; }, @@ -167,14 +169,14 @@ pub impl SmallIntMap { return true; } - fn get<'a>(&'a self, key: &uint) -> &'a V { + pub fn get<'a>(&'a self, key: &uint) -> &'a V { self.find(key).expect("key not present") } } -pub impl SmallIntMap { - fn update_with_key(&mut self, key: uint, val: V, - ff: &fn(uint, V, V) -> V) -> bool { +impl SmallIntMap { + pub fn update_with_key(&mut self, key: uint, val: V, + ff: &fn(uint, V, V) -> V) -> bool { let new_val = match self.find(&key) { None => val, Some(orig) => ff(key, *orig, val) @@ -182,7 +184,8 @@ pub impl SmallIntMap { self.insert(key, new_val) } - fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V) -> bool { + pub fn update(&mut self, key: uint, newval: V, ff: &fn(V, V) -> V) + -> bool { self.update_with_key(key, newval, |_k, v, v1| ff(v,v1)) } } @@ -280,9 +283,9 @@ impl Set for SmallIntSet { } } -pub impl SmallIntSet { +impl SmallIntSet { /// Create an empty SmallIntSet - fn new() -> SmallIntSet { SmallIntSet{map: SmallIntMap::new()} } + pub fn new() -> SmallIntSet { SmallIntSet{map: SmallIntMap::new()} } } #[cfg(test)] diff --git a/src/libextra/sync.rs b/src/libextra/sync.rs index 5a1982d830d65..29a2dec38ab67 100644 --- a/src/libextra/sync.rs +++ b/src/libextra/sync.rs @@ -99,8 +99,8 @@ fn new_sem_and_signal(count: int, num_condvars: uint) } #[doc(hidden)] -pub impl Sem { - fn acquire(&self) { +impl Sem { + pub fn acquire(&self) { unsafe { let mut waiter_nobe = None; do (**self).with |state| { @@ -122,7 +122,8 @@ pub impl Sem { } } } - fn release(&self) { + + pub fn release(&self) { unsafe { do (**self).with |state| { state.count += 1; @@ -135,8 +136,8 @@ pub impl Sem { } // FIXME(#3154) move both copies of this into Sem, and unify the 2 structs #[doc(hidden)] -pub impl Sem<()> { - fn access(&self, blk: &fn() -> U) -> U { +impl Sem<()> { + pub fn access(&self, blk: &fn() -> U) -> U { let mut release = None; unsafe { do task::unkillable { @@ -147,9 +148,10 @@ pub impl Sem<()> { blk() } } + #[doc(hidden)] -pub impl Sem<~[Waitqueue]> { - fn access(&self, blk: &fn() -> U) -> U { +impl Sem<~[Waitqueue]> { + pub fn access(&self, blk: &fn() -> U) -> U { let mut release = None; unsafe { do task::unkillable { @@ -193,7 +195,7 @@ pub struct Condvar<'self> { priv sem: &'self Sem<~[Waitqueue]> } #[unsafe_destructor] impl<'self> Drop for Condvar<'self> { fn finalize(&self) {} } -pub impl<'self> Condvar<'self> { +impl<'self> Condvar<'self> { /** * Atomically drop the associated lock, and block until a signal is sent. * @@ -202,7 +204,7 @@ pub impl<'self> Condvar<'self> { * while waiting on a condition variable will wake up, fail, and unlock * the associated lock as it unwinds. */ - fn wait(&self) { self.wait_on(0) } + pub fn wait(&self) { self.wait_on(0) } /** * As wait(), but can specify which of multiple condition variables to @@ -215,7 +217,7 @@ pub impl<'self> Condvar<'self> { * * wait() is equivalent to wait_on(0). */ - fn wait_on(&self, condvar_id: uint) { + pub fn wait_on(&self, condvar_id: uint) { // Create waiter nobe. let (WaitEnd, SignalEnd) = comm::oneshot(); let mut WaitEnd = Some(WaitEnd); @@ -284,10 +286,10 @@ pub impl<'self> Condvar<'self> { } /// Wake up a blocked task. Returns false if there was no blocked task. - fn signal(&self) -> bool { self.signal_on(0) } + pub fn signal(&self) -> bool { self.signal_on(0) } /// As signal, but with a specified condvar_id. See wait_on. - fn signal_on(&self, condvar_id: uint) -> bool { + pub fn signal_on(&self, condvar_id: uint) -> bool { unsafe { let mut out_of_bounds = None; let mut result = false; @@ -305,10 +307,10 @@ pub impl<'self> Condvar<'self> { } /// Wake up all blocked tasks. Returns the number of tasks woken. - fn broadcast(&self) -> uint { self.broadcast_on(0) } + pub fn broadcast(&self) -> uint { self.broadcast_on(0) } /// As broadcast, but with a specified condvar_id. See wait_on. - fn broadcast_on(&self, condvar_id: uint) -> uint { + pub fn broadcast_on(&self, condvar_id: uint) -> uint { let mut out_of_bounds = None; let mut queue = None; unsafe { @@ -347,9 +349,9 @@ fn check_cvar_bounds(out_of_bounds: Option, id: uint, act: &str, } #[doc(hidden)] -pub impl Sem<~[Waitqueue]> { +impl Sem<~[Waitqueue]> { // The only other place that condvars get built is rwlock_write_mode. - fn access_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn access_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { do self.access { blk(&Condvar { sem: self }) } } } @@ -373,21 +375,21 @@ impl Clone for Semaphore { } } -pub impl Semaphore { +impl Semaphore { /** * Acquire a resource represented by the semaphore. Blocks if necessary * until resource(s) become available. */ - fn acquire(&self) { (&self.sem).acquire() } + pub fn acquire(&self) { (&self.sem).acquire() } /** * Release a held resource represented by the semaphore. Wakes a blocked * contending task, if any exist. Won't block the caller. */ - fn release(&self) { (&self.sem).release() } + pub fn release(&self) { (&self.sem).release() } /// Run a function with ownership of one of the semaphore's resources. - fn access(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) } + pub fn access(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) } } /**************************************************************************** @@ -421,12 +423,12 @@ impl Clone for Mutex { fn clone(&self) -> Mutex { Mutex { sem: Sem((*self.sem).clone()) } } } -pub impl Mutex { +impl Mutex { /// Run a function with ownership of the mutex. - fn lock(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) } + pub fn lock(&self, blk: &fn() -> U) -> U { (&self.sem).access(blk) } /// Run a function with ownership of the mutex and a handle to a condvar. - fn lock_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn lock_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { (&self.sem).access_cond(blk) } } @@ -470,9 +472,9 @@ pub fn rwlock_with_condvars(num_condvars: uint) -> RWlock { read_count: 0 }) } } -pub impl RWlock { +impl RWlock { /// Create a new handle to the rwlock. - fn clone(&self) -> RWlock { + pub fn clone(&self) -> RWlock { RWlock { order_lock: (&(self.order_lock)).clone(), access_lock: Sem((*self.access_lock).clone()), state: self.state.clone() } @@ -482,7 +484,7 @@ pub impl RWlock { * Run a function with the rwlock in read mode. Calls to 'read' from other * tasks may run concurrently with this one. */ - fn read(&self, blk: &fn() -> U) -> U { + pub fn read(&self, blk: &fn() -> U) -> U { let mut release = None; unsafe { do task::unkillable { @@ -513,7 +515,7 @@ pub impl RWlock { * Run a function with the rwlock in write mode. No calls to 'read' or * 'write' from other tasks will run concurrently with this one. */ - fn write(&self, blk: &fn() -> U) -> U { + pub fn write(&self, blk: &fn() -> U) -> U { unsafe { do task::unkillable { (&self.order_lock).acquire(); @@ -531,7 +533,7 @@ pub impl RWlock { * the waiting task is signalled. (Note: a writer that waited and then * was signalled might reacquire the lock before other waiting writers.) */ - fn write_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn write_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { // NB: You might think I should thread the order_lock into the cond // wait call, so that it gets waited on before access_lock gets // reacquired upon being woken up. However, (a) this would be not @@ -569,7 +571,7 @@ pub impl RWlock { * } * ~~~ */ - fn write_downgrade(&self, blk: &fn(v: RWlockWriteMode) -> U) -> U { + pub fn write_downgrade(&self, blk: &fn(v: RWlockWriteMode) -> U) -> U { // Implementation slightly different from the slicker 'write's above. // The exit path is conditional on whether the caller downgrades. let mut _release = None; @@ -585,9 +587,8 @@ pub impl RWlock { } /// To be called inside of the write_downgrade block. - fn downgrade<'a>(&self, - token: RWlockWriteMode<'a>) - -> RWlockReadMode<'a> { + pub fn downgrade<'a>(&self, token: RWlockWriteMode<'a>) + -> RWlockReadMode<'a> { if !ptr::ref_eq(self, token.lock) { fail!("Can't downgrade() with a different rwlock's write_mode!"); } @@ -703,18 +704,18 @@ pub struct RWlockReadMode<'self> { priv lock: &'self RWlock } #[unsafe_destructor] impl<'self> Drop for RWlockReadMode<'self> { fn finalize(&self) {} } -pub impl<'self> RWlockWriteMode<'self> { +impl<'self> RWlockWriteMode<'self> { /// Access the pre-downgrade rwlock in write mode. - fn write(&self, blk: &fn() -> U) -> U { blk() } + pub fn write(&self, blk: &fn() -> U) -> U { blk() } /// Access the pre-downgrade rwlock in write mode with a condvar. - fn write_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { + pub fn write_cond(&self, blk: &fn(c: &Condvar) -> U) -> U { blk(&Condvar { sem: &self.lock.access_lock }) } } -pub impl<'self> RWlockReadMode<'self> { +impl<'self> RWlockReadMode<'self> { /// Access the post-downgrade rwlock in read mode. - fn read(&self, blk: &fn() -> U) -> U { blk() } + pub fn read(&self, blk: &fn() -> U) -> U { blk() } } /**************************************************************************** diff --git a/src/libextra/task_pool.rs b/src/libextra/task_pool.rs index 06bc3167040d2..b88bbff2a6668 100644 --- a/src/libextra/task_pool.rs +++ b/src/libextra/task_pool.rs @@ -42,16 +42,16 @@ impl Drop for TaskPool { } } -pub impl TaskPool { +impl TaskPool { /// Spawns a new task pool with `n_tasks` tasks. If the `sched_mode` /// is None, the tasks run on this scheduler; otherwise, they run on a /// new scheduler with the given mode. The provided `init_fn_factory` /// returns a function which, given the index of the task, should return /// local data to be kept around in that task. - fn new(n_tasks: uint, - opt_sched_mode: Option, - init_fn_factory: ~fn() -> ~fn(uint) -> T) - -> TaskPool { + pub fn new(n_tasks: uint, + opt_sched_mode: Option, + init_fn_factory: ~fn() -> ~fn(uint) -> T) + -> TaskPool { assert!(n_tasks >= 1); let channels = do vec::from_fn(n_tasks) |i| { @@ -89,7 +89,7 @@ pub impl TaskPool { /// Executes the function `f` on a task in the pool. The function /// receives a reference to the local data returned by the `init_fn`. - fn execute(&mut self, f: ~fn(&T)) { + pub fn execute(&mut self, f: ~fn(&T)) { self.channels[self.next_index].send(Execute(f)); self.next_index += 1; if self.next_index == self.channels.len() { self.next_index = 0; } diff --git a/src/libextra/test.rs b/src/libextra/test.rs index 141700bd0b3a3..16743d27a17cc 100644 --- a/src/libextra/test.rs +++ b/src/libextra/test.rs @@ -617,8 +617,7 @@ pub mod bench { use test::{BenchHarness, BenchSamples}; use time::precise_time_ns; - pub impl BenchHarness { - + impl BenchHarness { /// Callback for benchmark functions to run in their body. pub fn iter(&mut self, inner:&fn()) { self.ns_start = precise_time_ns(); @@ -629,7 +628,7 @@ pub mod bench { self.ns_end = precise_time_ns(); } - fn ns_elapsed(&mut self) -> u64 { + pub fn ns_elapsed(&mut self) -> u64 { if self.ns_start == 0 || self.ns_end == 0 { 0 } else { @@ -637,7 +636,7 @@ pub mod bench { } } - fn ns_per_iter(&mut self) -> u64 { + pub fn ns_per_iter(&mut self) -> u64 { if self.iterations == 0 { 0 } else { @@ -645,7 +644,7 @@ pub mod bench { } } - fn bench_n(&mut self, n: u64, f: &fn(&mut BenchHarness)) { + pub fn bench_n(&mut self, n: u64, f: &fn(&mut BenchHarness)) { self.iterations = n; debug!("running benchmark for %u iterations", n as uint); diff --git a/src/libextra/time.rs b/src/libextra/time.rs index 1a3a5db66aef9..758181980a832 100644 --- a/src/libextra/time.rs +++ b/src/libextra/time.rs @@ -49,8 +49,8 @@ pub struct Timespec { sec: i64, nsec: i32 } * -1.2 seconds before the epoch is represented by `Timespec { sec: -2_i64, * nsec: 800_000_000_i32 }`. */ -pub impl Timespec { - fn new(sec: i64, nsec: i32) -> Timespec { +impl Timespec { + pub fn new(sec: i64, nsec: i32) -> Timespec { assert!(nsec >= 0 && nsec < NSEC_PER_SEC); Timespec { sec: sec, nsec: nsec } } @@ -180,9 +180,9 @@ pub fn strftime(format: &str, tm: &Tm) -> ~str { do_strftime(format, tm) } -pub impl Tm { +impl Tm { /// Convert time to the seconds from January 1, 1970 - fn to_timespec(&self) -> Timespec { + pub fn to_timespec(&self) -> Timespec { unsafe { let sec = match self.tm_gmtoff { 0_i32 => rustrt::rust_timegm(self), @@ -194,12 +194,12 @@ pub impl Tm { } /// Convert time to the local timezone - fn to_local(&self) -> Tm { + pub fn to_local(&self) -> Tm { at(self.to_timespec()) } /// Convert time to the UTC - fn to_utc(&self) -> Tm { + pub fn to_utc(&self) -> Tm { at_utc(self.to_timespec()) } @@ -207,10 +207,10 @@ pub impl Tm { * Return a string of the current time in the form * "Thu Jan 1 00:00:00 1970". */ - fn ctime(&self) -> ~str { self.strftime("%c") } + pub fn ctime(&self) -> ~str { self.strftime("%c") } /// Formats the time according to the format string. - fn strftime(&self, format: &str) -> ~str { + pub fn strftime(&self, format: &str) -> ~str { strftime(format, self) } @@ -220,7 +220,7 @@ pub impl Tm { * local: "Thu, 22 Mar 2012 07:53:18 PST" * utc: "Thu, 22 Mar 2012 14:53:18 UTC" */ - fn rfc822(&self) -> ~str { + pub fn rfc822(&self) -> ~str { if self.tm_gmtoff == 0_i32 { self.strftime("%a, %d %b %Y %T GMT") } else { @@ -234,7 +234,7 @@ pub impl Tm { * local: "Thu, 22 Mar 2012 07:53:18 -0700" * utc: "Thu, 22 Mar 2012 14:53:18 -0000" */ - fn rfc822z(&self) -> ~str { + pub fn rfc822z(&self) -> ~str { self.strftime("%a, %d %b %Y %T %z") } @@ -244,7 +244,7 @@ pub impl Tm { * local: "2012-02-22T07:53:18-07:00" * utc: "2012-02-22T14:53:18Z" */ - fn rfc3339(&self) -> ~str { + pub fn rfc3339(&self) -> ~str { if self.tm_gmtoff == 0_i32 { self.strftime("%Y-%m-%dT%H:%M:%SZ") } else { diff --git a/src/libextra/treemap.rs b/src/libextra/treemap.rs index e6db84e855cf5..c39984791689c 100644 --- a/src/libextra/treemap.rs +++ b/src/libextra/treemap.rs @@ -181,28 +181,28 @@ impl Map for TreeMap { } } -pub impl TreeMap { +impl TreeMap { /// Create an empty TreeMap - fn new() -> TreeMap { TreeMap{root: None, length: 0} } + pub fn new() -> TreeMap { TreeMap{root: None, length: 0} } /// Visit all key-value pairs in reverse order - fn each_reverse<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool { + pub fn each_reverse<'a>(&'a self, f: &fn(&'a K, &'a V) -> bool) -> bool { each_reverse(&self.root, f) } /// Visit all keys in reverse order - fn each_key_reverse(&self, f: &fn(&K) -> bool) -> bool { + pub fn each_key_reverse(&self, f: &fn(&K) -> bool) -> bool { self.each_reverse(|k, _| f(k)) } /// Visit all values in reverse order - fn each_value_reverse(&self, f: &fn(&V) -> bool) -> bool { + pub fn each_value_reverse(&self, f: &fn(&V) -> bool) -> bool { self.each_reverse(|_, v| f(v)) } /// Get a lazy iterator over the key-value pairs in the map. /// Requires that it be frozen (immutable). - fn iter<'a>(&'a self) -> TreeMapIterator<'a, K, V> { + pub fn iter<'a>(&'a self) -> TreeMapIterator<'a, K, V> { TreeMapIterator{stack: ~[], node: &self.root} } } @@ -489,15 +489,15 @@ impl Set for TreeSet { } } -pub impl TreeSet { +impl TreeSet { /// Create an empty TreeSet #[inline(always)] - fn new() -> TreeSet { TreeSet{map: TreeMap::new()} } + pub fn new() -> TreeSet { TreeSet{map: TreeMap::new()} } /// Get a lazy iterator over the values in the set. /// Requires that it be frozen (immutable). #[inline(always)] - fn iter<'a>(&'a self) -> TreeSetIterator<'a, T> { + pub fn iter<'a>(&'a self) -> TreeSetIterator<'a, T> { TreeSetIterator{iter: self.map.iter()} } } @@ -517,9 +517,10 @@ struct TreeNode { level: uint } -pub impl TreeNode { +impl TreeNode { + /// Creates a new tree node. #[inline(always)] - fn new(key: K, value: V) -> TreeNode { + pub fn new(key: K, value: V) -> TreeNode { TreeNode{key: key, value: value, left: None, right: None, level: 1} } } diff --git a/src/libextra/workcache.rs b/src/libextra/workcache.rs index 47a717a56a58e..5d494b1b9165b 100644 --- a/src/libextra/workcache.rs +++ b/src/libextra/workcache.rs @@ -127,9 +127,12 @@ impl cmp::Ord for WorkKey { } } -pub impl WorkKey { - fn new(kind: &str, name: &str) -> WorkKey { - WorkKey { kind: kind.to_owned(), name: name.to_owned() } +impl WorkKey { + pub fn new(kind: &str, name: &str) -> WorkKey { + WorkKey { + kind: kind.to_owned(), + name: name.to_owned(), + } } } @@ -167,11 +170,11 @@ struct Database { db_dirty: bool } -pub impl Database { - fn prepare(&mut self, - fn_name: &str, - declared_inputs: &WorkMap) - -> Option<(WorkMap, WorkMap, ~str)> { +impl Database { + pub fn prepare(&mut self, + fn_name: &str, + declared_inputs: &WorkMap) + -> Option<(WorkMap, WorkMap, ~str)> { let k = json_encode(&(fn_name, declared_inputs)); match self.db_cache.find(&k) { None => None, @@ -179,12 +182,12 @@ pub impl Database { } } - fn cache(&mut self, - fn_name: &str, - declared_inputs: &WorkMap, - discovered_inputs: &WorkMap, - discovered_outputs: &WorkMap, - result: &str) { + pub fn cache(&mut self, + fn_name: &str, + declared_inputs: &WorkMap, + discovered_inputs: &WorkMap, + discovered_outputs: &WorkMap, + result: &str) { let k = json_encode(&(fn_name, declared_inputs)); let v = json_encode(&(discovered_inputs, discovered_outputs, @@ -199,8 +202,8 @@ struct Logger { a: () } -pub impl Logger { - fn info(&self, i: &str) { +impl Logger { + pub fn info(&self, i: &str) { io::println(~"workcache: " + i); } } @@ -257,11 +260,9 @@ fn digest_file(path: &Path) -> ~str { sha.result_str() } -pub impl Context { - - fn new(db: @mut Database, - lg: @mut Logger, - cfg: @json::Object) -> Context { +impl Context { + pub fn new(db: @mut Database, lg: @mut Logger, cfg: @json::Object) + -> Context { Context { db: db, logger: lg, @@ -270,12 +271,12 @@ pub impl Context { } } - fn prep + - Decodable>( // FIXME(#5121) - @self, - fn_name:&str, - blk: &fn(@mut Prep)->Work) -> Work { + pub fn prep + + Decodable>(@self, // FIXME(#5121) + fn_name:&str, + blk: &fn(@mut Prep)->Work) + -> Work { let p = @mut Prep { ctxt: self, fn_name: fn_name.to_owned(), @@ -363,10 +364,10 @@ impl TPrep for Prep { } } -pub impl + - Decodable> Work { // FIXME(#5121) - fn new(p: @mut Prep, e: Either>) -> Work { +impl + + Decodable> Work { // FIXME(#5121) + pub fn new(p: @mut Prep, e: Either>) -> Work { Work { prep: p, res: Some(e) } } } diff --git a/src/librustc/driver/session.rs b/src/librustc/driver/session.rs index 25c860ab2f0a8..ab895221de133 100644 --- a/src/librustc/driver/session.rs +++ b/src/librustc/driver/session.rs @@ -188,112 +188,116 @@ pub struct Session_ { pub type Session = @Session_; -pub impl Session_ { - fn span_fatal(@self, sp: span, msg: &str) -> ! { +impl Session_ { + pub fn span_fatal(@self, sp: span, msg: &str) -> ! { self.span_diagnostic.span_fatal(sp, msg) } - fn fatal(@self, msg: &str) -> ! { + pub fn fatal(@self, msg: &str) -> ! { self.span_diagnostic.handler().fatal(msg) } - fn span_err(@self, sp: span, msg: &str) { + pub fn span_err(@self, sp: span, msg: &str) { self.span_diagnostic.span_err(sp, msg) } - fn err(@self, msg: &str) { + pub fn err(@self, msg: &str) { self.span_diagnostic.handler().err(msg) } - fn err_count(@self) -> uint { + pub fn err_count(@self) -> uint { self.span_diagnostic.handler().err_count() } - fn has_errors(@self) -> bool { + pub fn has_errors(@self) -> bool { self.span_diagnostic.handler().has_errors() } - fn abort_if_errors(@self) { + pub fn abort_if_errors(@self) { self.span_diagnostic.handler().abort_if_errors() } - fn span_warn(@self, sp: span, msg: &str) { + pub fn span_warn(@self, sp: span, msg: &str) { self.span_diagnostic.span_warn(sp, msg) } - fn warn(@self, msg: &str) { + pub fn warn(@self, msg: &str) { self.span_diagnostic.handler().warn(msg) } - fn span_note(@self, sp: span, msg: &str) { + pub fn span_note(@self, sp: span, msg: &str) { self.span_diagnostic.span_note(sp, msg) } - fn note(@self, msg: &str) { + pub fn note(@self, msg: &str) { self.span_diagnostic.handler().note(msg) } - fn span_bug(@self, sp: span, msg: &str) -> ! { + pub fn span_bug(@self, sp: span, msg: &str) -> ! { self.span_diagnostic.span_bug(sp, msg) } - fn bug(@self, msg: &str) -> ! { + pub fn bug(@self, msg: &str) -> ! { self.span_diagnostic.handler().bug(msg) } - fn span_unimpl(@self, sp: span, msg: &str) -> ! { + pub fn span_unimpl(@self, sp: span, msg: &str) -> ! { self.span_diagnostic.span_unimpl(sp, msg) } - fn unimpl(@self, msg: &str) -> ! { + pub fn unimpl(@self, msg: &str) -> ! { self.span_diagnostic.handler().unimpl(msg) } - fn add_lint(@self, lint: lint::lint, id: ast::node_id, sp: span, msg: ~str) { + pub fn add_lint(@self, + lint: lint::lint, + id: ast::node_id, + sp: span, + msg: ~str) { match self.lints.find_mut(&id) { Some(arr) => { arr.push((lint, sp, msg)); return; } None => {} } self.lints.insert(id, ~[(lint, sp, msg)]); } - fn next_node_id(@self) -> ast::node_id { + pub fn next_node_id(@self) -> ast::node_id { return syntax::parse::next_node_id(self.parse_sess); } - fn diagnostic(@self) -> @diagnostic::span_handler { + pub fn diagnostic(@self) -> @diagnostic::span_handler { self.span_diagnostic } - fn debugging_opt(@self, opt: uint) -> bool { + pub fn debugging_opt(@self, opt: uint) -> bool { (self.opts.debugging_opts & opt) != 0u } // This exists to help with refactoring to eliminate impossible // cases later on - fn impossible_case(@self, sp: span, msg: &str) -> ! { + pub fn impossible_case(@self, sp: span, msg: &str) -> ! { self.span_bug(sp, fmt!("Impossible case reached: %s", msg)); } - fn verbose(@self) -> bool { self.debugging_opt(verbose) } - fn time_passes(@self) -> bool { self.debugging_opt(time_passes) } - fn count_llvm_insns(@self) -> bool { + pub fn verbose(@self) -> bool { self.debugging_opt(verbose) } + pub fn time_passes(@self) -> bool { self.debugging_opt(time_passes) } + pub fn count_llvm_insns(@self) -> bool { self.debugging_opt(count_llvm_insns) } - fn count_type_sizes(@self) -> bool { + pub fn count_type_sizes(@self) -> bool { self.debugging_opt(count_type_sizes) } - fn time_llvm_passes(@self) -> bool { + pub fn time_llvm_passes(@self) -> bool { self.debugging_opt(time_llvm_passes) } - fn trans_stats(@self) -> bool { self.debugging_opt(trans_stats) } - fn meta_stats(@self) -> bool { self.debugging_opt(meta_stats) } - fn asm_comments(@self) -> bool { self.debugging_opt(asm_comments) } - fn no_verify(@self) -> bool { self.debugging_opt(no_verify) } - fn lint_llvm(@self) -> bool { self.debugging_opt(lint_llvm) } - fn trace(@self) -> bool { self.debugging_opt(trace) } - fn coherence(@self) -> bool { self.debugging_opt(coherence) } - fn borrowck_stats(@self) -> bool { self.debugging_opt(borrowck_stats) } - fn borrowck_note_pure(@self) -> bool { + pub fn trans_stats(@self) -> bool { self.debugging_opt(trans_stats) } + pub fn meta_stats(@self) -> bool { self.debugging_opt(meta_stats) } + pub fn asm_comments(@self) -> bool { self.debugging_opt(asm_comments) } + pub fn no_verify(@self) -> bool { self.debugging_opt(no_verify) } + pub fn lint_llvm(@self) -> bool { self.debugging_opt(lint_llvm) } + pub fn trace(@self) -> bool { self.debugging_opt(trace) } + pub fn coherence(@self) -> bool { self.debugging_opt(coherence) } + pub fn borrowck_stats(@self) -> bool { self.debugging_opt(borrowck_stats) } + pub fn borrowck_note_pure(@self) -> bool { self.debugging_opt(borrowck_note_pure) } - fn borrowck_note_loan(@self) -> bool { + pub fn borrowck_note_loan(@self) -> bool { self.debugging_opt(borrowck_note_loan) } - fn no_monomorphic_collapse(@self) -> bool { + pub fn no_monomorphic_collapse(@self) -> bool { self.debugging_opt(no_monomorphic_collapse) } - fn debug_borrows(@self) -> bool { + pub fn debug_borrows(@self) -> bool { self.opts.optimize == No && !self.debugging_opt(no_debug_borrows) } - fn str_of(@self, id: ast::ident) -> @~str { + pub fn str_of(@self, id: ast::ident) -> @~str { self.parse_sess.interner.get(id) } - fn ident_of(@self, st: &str) -> ast::ident { + pub fn ident_of(@self, st: &str) -> ast::ident { self.parse_sess.interner.intern(st) } - fn intr(@self) -> @syntax::parse::token::ident_interner { + pub fn intr(@self) -> @syntax::parse::token::ident_interner { self.parse_sess.interner } } diff --git a/src/librustc/middle/astencode.rs b/src/librustc/middle/astencode.rs index 276b78d2e12d0..c26e91cc5ec84 100644 --- a/src/librustc/middle/astencode.rs +++ b/src/librustc/middle/astencode.rs @@ -163,8 +163,8 @@ fn reserve_id_range(sess: Session, ast_util::id_range { min: to_id_min, max: to_id_min } } -pub impl ExtendedDecodeContext { - fn tr_id(&self, id: ast::node_id) -> ast::node_id { +impl ExtendedDecodeContext { + pub fn tr_id(&self, id: ast::node_id) -> ast::node_id { /*! * Translates an internal id, meaning a node id that is known * to refer to some part of the item currently being inlined, @@ -179,7 +179,7 @@ pub impl ExtendedDecodeContext { assert!(!self.from_id_range.empty()); (id - self.from_id_range.min + self.to_id_range.min) } - fn tr_def_id(&self, did: ast::def_id) -> ast::def_id { + pub fn tr_def_id(&self, did: ast::def_id) -> ast::def_id { /*! * Translates an EXTERNAL def-id, converting the crate number * from the one used in the encoded data to the current crate @@ -203,7 +203,7 @@ pub impl ExtendedDecodeContext { decoder::translate_def_id(self.dcx.cdata, did) } - fn tr_intern_def_id(&self, did: ast::def_id) -> ast::def_id { + pub fn tr_intern_def_id(&self, did: ast::def_id) -> ast::def_id { /*! * Translates an INTERNAL def-id, meaning a def-id that is * known to refer to some part of the item currently being @@ -214,7 +214,7 @@ pub impl ExtendedDecodeContext { assert_eq!(did.crate, ast::local_crate); ast::def_id { crate: ast::local_crate, node: self.tr_id(did.node) } } - fn tr_span(&self, _span: span) -> span { + pub fn tr_span(&self, _span: span) -> span { codemap::dummy_sp() // FIXME (#1972): handle span properly } } diff --git a/src/librustc/middle/borrowck/check_loans.rs b/src/librustc/middle/borrowck/check_loans.rs index 1801585900b64..5d0def6f60a88 100644 --- a/src/librustc/middle/borrowck/check_loans.rs +++ b/src/librustc/middle/borrowck/check_loans.rs @@ -69,13 +69,13 @@ enum MoveError { MoveWhileBorrowed(/*move*/@LoanPath, /*loan*/@LoanPath, /*loan*/span) } -pub impl<'self> CheckLoanCtxt<'self> { - fn tcx(&self) -> ty::ctxt { self.bccx.tcx } +impl<'self> CheckLoanCtxt<'self> { + pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx } - fn each_issued_loan(&self, - scope_id: ast::node_id, - op: &fn(&Loan) -> bool) -> bool - { + pub fn each_issued_loan(&self, + scope_id: ast::node_id, + op: &fn(&Loan) -> bool) + -> bool { //! Iterates over each loan that that has been issued //! on entrance to `scope_id`, regardless of whether it is //! actually *in scope* at that point. Sometimes loans @@ -91,10 +91,10 @@ pub impl<'self> CheckLoanCtxt<'self> { return true; } - fn each_in_scope_loan(&self, - scope_id: ast::node_id, - op: &fn(&Loan) -> bool) -> bool - { + pub fn each_in_scope_loan(&self, + scope_id: ast::node_id, + op: &fn(&Loan) -> bool) + -> bool { //! Like `each_issued_loan()`, but only considers loans that are //! currently in scope. @@ -109,11 +109,11 @@ pub impl<'self> CheckLoanCtxt<'self> { return true; } - fn each_in_scope_restriction(&self, - scope_id: ast::node_id, - loan_path: @LoanPath, - op: &fn(&Loan, &Restriction) -> bool) -> bool - { + pub fn each_in_scope_restriction(&self, + scope_id: ast::node_id, + loan_path: @LoanPath, + op: &fn(&Loan, &Restriction) -> bool) + -> bool { //! Iterates through all the in-scope restrictions for the //! given `loan_path` @@ -129,7 +129,7 @@ pub impl<'self> CheckLoanCtxt<'self> { return true; } - fn loans_generated_by(&self, scope_id: ast::node_id) -> ~[uint] { + pub fn loans_generated_by(&self, scope_id: ast::node_id) -> ~[uint] { //! Returns a vector of the loans that are generated as //! we encounter `scope_id`. @@ -140,7 +140,7 @@ pub impl<'self> CheckLoanCtxt<'self> { return result; } - fn check_for_conflicting_loans(&mut self, scope_id: ast::node_id) { + pub fn check_for_conflicting_loans(&mut self, scope_id: ast::node_id) { //! Checks to see whether any of the loans that are issued //! by `scope_id` conflict with loans that have already been //! issued when we enter `scope_id` (for example, we do not @@ -167,9 +167,9 @@ pub impl<'self> CheckLoanCtxt<'self> { } } - fn report_error_if_loans_conflict(&self, - old_loan: &Loan, - new_loan: &Loan) { + pub fn report_error_if_loans_conflict(&self, + old_loan: &Loan, + new_loan: &Loan) { //! Checks whether `old_loan` and `new_loan` can safely be issued //! simultaneously. @@ -188,11 +188,12 @@ pub impl<'self> CheckLoanCtxt<'self> { new_loan, old_loan, old_loan, new_loan); } - fn report_error_if_loan_conflicts_with_restriction(&self, - loan1: &Loan, - loan2: &Loan, - old_loan: &Loan, - new_loan: &Loan) -> bool { + pub fn report_error_if_loan_conflicts_with_restriction(&self, + loan1: &Loan, + loan2: &Loan, + old_loan: &Loan, + new_loan: &Loan) + -> bool { //! Checks whether the restrictions introduced by `loan1` would //! prohibit `loan2`. Returns false if an error is reported. @@ -247,18 +248,18 @@ pub impl<'self> CheckLoanCtxt<'self> { true } - fn is_local_variable(&self, cmt: mc::cmt) -> bool { + pub fn is_local_variable(&self, cmt: mc::cmt) -> bool { match cmt.cat { mc::cat_local(_) => true, _ => false } } - fn check_if_path_is_moved(&self, - id: ast::node_id, - span: span, - use_kind: MovedValueUseKind, - lp: @LoanPath) { + pub fn check_if_path_is_moved(&self, + id: ast::node_id, + span: span, + use_kind: MovedValueUseKind, + lp: @LoanPath) { /*! * Reports an error if `expr` (which should be a path) * is using a moved/uninitialized value @@ -277,7 +278,7 @@ pub impl<'self> CheckLoanCtxt<'self> { } } - fn check_assignment(&self, expr: @ast::expr) { + pub fn check_assignment(&self, expr: @ast::expr) { // We don't use cat_expr() here because we don't want to treat // auto-ref'd parameters in overloaded operators as rvalues. let cmt = match self.bccx.tcx.adjustments.find(&expr.id) { @@ -533,10 +534,10 @@ pub impl<'self> CheckLoanCtxt<'self> { } } - fn report_illegal_mutation(&self, - expr: @ast::expr, - loan_path: &LoanPath, - loan: &Loan) { + pub fn report_illegal_mutation(&self, + expr: @ast::expr, + loan_path: &LoanPath, + loan: &Loan) { self.bccx.span_err( expr.span, fmt!("cannot assign to `%s` because it is borrowed", @@ -547,7 +548,7 @@ pub impl<'self> CheckLoanCtxt<'self> { self.bccx.loan_path_to_str(loan_path))); } - fn check_move_out_from_expr(&self, ex: @ast::expr) { + pub fn check_move_out_from_expr(&self, ex: @ast::expr) { match ex.node { ast::expr_paren(*) => { /* In the case of an expr_paren(), the expression inside @@ -574,7 +575,7 @@ pub impl<'self> CheckLoanCtxt<'self> { } } - fn analyze_move_out_from_cmt(&self, cmt: mc::cmt) -> MoveError { + pub fn analyze_move_out_from_cmt(&self, cmt: mc::cmt) -> MoveError { debug!("analyze_move_out_from_cmt(cmt=%s)", cmt.repr(self.tcx())); // FIXME(#4384) inadequare if/when we permit `move a.b` @@ -590,13 +591,12 @@ pub impl<'self> CheckLoanCtxt<'self> { return MoveOk; } - fn check_call(&mut self, - _expr: @ast::expr, - _callee: Option<@ast::expr>, - _callee_id: ast::node_id, - _callee_span: span, - _args: &[@ast::expr]) - { + pub fn check_call(&mut self, + _expr: @ast::expr, + _callee: Option<@ast::expr>, + _callee_id: ast::node_id, + _callee_span: span, + _args: &[@ast::expr]) { // NB: This call to check for conflicting loans is not truly // necessary, because the callee_id never issues new loans. // However, I added it for consistency and lest the system diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index 552476d25d6f4..83d039b75200f 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -273,21 +273,21 @@ fn gather_loans_in_expr(ex: @ast::expr, } } -pub impl GatherLoanCtxt { - fn tcx(&self) -> ty::ctxt { self.bccx.tcx } +impl GatherLoanCtxt { + pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx } - fn push_repeating_id(&mut self, id: ast::node_id) { + pub fn push_repeating_id(&mut self, id: ast::node_id) { self.repeating_ids.push(id); } - fn pop_repeating_id(&mut self, id: ast::node_id) { + pub fn pop_repeating_id(&mut self, id: ast::node_id) { let popped = self.repeating_ids.pop(); assert_eq!(id, popped); } - fn guarantee_adjustments(&mut self, - expr: @ast::expr, - adjustment: &ty::AutoAdjustment) { + pub fn guarantee_adjustments(&mut self, + expr: @ast::expr, + adjustment: &ty::AutoAdjustment) { debug!("guarantee_adjustments(expr=%s, adjustment=%?)", expr.repr(self.tcx()), adjustment); let _i = indenter(); @@ -350,13 +350,12 @@ pub impl GatherLoanCtxt { // out loans, which will be added to the `req_loan_map`. This can // also entail "rooting" GC'd pointers, which means ensuring // dynamically that they are not freed. - fn guarantee_valid(&mut self, - borrow_id: ast::node_id, - borrow_span: span, - cmt: mc::cmt, - req_mutbl: ast::mutability, - loan_region: ty::Region) - { + pub fn guarantee_valid(&mut self, + borrow_id: ast::node_id, + borrow_span: span, + cmt: mc::cmt, + req_mutbl: ast::mutability, + loan_region: ty::Region) { debug!("guarantee_valid(borrow_id=%?, cmt=%s, \ req_mutbl=%?, loan_region=%?)", borrow_id, @@ -514,7 +513,8 @@ pub impl GatherLoanCtxt { } } - fn restriction_set(&self, req_mutbl: ast::mutability) -> RestrictionSet { + pub fn restriction_set(&self, req_mutbl: ast::mutability) + -> RestrictionSet { match req_mutbl { m_const => RESTR_EMPTY, m_imm => RESTR_EMPTY | RESTR_MUTATE | RESTR_CLAIM, @@ -522,7 +522,7 @@ pub impl GatherLoanCtxt { } } - fn mark_loan_path_as_mutated(&self, loan_path: @LoanPath) { + pub fn mark_loan_path_as_mutated(&self, loan_path: @LoanPath) { //! For mutable loans of content whose mutability derives //! from a local variable, mark the mutability decl as necessary. @@ -540,9 +540,10 @@ pub impl GatherLoanCtxt { } } - fn compute_gen_scope(&self, - borrow_id: ast::node_id, - loan_scope: ast::node_id) -> ast::node_id { + pub fn compute_gen_scope(&self, + borrow_id: ast::node_id, + loan_scope: ast::node_id) + -> ast::node_id { //! Determine when to introduce the loan. Typically the loan //! is introduced at the point of the borrow, but in some cases, //! notably method arguments, the loan may be introduced only @@ -556,9 +557,8 @@ pub impl GatherLoanCtxt { } } - fn compute_kill_scope(&self, - loan_scope: ast::node_id, - lp: @LoanPath) -> ast::node_id { + pub fn compute_kill_scope(&self, loan_scope: ast::node_id, lp: @LoanPath) + -> ast::node_id { //! Determine when the loan restrictions go out of scope. //! This is either when the lifetime expires or when the //! local variable which roots the loan-path goes out of scope, @@ -588,11 +588,11 @@ pub impl GatherLoanCtxt { } } - fn gather_pat(&mut self, - discr_cmt: mc::cmt, - root_pat: @ast::pat, - arm_body_id: ast::node_id, - match_id: ast::node_id) { + pub fn gather_pat(&mut self, + discr_cmt: mc::cmt, + root_pat: @ast::pat, + arm_body_id: ast::node_id, + match_id: ast::node_id) { do self.bccx.cat_pattern(discr_cmt, root_pat) |cmt, pat| { match pat.node { ast::pat_ident(bm, _, _) if self.pat_is_binding(pat) => { @@ -653,9 +653,8 @@ pub impl GatherLoanCtxt { } } - fn vec_slice_info(&self, - pat: @ast::pat, - slice_ty: ty::t) -> (ast::mutability, ty::Region) { + pub fn vec_slice_info(&self, pat: @ast::pat, slice_ty: ty::t) + -> (ast::mutability, ty::Region) { /*! * * In a pattern like [a, b, ..c], normally `c` has slice type, @@ -681,11 +680,11 @@ pub impl GatherLoanCtxt { } } - fn pat_is_variant_or_struct(&self, pat: @ast::pat) -> bool { + pub fn pat_is_variant_or_struct(&self, pat: @ast::pat) -> bool { pat_util::pat_is_variant_or_struct(self.bccx.tcx.def_map, pat) } - fn pat_is_binding(&self, pat: @ast::pat) -> bool { + pub fn pat_is_binding(&self, pat: @ast::pat) -> bool { pat_util::pat_is_binding(self.bccx.tcx.def_map, pat) } } diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 066d0189fcb10..0834d0360832a 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -248,8 +248,8 @@ pub enum LoanPathElem { LpInterior(mc::InteriorKind) // `LV.f` in doc.rs } -pub impl LoanPath { - fn node_id(&self) -> ast::node_id { +impl LoanPath { + pub fn node_id(&self) -> ast::node_id { match *self { LpVar(local_id) => local_id, LpExtend(base, _, _) => base.node_id() @@ -327,12 +327,12 @@ pub static RESTR_CLAIM: RestrictionSet = RestrictionSet {bits: 0b0010}; pub static RESTR_FREEZE: RestrictionSet = RestrictionSet {bits: 0b0100}; pub static RESTR_ALIAS: RestrictionSet = RestrictionSet {bits: 0b1000}; -pub impl RestrictionSet { - fn intersects(&self, restr: RestrictionSet) -> bool { +impl RestrictionSet { + pub fn intersects(&self, restr: RestrictionSet) -> bool { (self.bits & restr.bits) != 0 } - fn contains_all(&self, restr: RestrictionSet) -> bool { + pub fn contains_all(&self, restr: RestrictionSet) -> bool { (self.bits & restr.bits) == restr.bits } } @@ -427,29 +427,33 @@ pub enum MovedValueUseKind { /////////////////////////////////////////////////////////////////////////// // Misc -pub impl BorrowckCtxt { - fn is_subregion_of(&self, r_sub: ty::Region, r_sup: ty::Region) -> bool { +impl BorrowckCtxt { + pub fn is_subregion_of(&self, r_sub: ty::Region, r_sup: ty::Region) + -> bool { self.tcx.region_maps.is_subregion_of(r_sub, r_sup) } - fn is_subscope_of(&self, r_sub: ast::node_id, r_sup: ast::node_id) -> bool { + pub fn is_subscope_of(&self, r_sub: ast::node_id, r_sup: ast::node_id) + -> bool { self.tcx.region_maps.is_subscope_of(r_sub, r_sup) } - fn is_move(&self, id: ast::node_id) -> bool { + pub fn is_move(&self, id: ast::node_id) -> bool { self.moves_map.contains(&id) } - fn cat_expr(&self, expr: @ast::expr) -> mc::cmt { + pub fn cat_expr(&self, expr: @ast::expr) -> mc::cmt { mc::cat_expr(self.tcx, self.method_map, expr) } - fn cat_expr_unadjusted(&self, expr: @ast::expr) -> mc::cmt { + pub fn cat_expr_unadjusted(&self, expr: @ast::expr) -> mc::cmt { mc::cat_expr_unadjusted(self.tcx, self.method_map, expr) } - fn cat_expr_autoderefd(&self, expr: @ast::expr, - adj: @ty::AutoAdjustment) -> mc::cmt { + pub fn cat_expr_autoderefd(&self, + expr: @ast::expr, + adj: @ty::AutoAdjustment) + -> mc::cmt { match *adj { ty::AutoAddEnv(*) => { // no autoderefs @@ -465,46 +469,47 @@ pub impl BorrowckCtxt { } } - fn cat_def(&self, - id: ast::node_id, - span: span, - ty: ty::t, - def: ast::def) -> mc::cmt { + pub fn cat_def(&self, + id: ast::node_id, + span: span, + ty: ty::t, + def: ast::def) + -> mc::cmt { mc::cat_def(self.tcx, self.method_map, id, span, ty, def) } - fn cat_discr(&self, cmt: mc::cmt, match_id: ast::node_id) -> mc::cmt { + pub fn cat_discr(&self, cmt: mc::cmt, match_id: ast::node_id) -> mc::cmt { @mc::cmt_ {cat:mc::cat_discr(cmt, match_id), mutbl:cmt.mutbl.inherit(), ..*cmt} } - fn mc_ctxt(&self) -> mc::mem_categorization_ctxt { + pub fn mc_ctxt(&self) -> mc::mem_categorization_ctxt { mc::mem_categorization_ctxt {tcx: self.tcx, method_map: self.method_map} } - fn cat_pattern(&self, - cmt: mc::cmt, - pat: @ast::pat, - op: &fn(mc::cmt, @ast::pat)) { + pub fn cat_pattern(&self, + cmt: mc::cmt, + pat: @ast::pat, + op: &fn(mc::cmt, @ast::pat)) { let mc = self.mc_ctxt(); mc.cat_pattern(cmt, pat, op); } - fn report(&self, err: BckError) { + pub fn report(&self, err: BckError) { self.span_err( err.span, self.bckerr_to_str(err)); self.note_and_explain_bckerr(err); } - fn report_use_of_moved_value(&self, - use_span: span, - use_kind: MovedValueUseKind, - lp: @LoanPath, - move: &move_data::Move, - moved_lp: @LoanPath) { + pub fn report_use_of_moved_value(&self, + use_span: span, + use_kind: MovedValueUseKind, + lp: @LoanPath, + move: &move_data::Move, + moved_lp: @LoanPath) { let verb = match use_kind { MovedInUse => "use", MovedInCapture => "capture", @@ -563,10 +568,11 @@ pub impl BorrowckCtxt { } } - fn report_reassigned_immutable_variable(&self, - span: span, - lp: @LoanPath, - assign: &move_data::Assignment) { + pub fn report_reassigned_immutable_variable(&self, + span: span, + lp: @LoanPath, + assign: + &move_data::Assignment) { self.tcx.sess.span_err( span, fmt!("re-assignment of immutable variable `%s`", @@ -576,15 +582,15 @@ pub impl BorrowckCtxt { fmt!("prior assignment occurs here")); } - fn span_err(&self, s: span, m: &str) { + pub fn span_err(&self, s: span, m: &str) { self.tcx.sess.span_err(s, m); } - fn span_note(&self, s: span, m: &str) { + pub fn span_note(&self, s: span, m: &str) { self.tcx.sess.span_note(s, m); } - fn bckerr_to_str(&self, err: BckError) -> ~str { + pub fn bckerr_to_str(&self, err: BckError) -> ~str { match err.code { err_mutbl(lk) => { fmt!("cannot borrow %s %s as %s", @@ -608,10 +614,10 @@ pub impl BorrowckCtxt { } } - fn report_aliasability_violation(&self, - span: span, - kind: AliasableViolationKind, - cause: mc::AliasableReason) { + pub fn report_aliasability_violation(&self, + span: span, + kind: AliasableViolationKind, + cause: mc::AliasableReason) { let prefix = match kind { MutabilityViolation => "cannot assign to an `&mut`", BorrowViolation => "cannot borrow an `&mut`" @@ -649,7 +655,7 @@ pub impl BorrowckCtxt { } } - fn note_and_explain_bckerr(&self, err: BckError) { + pub fn note_and_explain_bckerr(&self, err: BckError) { let code = err.code; match code { err_mutbl(*) | err_freeze_aliasable_const(*) => {} @@ -682,9 +688,9 @@ pub impl BorrowckCtxt { } } - fn append_loan_path_to_str_from_interior(&self, - loan_path: &LoanPath, - out: &mut ~str) { + pub fn append_loan_path_to_str_from_interior(&self, + loan_path: &LoanPath, + out: &mut ~str) { match *loan_path { LpExtend(_, _, LpDeref) => { str::push_char(out, '('); @@ -698,7 +704,9 @@ pub impl BorrowckCtxt { } } - fn append_loan_path_to_str(&self, loan_path: &LoanPath, out: &mut ~str) { + pub fn append_loan_path_to_str(&self, + loan_path: &LoanPath, + out: &mut ~str) { match *loan_path { LpVar(id) => { match self.tcx.items.find(&id) { @@ -739,25 +747,25 @@ pub impl BorrowckCtxt { } } - fn loan_path_to_str(&self, loan_path: &LoanPath) -> ~str { + pub fn loan_path_to_str(&self, loan_path: &LoanPath) -> ~str { let mut result = ~""; self.append_loan_path_to_str(loan_path, &mut result); result } - fn cmt_to_str(&self, cmt: mc::cmt) -> ~str { + pub fn cmt_to_str(&self, cmt: mc::cmt) -> ~str { let mc = &mc::mem_categorization_ctxt {tcx: self.tcx, method_map: self.method_map}; mc.cmt_to_str(cmt) } - fn mut_to_str(&self, mutbl: ast::mutability) -> ~str { + pub fn mut_to_str(&self, mutbl: ast::mutability) -> ~str { let mc = &mc::mem_categorization_ctxt {tcx: self.tcx, method_map: self.method_map}; mc.mut_to_str(mutbl) } - fn mut_to_keyword(&self, mutbl: ast::mutability) -> &'static str { + pub fn mut_to_keyword(&self, mutbl: ast::mutability) -> &'static str { match mutbl { ast::m_imm => "", ast::m_const => "const", diff --git a/src/librustc/middle/lang_items.rs b/src/librustc/middle/lang_items.rs index be1aa957666fa..798cba236297b 100644 --- a/src/librustc/middle/lang_items.rs +++ b/src/librustc/middle/lang_items.rs @@ -82,14 +82,14 @@ pub struct LanguageItems { items: [Option, ..38] } -pub impl LanguageItems { +impl LanguageItems { pub fn new() -> LanguageItems { LanguageItems { items: [ None, ..38 ] } } - fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) -> bool { + pub fn each_item(&self, f: &fn(def_id: def_id, i: uint) -> bool) -> bool { self.items.eachi(|i, &item| f(item.get(), i)) } @@ -331,9 +331,10 @@ struct LanguageItemCollector { item_refs: HashMap<@~str, uint>, } -pub impl LanguageItemCollector { - fn match_and_collect_meta_item(&mut self, item_def_id: def_id, - meta_item: @meta_item) { +impl LanguageItemCollector { + pub fn match_and_collect_meta_item(&mut self, + item_def_id: def_id, + meta_item: @meta_item) { match meta_item.node { meta_name_value(key, literal) => { match literal.node { @@ -347,7 +348,7 @@ pub impl LanguageItemCollector { } } - fn collect_item(&mut self, item_index: uint, item_def_id: def_id) { + pub fn collect_item(&mut self, item_index: uint, item_def_id: def_id) { // Check for duplicates. match self.items.items[item_index] { Some(original_def_id) if original_def_id != item_def_id => { @@ -363,8 +364,10 @@ pub impl LanguageItemCollector { self.items.items[item_index] = Some(item_def_id); } - fn match_and_collect_item(&mut self, - item_def_id: def_id, key: @~str, value: @~str) { + pub fn match_and_collect_item(&mut self, + item_def_id: def_id, + key: @~str, + value: @~str) { if *key != ~"lang" { return; // Didn't match. } @@ -384,7 +387,7 @@ pub impl LanguageItemCollector { } } - fn collect_local_language_items(&mut self) { + pub fn collect_local_language_items(&mut self) { let this: *mut LanguageItemCollector = &mut *self; visit_crate(self.crate, (), mk_simple_visitor(@SimpleVisitor { visit_item: |item| { @@ -401,7 +404,7 @@ pub impl LanguageItemCollector { })); } - fn collect_external_language_items(&mut self) { + pub fn collect_external_language_items(&mut self) { let crate_store = self.session.cstore; do iter_crate_data(crate_store) |crate_number, _crate_metadata| { for each_lang_item(crate_store, crate_number) @@ -412,7 +415,7 @@ pub impl LanguageItemCollector { } } - fn check_completeness(&self) { + pub fn check_completeness(&self) { for self.item_refs.each |&key, &item_ref| { match self.items.items[item_ref] { None => { @@ -425,7 +428,7 @@ pub impl LanguageItemCollector { } } - fn collect(&mut self) { + pub fn collect(&mut self) { self.collect_local_language_items(); self.collect_external_language_items(); self.check_completeness(); diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index ee7b21638b240..a9d9d55563a61 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -197,8 +197,10 @@ impl to_str::ToStr for Variable { // variable must not be assigned if there is some successor // assignment. And so forth. -pub impl LiveNode { - fn is_valid(&self) -> bool { **self != uint::max_value } +impl LiveNode { + pub fn is_valid(&self) -> bool { + **self != uint::max_value + } } fn invalid_node() -> LiveNode { LiveNode(uint::max_value) } @@ -260,8 +262,8 @@ fn IrMaps(tcx: ty::ctxt, } } -pub impl IrMaps { - fn add_live_node(&mut self, lnk: LiveNodeKind) -> LiveNode { +impl IrMaps { + pub fn add_live_node(&mut self, lnk: LiveNodeKind) -> LiveNode { let ln = LiveNode(self.num_live_nodes); self.lnks.push(lnk); self.num_live_nodes += 1; @@ -272,16 +274,16 @@ pub impl IrMaps { ln } - fn add_live_node_for_node(&mut self, - node_id: node_id, - lnk: LiveNodeKind) { + pub fn add_live_node_for_node(&mut self, + node_id: node_id, + lnk: LiveNodeKind) { let ln = self.add_live_node(lnk); self.live_node_map.insert(node_id, ln); debug!("%s is node %d", ln.to_str(), node_id); } - fn add_variable(&mut self, vk: VarKind) -> Variable { + pub fn add_variable(&mut self, vk: VarKind) -> Variable { let v = Variable(self.num_vars); self.var_kinds.push(vk); self.num_vars += 1; @@ -298,7 +300,7 @@ pub impl IrMaps { v } - fn variable(&mut self, node_id: node_id, span: span) -> Variable { + pub fn variable(&mut self, node_id: node_id, span: span) -> Variable { match self.variable_map.find(&node_id) { Some(&var) => var, None => { @@ -308,7 +310,7 @@ pub impl IrMaps { } } - fn variable_name(&mut self, var: Variable) -> @~str { + pub fn variable_name(&mut self, var: Variable) -> @~str { match self.var_kinds[*var] { Local(LocalInfo { ident: nm, _ }) | Arg(_, nm) => { self.tcx.sess.str_of(nm) @@ -317,11 +319,11 @@ pub impl IrMaps { } } - fn set_captures(&mut self, node_id: node_id, cs: ~[CaptureInfo]) { + pub fn set_captures(&mut self, node_id: node_id, cs: ~[CaptureInfo]) { self.capture_info_map.insert(node_id, @cs); } - fn captures(&mut self, expr: @expr) -> @~[CaptureInfo] { + pub fn captures(&mut self, expr: @expr) -> @~[CaptureInfo] { match self.capture_info_map.find(&expr.id) { Some(&caps) => caps, None => { @@ -330,7 +332,7 @@ pub impl IrMaps { } } - fn lnk(&mut self, ln: LiveNode) -> LiveNodeKind { + pub fn lnk(&mut self, ln: LiveNode) -> LiveNodeKind { self.lnks[*ln] } } @@ -578,8 +580,8 @@ fn Liveness(ir: @mut IrMaps, specials: Specials) -> Liveness { } } -pub impl Liveness { - fn live_node(&self, node_id: node_id, span: span) -> LiveNode { +impl Liveness { + pub fn live_node(&self, node_id: node_id, span: span) -> LiveNode { let ir: &mut IrMaps = self.ir; match ir.live_node_map.find(&node_id) { Some(&ln) => ln, @@ -595,7 +597,7 @@ pub impl Liveness { } } - fn variable_from_path(&self, expr: @expr) -> Option { + pub fn variable_from_path(&self, expr: @expr) -> Option { match expr.node { expr_path(_) => { let def = self.tcx.def_map.get_copy(&expr.id); @@ -607,12 +609,12 @@ pub impl Liveness { } } - fn variable(&self, node_id: node_id, span: span) -> Variable { + pub fn variable(&self, node_id: node_id, span: span) -> Variable { self.ir.variable(node_id, span) } - fn variable_from_def_map(&self, node_id: node_id, - span: span) -> Option { + pub fn variable_from_def_map(&self, node_id: node_id, span: span) + -> Option { match self.tcx.def_map.find(&node_id) { Some(&def) => { moves::moved_variable_node_id_from_def(def).map( @@ -626,8 +628,9 @@ pub impl Liveness { } } - fn pat_bindings(&self, pat: @pat, - f: &fn(LiveNode, Variable, span, node_id)) { + pub fn pat_bindings(&self, + pat: @pat, + f: &fn(LiveNode, Variable, span, node_id)) { let def_map = self.tcx.def_map; do pat_util::pat_bindings(def_map, pat) |_bm, p_id, sp, _n| { let ln = self.live_node(p_id, sp); @@ -636,9 +639,9 @@ pub impl Liveness { } } - fn arm_pats_bindings(&self, - pats: &[@pat], - f: &fn(LiveNode, Variable, span, node_id)) { + pub fn arm_pats_bindings(&self, + pats: &[@pat], + f: &fn(LiveNode, Variable, span, node_id)) { // only consider the first pattern; any later patterns must have // the same bindings, and we also consider the first pattern to be // the "authoratative" set of ids @@ -647,12 +650,13 @@ pub impl Liveness { } } - fn define_bindings_in_pat(&self, pat: @pat, succ: LiveNode) -> LiveNode { + pub fn define_bindings_in_pat(&self, pat: @pat, succ: LiveNode) + -> LiveNode { self.define_bindings_in_arm_pats([pat], succ) } - fn define_bindings_in_arm_pats(&self, pats: &[@pat], - succ: LiveNode) -> LiveNode { + pub fn define_bindings_in_arm_pats(&self, pats: &[@pat], succ: LiveNode) + -> LiveNode { let mut succ = succ; do self.arm_pats_bindings(pats) |ln, var, _sp, _id| { self.init_from_succ(ln, succ); @@ -662,13 +666,12 @@ pub impl Liveness { succ } - fn idx(&self, ln: LiveNode, var: Variable) -> uint { + pub fn idx(&self, ln: LiveNode, var: Variable) -> uint { *ln * self.ir.num_vars + *var } - fn live_on_entry(&self, ln: LiveNode, var: Variable) - -> Option { - + pub fn live_on_entry(&self, ln: LiveNode, var: Variable) + -> Option { assert!(ln.is_valid()); let reader = self.users[self.idx(ln, var)].reader; if reader.is_valid() {Some(self.ir.lnk(reader))} else {None} @@ -677,39 +680,39 @@ pub impl Liveness { /* Is this variable live on entry to any of its successor nodes? */ - fn live_on_exit(&self, ln: LiveNode, var: Variable) - -> Option { - + pub fn live_on_exit(&self, ln: LiveNode, var: Variable) + -> Option { self.live_on_entry(copy self.successors[*ln], var) } - fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool { + pub fn used_on_entry(&self, ln: LiveNode, var: Variable) -> bool { assert!(ln.is_valid()); self.users[self.idx(ln, var)].used } - fn assigned_on_entry(&self, ln: LiveNode, var: Variable) - -> Option { - + pub fn assigned_on_entry(&self, ln: LiveNode, var: Variable) + -> Option { assert!(ln.is_valid()); let writer = self.users[self.idx(ln, var)].writer; if writer.is_valid() {Some(self.ir.lnk(writer))} else {None} } - fn assigned_on_exit(&self, ln: LiveNode, var: Variable) - -> Option { - + pub fn assigned_on_exit(&self, ln: LiveNode, var: Variable) + -> Option { self.assigned_on_entry(copy self.successors[*ln], var) } - fn indices(&self, ln: LiveNode, op: &fn(uint)) { + pub fn indices(&self, ln: LiveNode, op: &fn(uint)) { let node_base_idx = self.idx(ln, Variable(0)); for uint::range(0, self.ir.num_vars) |var_idx| { op(node_base_idx + var_idx) } } - fn indices2(&self, ln: LiveNode, succ_ln: LiveNode, op: &fn(uint, uint)) { + pub fn indices2(&self, + ln: LiveNode, + succ_ln: LiveNode, + op: &fn(uint, uint)) { let node_base_idx = self.idx(ln, Variable(0u)); let succ_base_idx = self.idx(succ_ln, Variable(0u)); for uint::range(0u, self.ir.num_vars) |var_idx| { @@ -717,10 +720,10 @@ pub impl Liveness { } } - fn write_vars(&self, - wr: @io::Writer, - ln: LiveNode, - test: &fn(uint) -> LiveNode) { + pub fn write_vars(&self, + wr: @io::Writer, + ln: LiveNode, + test: &fn(uint) -> LiveNode) { let node_base_idx = self.idx(ln, Variable(0)); for uint::range(0, self.ir.num_vars) |var_idx| { let idx = node_base_idx + var_idx; @@ -731,8 +734,11 @@ pub impl Liveness { } } - fn find_loop_scope(&self, opt_label: Option, id: node_id, sp: span) - -> node_id { + pub fn find_loop_scope(&self, + opt_label: Option, + id: node_id, + sp: span) + -> node_id { match opt_label { Some(_) => // Refers to a labeled loop. Use the results of resolve // to find with one @@ -758,12 +764,12 @@ pub impl Liveness { } } - fn last_loop_scope(&self) -> node_id { + pub fn last_loop_scope(&self) -> node_id { let loop_scope = &mut *self.loop_scope; *loop_scope.last() } - fn ln_str(&self, ln: LiveNode) -> ~str { + pub fn ln_str(&self, ln: LiveNode) -> ~str { do io::with_str_writer |wr| { wr.write_str("[ln("); wr.write_uint(*ln); @@ -780,7 +786,7 @@ pub impl Liveness { } } - fn init_empty(&self, ln: LiveNode, succ_ln: LiveNode) { + pub fn init_empty(&self, ln: LiveNode, succ_ln: LiveNode) { self.successors[*ln] = succ_ln; // It is not necessary to initialize the @@ -793,7 +799,7 @@ pub impl Liveness { // } } - fn init_from_succ(&self, ln: LiveNode, succ_ln: LiveNode) { + pub fn init_from_succ(&self, ln: LiveNode, succ_ln: LiveNode) { // more efficient version of init_empty() / merge_from_succ() self.successors[*ln] = succ_ln; self.indices2(ln, succ_ln, |idx, succ_idx| { @@ -803,8 +809,11 @@ pub impl Liveness { self.ln_str(ln), self.ln_str(succ_ln)); } - fn merge_from_succ(&self, ln: LiveNode, succ_ln: LiveNode, - first_merge: bool) -> bool { + pub fn merge_from_succ(&self, + ln: LiveNode, + succ_ln: LiveNode, + first_merge: bool) + -> bool { if ln == succ_ln { return false; } let mut changed = false; @@ -838,7 +847,7 @@ pub impl Liveness { // Indicates that a local variable was *defined*; we know that no // uses of the variable can precede the definition (resolve checks // this) so we just clear out all the data. - fn define(&self, writer: LiveNode, var: Variable) { + pub fn define(&self, writer: LiveNode, var: Variable) { let idx = self.idx(writer, var); self.users[idx].reader = invalid_node(); self.users[idx].writer = invalid_node(); @@ -848,7 +857,7 @@ pub impl Liveness { } // Either read, write, or both depending on the acc bitset - fn acc(&self, ln: LiveNode, var: Variable, acc: uint) { + pub fn acc(&self, ln: LiveNode, var: Variable, acc: uint) { let idx = self.idx(ln, var); let users = &mut *self.users; let user = &mut users[idx]; @@ -874,7 +883,7 @@ pub impl Liveness { // _______________________________________________________________________ - fn compute(&self, decl: &fn_decl, body: &blk) -> LiveNode { + pub fn compute(&self, decl: &fn_decl, body: &blk) -> LiveNode { // if there is a `break` or `again` at the top level, then it's // effectively a return---this only occurs in `for` loops, // where the body is really a closure. @@ -899,8 +908,8 @@ pub impl Liveness { entry_ln } - fn propagate_through_fn_block(&self, _: &fn_decl, blk: &blk) - -> LiveNode { + pub fn propagate_through_fn_block(&self, _: &fn_decl, blk: &blk) + -> LiveNode { // the fallthrough exit is only for those cases where we do not // explicitly return: self.init_from_succ(self.s.fallthrough_ln, self.s.exit_ln); @@ -911,15 +920,16 @@ pub impl Liveness { self.propagate_through_block(blk, self.s.fallthrough_ln) } - fn propagate_through_block(&self, blk: &blk, succ: LiveNode) -> LiveNode { + pub fn propagate_through_block(&self, blk: &blk, succ: LiveNode) + -> LiveNode { let succ = self.propagate_through_opt_expr(blk.node.expr, succ); do blk.node.stmts.foldr(succ) |stmt, succ| { self.propagate_through_stmt(*stmt, succ) } } - fn propagate_through_stmt(&self, stmt: @stmt, succ: LiveNode) - -> LiveNode { + pub fn propagate_through_stmt(&self, stmt: @stmt, succ: LiveNode) + -> LiveNode { match stmt.node { stmt_decl(decl, _) => { return self.propagate_through_decl(decl, succ); @@ -935,8 +945,8 @@ pub impl Liveness { } } - fn propagate_through_decl(&self, decl: @decl, succ: LiveNode) - -> LiveNode { + pub fn propagate_through_decl(&self, decl: @decl, succ: LiveNode) + -> LiveNode { match decl.node { decl_local(ref locals) => { do locals.foldr(succ) |local, succ| { @@ -949,8 +959,8 @@ pub impl Liveness { } } - fn propagate_through_local(&self, local: @local, succ: LiveNode) - -> LiveNode { + pub fn propagate_through_local(&self, local: @local, succ: LiveNode) + -> LiveNode { // Note: we mark the variable as defined regardless of whether // there is an initializer. Initially I had thought to only mark // the live variable as defined if it was initialized, and then we @@ -969,22 +979,24 @@ pub impl Liveness { self.define_bindings_in_pat(local.node.pat, succ) } - fn propagate_through_exprs(&self, exprs: &[@expr], - succ: LiveNode) -> LiveNode { + pub fn propagate_through_exprs(&self, exprs: &[@expr], succ: LiveNode) + -> LiveNode { do exprs.foldr(succ) |expr, succ| { self.propagate_through_expr(*expr, succ) } } - fn propagate_through_opt_expr(&self, opt_expr: Option<@expr>, - succ: LiveNode) -> LiveNode { + pub fn propagate_through_opt_expr(&self, + opt_expr: Option<@expr>, + succ: LiveNode) + -> LiveNode { do old_iter::foldl(&opt_expr, succ) |succ, expr| { self.propagate_through_expr(*expr, *succ) } } - fn propagate_through_expr(&self, expr: @expr, succ: LiveNode) - -> LiveNode { + pub fn propagate_through_expr(&self, expr: @expr, succ: LiveNode) + -> LiveNode { debug!("propagate_through_expr: %s", expr_to_str(expr, self.tcx.sess.intr())); @@ -1230,8 +1242,10 @@ pub impl Liveness { } } - fn propagate_through_lvalue_components(&self, expr: @expr, - succ: LiveNode) -> LiveNode { + pub fn propagate_through_lvalue_components(&self, + expr: @expr, + succ: LiveNode) + -> LiveNode { // # Lvalues // // In general, the full flow graph structure for an @@ -1289,9 +1303,8 @@ pub impl Liveness { } // see comment on propagate_through_lvalue() - fn write_lvalue(&self, expr: @expr, - succ: LiveNode, - acc: uint) -> LiveNode { + pub fn write_lvalue(&self, expr: @expr, succ: LiveNode, acc: uint) + -> LiveNode { match expr.node { expr_path(_) => self.access_path(expr, succ, acc), @@ -1303,8 +1316,8 @@ pub impl Liveness { } } - fn access_path(&self, expr: @expr, succ: LiveNode, acc: uint) - -> LiveNode { + pub fn access_path(&self, expr: @expr, succ: LiveNode, acc: uint) + -> LiveNode { let def = self.tcx.def_map.get_copy(&expr.id); match moves::moved_variable_node_id_from_def(def) { Some(nid) => { @@ -1320,10 +1333,12 @@ pub impl Liveness { } } - fn propagate_through_loop(&self, expr: @expr, - cond: Option<@expr>, - body: &blk, - succ: LiveNode) -> LiveNode { + pub fn propagate_through_loop(&self, + expr: @expr, + cond: Option<@expr>, + body: &blk, + succ: LiveNode) + -> LiveNode { /* @@ -1377,10 +1392,12 @@ pub impl Liveness { cond_ln } - fn with_loop_nodes(&self, loop_node_id: node_id, - break_ln: LiveNode, - cont_ln: LiveNode, - f: &fn() -> R) -> R { + pub fn with_loop_nodes(&self, + loop_node_id: node_id, + break_ln: LiveNode, + cont_ln: LiveNode, + f: &fn() -> R) + -> R { debug!("with_loop_nodes: %d %u", loop_node_id, *break_ln); self.loop_scope.push(loop_node_id); self.break_ln.insert(loop_node_id, break_ln); @@ -1491,9 +1508,12 @@ enum ReadKind { PartiallyMovedValue } -pub impl Liveness { - fn check_ret(&self, id: node_id, sp: span, _fk: &visit::fn_kind, - entry_ln: LiveNode) { +impl Liveness { + pub fn check_ret(&self, + id: node_id, + sp: span, + _fk: &visit::fn_kind, + entry_ln: LiveNode) { if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() { // if no_ret_var is live, then we fall off the end of the // function without any kind of return expression: @@ -1512,7 +1532,7 @@ pub impl Liveness { } } - fn check_lvalue(@self, expr: @expr, vt: vt<@Liveness>) { + pub fn check_lvalue(@self, expr: @expr, vt: vt<@Liveness>) { match expr.node { expr_path(_) => { match self.tcx.def_map.get_copy(&expr.id) { @@ -1546,11 +1566,11 @@ pub impl Liveness { } } - fn report_illegal_read(&self, - chk_span: span, - lnk: LiveNodeKind, - var: Variable, - rk: ReadKind) { + pub fn report_illegal_read(&self, + chk_span: span, + lnk: LiveNodeKind, + var: Variable, + rk: ReadKind) { let msg = match rk { PossiblyUninitializedVariable => "possibly uninitialized \ variable", @@ -1578,12 +1598,12 @@ pub impl Liveness { } } - fn should_warn(&self, var: Variable) -> Option<@~str> { + pub fn should_warn(&self, var: Variable) -> Option<@~str> { let name = self.ir.variable_name(var); if name[0] == ('_' as u8) { None } else { Some(name) } } - fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) { + pub fn warn_about_unused_args(&self, decl: &fn_decl, entry_ln: LiveNode) { for decl.inputs.each |arg| { do pat_util::pat_bindings(self.tcx.def_map, arg.pat) |_bm, p_id, sp, _n| { @@ -1593,7 +1613,7 @@ pub impl Liveness { } } - fn warn_about_unused_or_dead_vars_in_pat(&self, pat: @pat) { + pub fn warn_about_unused_or_dead_vars_in_pat(&self, pat: @pat) { do self.pat_bindings(pat) |ln, var, sp, id| { if !self.warn_about_unused(sp, id, ln, var) { self.warn_about_dead_assign(sp, id, ln, var); @@ -1601,8 +1621,12 @@ pub impl Liveness { } } - fn warn_about_unused(&self, sp: span, id: node_id, - ln: LiveNode, var: Variable) -> bool { + pub fn warn_about_unused(&self, + sp: span, + id: node_id, + ln: LiveNode, + var: Variable) + -> bool { if !self.used_on_entry(ln, var) { for self.should_warn(var).each |name| { @@ -1629,8 +1653,11 @@ pub impl Liveness { return false; } - fn warn_about_dead_assign(&self, sp: span, id: node_id, - ln: LiveNode, var: Variable) { + pub fn warn_about_dead_assign(&self, + sp: span, + id: node_id, + ln: LiveNode, + var: Variable) { if self.live_on_exit(ln, var).is_none() { for self.should_warn(var).each |name| { self.tcx.sess.add_lint(dead_assignment, id, sp, diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 3a14a6816289e..194ea9ac32d6f 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -290,8 +290,8 @@ impl ToStr for MutabilityCategory { } } -pub impl MutabilityCategory { - fn from_mutbl(m: ast::mutability) -> MutabilityCategory { +impl MutabilityCategory { + pub fn from_mutbl(m: ast::mutability) -> MutabilityCategory { match m { m_imm => McImmutable, m_const => McReadOnly, @@ -299,7 +299,7 @@ pub impl MutabilityCategory { } } - fn inherit(&self) -> MutabilityCategory { + pub fn inherit(&self) -> MutabilityCategory { match *self { McImmutable => McImmutable, McReadOnly => McReadOnly, @@ -308,21 +308,21 @@ pub impl MutabilityCategory { } } - fn is_mutable(&self) -> bool { + pub fn is_mutable(&self) -> bool { match *self { McImmutable | McReadOnly => false, McDeclared | McInherited => true } } - fn is_immutable(&self) -> bool { + pub fn is_immutable(&self) -> bool { match *self { McImmutable => true, McReadOnly | McDeclared | McInherited => false } } - fn to_user_str(&self) -> &'static str { + pub fn to_user_str(&self) -> &'static str { match *self { McDeclared | McInherited => "mutable", McImmutable => "immutable", @@ -331,16 +331,16 @@ pub impl MutabilityCategory { } } -pub impl mem_categorization_ctxt { - fn expr_ty(&self, expr: @ast::expr) -> ty::t { +impl mem_categorization_ctxt { + pub fn expr_ty(&self, expr: @ast::expr) -> ty::t { ty::expr_ty(self.tcx, expr) } - fn pat_ty(&self, pat: @ast::pat) -> ty::t { + pub fn pat_ty(&self, pat: @ast::pat) -> ty::t { ty::node_id_to_type(self.tcx, pat.id) } - fn cat_expr(&self, expr: @ast::expr) -> cmt { + pub fn cat_expr(&self, expr: @ast::expr) -> cmt { match self.tcx.adjustments.find(&expr.id) { None => { // No adjustments. @@ -374,9 +374,8 @@ pub impl mem_categorization_ctxt { } } - fn cat_expr_autoderefd(&self, - expr: @ast::expr, - autoderefs: uint) -> cmt { + pub fn cat_expr_autoderefd(&self, expr: @ast::expr, autoderefs: uint) + -> cmt { let mut cmt = self.cat_expr_unadjusted(expr); for uint::range(1, autoderefs+1) |deref| { cmt = self.cat_deref(expr, cmt, deref); @@ -384,7 +383,7 @@ pub impl mem_categorization_ctxt { return cmt; } - fn cat_expr_unadjusted(&self, expr: @ast::expr) -> cmt { + pub fn cat_expr_unadjusted(&self, expr: @ast::expr) -> cmt { debug!("cat_expr: id=%d expr=%s", expr.id, pprust::expr_to_str(expr, self.tcx.sess.intr())); @@ -440,11 +439,12 @@ pub impl mem_categorization_ctxt { } } - fn cat_def(&self, - id: ast::node_id, - span: span, - expr_ty: ty::t, - def: ast::def) -> cmt { + pub fn cat_def(&self, + id: ast::node_id, + span: span, + expr_ty: ty::t, + def: ast::def) + -> cmt { match def { ast::def_fn(*) | ast::def_static_method(*) | ast::def_mod(_) | ast::def_foreign_mod(_) | ast::def_const(_) | @@ -557,7 +557,7 @@ pub impl mem_categorization_ctxt { } } - fn cat_rvalue(&self, elt: N, expr_ty: ty::t) -> cmt { + pub fn cat_rvalue(&self, elt: N, expr_ty: ty::t) -> cmt { @cmt_ { id:elt.id(), span:elt.span(), @@ -571,10 +571,10 @@ pub impl mem_categorization_ctxt { /// component is inherited from the base it is a part of. For /// example, a record field is mutable if it is declared mutable /// or if the container is mutable. - fn inherited_mutability(&self, - base_m: MutabilityCategory, - interior_m: ast::mutability) -> MutabilityCategory - { + pub fn inherited_mutability(&self, + base_m: MutabilityCategory, + interior_m: ast::mutability) + -> MutabilityCategory { match interior_m { m_imm => base_m.inherit(), m_const => McReadOnly, @@ -582,11 +582,12 @@ pub impl mem_categorization_ctxt { } } - fn cat_field(&self, - node: N, - base_cmt: cmt, - f_name: ast::ident, - f_ty: ty::t) -> cmt { + pub fn cat_field(&self, + node: N, + base_cmt: cmt, + f_name: ast::ident, + f_ty: ty::t) + -> cmt { @cmt_ { id: node.id(), span: node.span(), @@ -596,11 +597,11 @@ pub impl mem_categorization_ctxt { } } - fn cat_deref_fn(&self, - node: N, - base_cmt: cmt, - deref_cnt: uint) -> cmt - { + pub fn cat_deref_fn(&self, + node: N, + base_cmt: cmt, + deref_cnt: uint) + -> cmt { // Bit of a hack: the "dereference" of a function pointer like // `@fn()` is a mere logical concept. We interpret it as // dereferencing the environment pointer; of course, we don't @@ -612,11 +613,11 @@ pub impl mem_categorization_ctxt { return self.cat_deref_common(node, base_cmt, deref_cnt, mt); } - fn cat_deref(&self, - node: N, - base_cmt: cmt, - deref_cnt: uint) -> cmt - { + pub fn cat_deref(&self, + node: N, + base_cmt: cmt, + deref_cnt: uint) + -> cmt { let mt = match ty::deref(self.tcx, base_cmt.ty, true) { Some(mt) => mt, None => { @@ -630,12 +631,12 @@ pub impl mem_categorization_ctxt { return self.cat_deref_common(node, base_cmt, deref_cnt, mt); } - fn cat_deref_common(&self, - node: N, - base_cmt: cmt, - deref_cnt: uint, - mt: ty::mt) -> cmt - { + pub fn cat_deref_common(&self, + node: N, + base_cmt: cmt, + deref_cnt: uint, + mt: ty::mt) + -> cmt { match deref_kind(self.tcx, base_cmt.ty) { deref_ptr(ptr) => { // for unique ptrs, we inherit mutability from the @@ -671,10 +672,11 @@ pub impl mem_categorization_ctxt { } } - fn cat_index(&self, - elt: N, - base_cmt: cmt, - derefs: uint) -> cmt { + pub fn cat_index(&self, + elt: N, + base_cmt: cmt, + derefs: uint) + -> cmt { //! Creates a cmt for an indexing operation (`[]`); this //! indexing operation may occurs as part of an //! AutoBorrowVec, which when converting a `~[]` to an `&[]` @@ -764,11 +766,12 @@ pub impl mem_categorization_ctxt { } } - fn cat_imm_interior(&self, - node: N, - base_cmt: cmt, - interior_ty: ty::t, - interior: InteriorKind) -> cmt { + pub fn cat_imm_interior(&self, + node: N, + base_cmt: cmt, + interior_ty: ty::t, + interior: InteriorKind) + -> cmt { @cmt_ { id: node.id(), span: node.span(), @@ -778,10 +781,11 @@ pub impl mem_categorization_ctxt { } } - fn cat_downcast(&self, - node: N, - base_cmt: cmt, - downcast_ty: ty::t) -> cmt { + pub fn cat_downcast(&self, + node: N, + base_cmt: cmt, + downcast_ty: ty::t) + -> cmt { @cmt_ { id: node.id(), span: node.span(), @@ -791,11 +795,10 @@ pub impl mem_categorization_ctxt { } } - fn cat_pattern(&self, - cmt: cmt, - pat: @ast::pat, - op: &fn(cmt, @ast::pat)) - { + pub fn cat_pattern(&self, + cmt: cmt, + pat: @ast::pat, + op: &fn(cmt, @ast::pat)) { // Here, `cmt` is the categorization for the value being // matched and pat is the pattern it is being matched against. // @@ -961,7 +964,7 @@ pub impl mem_categorization_ctxt { } } - fn mut_to_str(&self, mutbl: ast::mutability) -> ~str { + pub fn mut_to_str(&self, mutbl: ast::mutability) -> ~str { match mutbl { m_mutbl => ~"mutable", m_const => ~"const", @@ -969,7 +972,7 @@ pub impl mem_categorization_ctxt { } } - fn cmt_to_str(&self, cmt: cmt) -> ~str { + pub fn cmt_to_str(&self, cmt: cmt) -> ~str { match cmt.cat { cat_static_item => { ~"static item" @@ -1022,7 +1025,7 @@ pub impl mem_categorization_ctxt { } } - fn region_to_str(&self, r: ty::Region) -> ~str { + pub fn region_to_str(&self, r: ty::Region) -> ~str { region_to_str(self.tcx, r) } } @@ -1068,8 +1071,8 @@ pub enum AliasableReason { AliasableOther } -pub impl cmt_ { - fn guarantor(@self) -> cmt { +impl cmt_ { + pub fn guarantor(@self) -> cmt { //! Returns `self` after stripping away any owned pointer derefs or //! interior content. The return value is basically the `cmt` which //! determines how long the value in `self` remains live. @@ -1097,11 +1100,11 @@ pub impl cmt_ { } } - fn is_freely_aliasable(&self) -> bool { + pub fn is_freely_aliasable(&self) -> bool { self.freely_aliasable().is_some() } - fn freely_aliasable(&self) -> Option { + pub fn freely_aliasable(&self) -> Option { //! True if this lvalue resides in an area that is //! freely aliasable, meaning that rustc cannot track //! the alias//es with precision. diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index d2f6d65277388..2e7ceba33663d 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -230,20 +230,14 @@ fn compute_modes_for_expr(expr: @expr, cx.consume_expr(expr, v); } -pub impl VisitContext { - fn consume_exprs(&self, - exprs: &[@expr], - visitor: vt) - { +impl VisitContext { + pub fn consume_exprs(&self, exprs: &[@expr], visitor: vt) { for exprs.each |expr| { self.consume_expr(*expr, visitor); } } - fn consume_expr(&self, - expr: @expr, - visitor: vt) - { + pub fn consume_expr(&self, expr: @expr, visitor: vt) { /*! * Indicates that the value of `expr` will be consumed, * meaning either copied or moved depending on its type. @@ -261,10 +255,7 @@ pub impl VisitContext { }; } - fn consume_block(&self, - blk: &blk, - visitor: vt) - { + pub fn consume_block(&self, blk: &blk, visitor: vt) { /*! * Indicates that the value of `blk` will be consumed, * meaning either copied or moved depending on its type. @@ -281,11 +272,10 @@ pub impl VisitContext { } } - fn use_expr(&self, - expr: @expr, - expr_mode: UseMode, - visitor: vt) - { + pub fn use_expr(&self, + expr: @expr, + expr_mode: UseMode, + visitor: vt) { /*! * Indicates that `expr` is used with a given mode. This will * in turn trigger calls to the subcomponents of `expr`. @@ -529,12 +519,12 @@ pub impl VisitContext { } } - fn use_overloaded_operator(&self, - expr: @expr, - receiver_expr: @expr, - arg_exprs: &[@expr], - visitor: vt) -> bool - { + pub fn use_overloaded_operator(&self, + expr: @expr, + receiver_expr: @expr, + arg_exprs: &[@expr], + visitor: vt) + -> bool { if !self.method_map.contains_key(&expr.id) { return false; } @@ -550,10 +540,7 @@ pub impl VisitContext { return true; } - fn consume_arm(&self, - arm: &arm, - visitor: vt) - { + pub fn consume_arm(&self, arm: &arm, visitor: vt) { for arm.pats.each |pat| { self.use_pat(*pat); } @@ -565,9 +552,7 @@ pub impl VisitContext { self.consume_block(&arm.body, visitor); } - fn use_pat(&self, - pat: @pat) - { + pub fn use_pat(&self, pat: @pat) { /*! * * Decides whether each binding in a pattern moves the value @@ -594,32 +579,31 @@ pub impl VisitContext { } } - fn use_receiver(&self, - receiver_expr: @expr, - visitor: vt) - { + pub fn use_receiver(&self, + receiver_expr: @expr, + visitor: vt) { self.use_fn_arg(receiver_expr, visitor); } - fn use_fn_args(&self, - _: node_id, - arg_exprs: &[@expr], - visitor: vt) { + pub fn use_fn_args(&self, + _: node_id, + arg_exprs: &[@expr], + visitor: vt) { //! Uses the argument expressions. for arg_exprs.each |arg_expr| { self.use_fn_arg(*arg_expr, visitor); } } - fn use_fn_arg(&self, arg_expr: @expr, visitor: vt) { + pub fn use_fn_arg(&self, arg_expr: @expr, visitor: vt) { //! Uses the argument. self.consume_expr(arg_expr, visitor) } - fn arms_have_by_move_bindings(&self, - moves_map: MovesMap, - arms: &[arm]) -> Option<@pat> - { + pub fn arms_have_by_move_bindings(&self, + moves_map: MovesMap, + arms: &[arm]) + -> Option<@pat> { for arms.each |arm| { for arm.pats.each |&pat| { for ast_util::walk_pat(pat) |p| { @@ -632,7 +616,7 @@ pub impl VisitContext { return None; } - fn compute_captures(&self, fn_expr_id: node_id) -> @[CaptureVar] { + pub fn compute_captures(&self, fn_expr_id: node_id) -> @[CaptureVar] { debug!("compute_capture_vars(fn_expr_id=%?)", fn_expr_id); let _indenter = indenter(); diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index 1731ced634f29..ce22909232330 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -73,11 +73,8 @@ pub struct Context { parent: parent, } -pub impl RegionMaps { - fn relate_free_regions(&mut self, - sub: FreeRegion, - sup: FreeRegion) - { +impl RegionMaps { + pub fn relate_free_regions(&mut self, sub: FreeRegion, sup: FreeRegion) { match self.free_region_map.find_mut(&sub) { Some(sups) => { if !sups.contains(&sup) { @@ -93,19 +90,14 @@ pub impl RegionMaps { self.free_region_map.insert(sub, ~[sup]); } - fn record_parent(&mut self, - sub: ast::node_id, - sup: ast::node_id) - { + pub fn record_parent(&mut self, sub: ast::node_id, sup: ast::node_id) { debug!("record_parent(sub=%?, sup=%?)", sub, sup); assert!(sub != sup); self.scope_map.insert(sub, sup); } - pub fn record_cleanup_scope(&mut self, - scope_id: ast::node_id) - { + pub fn record_cleanup_scope(&mut self, scope_id: ast::node_id) { //! Records that a scope is a CLEANUP SCOPE. This is invoked //! from within regionck. We wait until regionck because we do //! not know which operators are overloaded until that point, @@ -114,17 +106,13 @@ pub impl RegionMaps { self.cleanup_scopes.insert(scope_id); } - fn opt_encl_scope(&self, - id: ast::node_id) -> Option - { + pub fn opt_encl_scope(&self, id: ast::node_id) -> Option { //! Returns the narrowest scope that encloses `id`, if any. self.scope_map.find(&id).map(|&x| *x) } - fn encl_scope(&self, - id: ast::node_id) -> ast::node_id - { + pub fn encl_scope(&self, id: ast::node_id) -> ast::node_id { //! Returns the narrowest scope that encloses `id`, if any. match self.scope_map.find(&id) { @@ -133,13 +121,11 @@ pub impl RegionMaps { } } - fn is_cleanup_scope(&self, scope_id: ast::node_id) -> bool { + pub fn is_cleanup_scope(&self, scope_id: ast::node_id) -> bool { self.cleanup_scopes.contains(&scope_id) } - fn cleanup_scope(&self, - expr_id: ast::node_id) -> ast::node_id - { + pub fn cleanup_scope(&self, expr_id: ast::node_id) -> ast::node_id { //! Returns the scope when temps in expr will be cleaned up let mut id = self.encl_scope(expr_id); @@ -149,25 +135,22 @@ pub impl RegionMaps { return id; } - fn encl_region(&self, - id: ast::node_id) -> ty::Region - { + pub fn encl_region(&self, id: ast::node_id) -> ty::Region { //! Returns the narrowest scope region that encloses `id`, if any. ty::re_scope(self.encl_scope(id)) } - pub fn scopes_intersect(&self, - scope1: ast::node_id, - scope2: ast::node_id) -> bool - { - self.is_subscope_of(scope1, scope2) || self.is_subscope_of(scope2, scope1) + pub fn scopes_intersect(&self, scope1: ast::node_id, scope2: ast::node_id) + -> bool { + self.is_subscope_of(scope1, scope2) || + self.is_subscope_of(scope2, scope1) } - fn is_subscope_of(&self, - subscope: ast::node_id, - superscope: ast::node_id) -> bool - { + pub fn is_subscope_of(&self, + subscope: ast::node_id, + superscope: ast::node_id) + -> bool { /*! * Returns true if `subscope` is equal to or is lexically * nested inside `superscope` and false otherwise. @@ -192,10 +175,7 @@ pub impl RegionMaps { return true; } - fn sub_free_region(&self, - sub: FreeRegion, - sup: FreeRegion) -> bool - { + pub fn sub_free_region(&self, sub: FreeRegion, sup: FreeRegion) -> bool { /*! * Determines whether two free regions have a subregion relationship * by walking the graph encoded in `free_region_map`. Note that @@ -233,10 +213,10 @@ pub impl RegionMaps { return false; } - fn is_subregion_of(&self, - sub_region: ty::Region, - super_region: ty::Region) -> bool - { + pub fn is_subregion_of(&self, + sub_region: ty::Region, + super_region: ty::Region) + -> bool { /*! * Determines whether one region is a subregion of another. This is * intended to run *after inference* and sadly the logic is somewhat @@ -271,10 +251,10 @@ pub impl RegionMaps { } } - fn nearest_common_ancestor(&self, - scope_a: ast::node_id, - scope_b: ast::node_id) -> Option - { + pub fn nearest_common_ancestor(&self, + scope_a: ast::node_id, + scope_b: ast::node_id) + -> Option { /*! * Finds the nearest common ancestor (if any) of two scopes. That * is, finds the smallest scope which is greater than or equal to @@ -588,15 +568,15 @@ pub fn add_variance(ambient_variance: region_variance, } } -pub impl DetermineRpCtxt { - fn add_variance(&self, variance: region_variance) -> region_variance { +impl DetermineRpCtxt { + pub fn add_variance(&self, variance: region_variance) -> region_variance { add_variance(self.ambient_variance, variance) } /// Records that item `id` is region-parameterized with the /// variance `variance`. If `id` was already parameterized, then /// the new variance is joined with the old variance. - fn add_rp(&mut self, id: ast::node_id, variance: region_variance) { + pub fn add_rp(&mut self, id: ast::node_id, variance: region_variance) { assert!(id != 0); let old_variance = self.region_paramd_items.find(&id). map_consume(|x| *x); @@ -622,7 +602,7 @@ pub impl DetermineRpCtxt { /// `from`. Put another way, it indicates that the current item /// contains a value of type `from`, so if `from` is /// region-parameterized, so is the current item. - fn add_dep(&mut self, from: ast::node_id) { + pub fn add_dep(&mut self, from: ast::node_id) { debug!("add dependency from %d -> %d (%s -> %s) with variance %?", from, self.item_id, ast_map::node_id_to_str(self.ast_map, from, @@ -682,7 +662,7 @@ pub impl DetermineRpCtxt { // with &self type, &self is also bound. We detect those last two // cases via flags (anon_implies_rp and self_implies_rp) that are // true when the anon or self region implies RP. - fn region_is_relevant(&self, r: Option<@ast::Lifetime>) -> bool { + pub fn region_is_relevant(&self, r: Option<@ast::Lifetime>) -> bool { match r { None => { self.anon_implies_rp @@ -699,10 +679,10 @@ pub impl DetermineRpCtxt { } } - fn with(@mut self, - item_id: ast::node_id, - anon_implies_rp: bool, - f: &fn()) { + pub fn with(@mut self, + item_id: ast::node_id, + anon_implies_rp: bool, + f: &fn()) { let old_item_id = self.item_id; let old_anon_implies_rp = self.anon_implies_rp; self.item_id = item_id; @@ -716,7 +696,9 @@ pub impl DetermineRpCtxt { self.anon_implies_rp = old_anon_implies_rp; } - fn with_ambient_variance(@mut self, variance: region_variance, f: &fn()) { + pub fn with_ambient_variance(@mut self, + variance: region_variance, + f: &fn()) { let old_ambient_variance = self.ambient_variance; self.ambient_variance = self.add_variance(variance); f(); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 4d71055857784..b8faa0740b8ba 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -117,8 +117,8 @@ pub enum NamespaceResult { BoundResult(@mut Module, @mut NameBindings) } -pub impl NamespaceResult { - fn is_unknown(&self) -> bool { +impl NamespaceResult { + pub fn is_unknown(&self) -> bool { match *self { UnknownResult => true, _ => false @@ -162,11 +162,11 @@ pub enum ResolveResult { Success(T) // Successfully resolved the import. } -pub impl ResolveResult { - fn failed(&self) -> bool { +impl ResolveResult { + pub fn failed(&self) -> bool { match *self { Failed => true, _ => false } } - fn indeterminate(&self) -> bool { + pub fn indeterminate(&self) -> bool { match *self { Indeterminate => true, _ => false } } } @@ -390,8 +390,9 @@ pub fn ImportResolution(privacy: Privacy, } } -pub impl ImportResolution { - fn target_for_namespace(&self, namespace: Namespace) -> Option { +impl ImportResolution { + pub fn target_for_namespace(&self, namespace: Namespace) + -> Option { match namespace { TypeNS => return copy self.type_target, ValueNS => return copy self.value_target @@ -472,8 +473,8 @@ pub fn Module(parent_link: ParentLink, } } -pub impl Module { - fn all_imports_resolved(&self) -> bool { +impl Module { + pub fn all_imports_resolved(&self) -> bool { let imports = &mut *self.imports; return imports.len() == self.resolved_import_count; } @@ -501,14 +502,14 @@ pub struct NameBindings { value_def: Option, //< Meaning in value namespace. } -pub impl NameBindings { +impl NameBindings { /// Creates a new module in this set of name bindings. - fn define_module(@mut self, - privacy: Privacy, - parent_link: ParentLink, - def_id: Option, - kind: ModuleKind, - sp: span) { + pub fn define_module(@mut self, + privacy: Privacy, + parent_link: ParentLink, + def_id: Option, + kind: ModuleKind, + sp: span) { // Merges the module with the existing type def or creates a new one. let module_ = @mut Module(parent_link, def_id, kind); match self.type_def { @@ -532,12 +533,12 @@ pub impl NameBindings { } /// Sets the kind of the module, creating a new one if necessary. - fn set_module_kind(@mut self, - privacy: Privacy, - parent_link: ParentLink, - def_id: Option, - kind: ModuleKind, - _sp: span) { + pub fn set_module_kind(@mut self, + privacy: Privacy, + parent_link: ParentLink, + def_id: Option, + kind: ModuleKind, + _sp: span) { match self.type_def { None => { let module = @mut Module(parent_link, def_id, kind); @@ -566,7 +567,7 @@ pub impl NameBindings { } /// Records a type definition. - fn define_type(@mut self, privacy: Privacy, def: def, sp: span) { + pub fn define_type(@mut self, privacy: Privacy, def: def, sp: span) { // Merges the type with the existing type def or creates a new one. match self.type_def { None => { @@ -589,12 +590,12 @@ pub impl NameBindings { } /// Records a value definition. - fn define_value(@mut self, privacy: Privacy, def: def, sp: span) { + pub fn define_value(@mut self, privacy: Privacy, def: def, sp: span) { self.value_def = Some(ValueNsDef { privacy: privacy, def: def, value_span: Some(sp) }); } /// Returns the module node if applicable. - fn get_module_if_available(&self) -> Option<@mut Module> { + pub fn get_module_if_available(&self) -> Option<@mut Module> { match self.type_def { Some(ref type_def) => (*type_def).module_def, None => None @@ -605,7 +606,7 @@ pub impl NameBindings { * Returns the module node. Fails if this node does not have a module * definition. */ - fn get_module(@mut self) -> @mut Module { + pub fn get_module(@mut self) -> @mut Module { match self.get_module_if_available() { None => { fail!("get_module called on a node with no module \ @@ -615,14 +616,14 @@ pub impl NameBindings { } } - fn defined_in_namespace(&self, namespace: Namespace) -> bool { + pub fn defined_in_namespace(&self, namespace: Namespace) -> bool { match namespace { TypeNS => return self.type_def.is_some(), ValueNS => return self.value_def.is_some() } } - fn defined_in_public_namespace(&self, namespace: Namespace) -> bool { + pub fn defined_in_public_namespace(&self, namespace: Namespace) -> bool { match namespace { TypeNS => match self.type_def { Some(def) => def.privacy != Private, @@ -635,7 +636,7 @@ pub impl NameBindings { } } - fn def_for_namespace(&self, namespace: Namespace) -> Option { + pub fn def_for_namespace(&self, namespace: Namespace) -> Option { match namespace { TypeNS => { match self.type_def { @@ -669,7 +670,8 @@ pub impl NameBindings { } } - fn privacy_for_namespace(&self, namespace: Namespace) -> Option { + pub fn privacy_for_namespace(&self, namespace: Namespace) + -> Option { match namespace { TypeNS => { match self.type_def { @@ -686,7 +688,7 @@ pub impl NameBindings { } } - fn span_for_namespace(&self, namespace: Namespace) -> Option { + pub fn span_for_namespace(&self, namespace: Namespace) -> Option { if self.defined_in_namespace(namespace) { match namespace { TypeNS => { @@ -720,9 +722,11 @@ pub struct PrimitiveTypeTable { primitive_types: HashMap, } -pub impl PrimitiveTypeTable { - fn intern(&mut self, intr: @ident_interner, string: &str, - primitive_type: prim_ty) { +impl PrimitiveTypeTable { + pub fn intern(&mut self, + intr: @ident_interner, + string: &str, + primitive_type: prim_ty) { let ident = intr.intern(string); self.primitive_types.insert(ident, primitive_type); } @@ -871,9 +875,9 @@ pub struct Resolver { used_imports: HashSet, } -pub impl Resolver { +impl Resolver { /// The main name resolution procedure. - fn resolve(@mut self) { + pub fn resolve(@mut self) { self.build_reduced_graph(); self.session.abort_if_errors(); @@ -897,7 +901,7 @@ pub impl Resolver { // /// Constructs the reduced graph for the entire crate. - fn build_reduced_graph(@mut self) { + pub fn build_reduced_graph(@mut self) { let initial_parent = ModuleReducedGraphParent(self.graph_root.get_module()); visit_crate(self.crate, initial_parent, mk_vt(@Visitor { @@ -924,9 +928,9 @@ pub impl Resolver { } /// Returns the current module tracked by the reduced graph parent. - fn get_module_from_parent(@mut self, - reduced_graph_parent: ReducedGraphParent) - -> @mut Module { + pub fn get_module_from_parent(@mut self, + reduced_graph_parent: ReducedGraphParent) + -> @mut Module { match reduced_graph_parent { ModuleReducedGraphParent(module_) => { return module_; @@ -944,14 +948,13 @@ pub impl Resolver { * If this node does not have a module definition and we are not inside * a block, fails. */ - fn add_child(@mut self, - name: ident, - reduced_graph_parent: ReducedGraphParent, - duplicate_checking_mode: DuplicateCheckingMode, - // For printing errors - sp: span) - -> (@mut NameBindings, ReducedGraphParent) { - + pub fn add_child(@mut self, + name: ident, + reduced_graph_parent: ReducedGraphParent, + duplicate_checking_mode: DuplicateCheckingMode, + // For printing errors + sp: span) + -> (@mut NameBindings, ReducedGraphParent) { // If this is the immediate descendant of a module, then we add the // child name directly. Otherwise, we create or reuse an anonymous // module and add the child to that. @@ -1038,7 +1041,7 @@ pub impl Resolver { } } - fn block_needs_anonymous_module(@mut self, block: &blk) -> bool { + pub fn block_needs_anonymous_module(@mut self, block: &blk) -> bool { // If the block has view items, we need an anonymous module. if block.node.view_items.len() > 0 { return true; @@ -1069,10 +1072,8 @@ pub impl Resolver { return false; } - fn get_parent_link(@mut self, - parent: ReducedGraphParent, - name: ident) - -> ParentLink { + pub fn get_parent_link(@mut self, parent: ReducedGraphParent, name: ident) + -> ParentLink { match parent { ModuleReducedGraphParent(module_) => { return ModuleParentLink(module_, name); @@ -1081,10 +1082,10 @@ pub impl Resolver { } /// Constructs the reduced graph for one item. - fn build_reduced_graph_for_item(@mut self, - item: @item, - parent: ReducedGraphParent, - visitor: vt) { + pub fn build_reduced_graph_for_item(@mut self, + item: @item, + parent: ReducedGraphParent, + visitor: vt) { let ident = item.ident; let sp = item.span; let privacy = visibility_to_privacy(item.vis); @@ -1365,12 +1366,12 @@ pub impl Resolver { // Constructs the reduced graph for one variant. Variants exist in the // type and/or value namespaces. - fn build_reduced_graph_for_variant(@mut self, - variant: &variant, - item_id: def_id, - parent_privacy: Privacy, - parent: ReducedGraphParent, - _visitor: vt) { + pub fn build_reduced_graph_for_variant(@mut self, + variant: &variant, + item_id: def_id, + parent_privacy: Privacy, + parent: ReducedGraphParent, + _visitor: vt) { let ident = variant.node.name; let (child, _) = self.add_child(ident, parent, ForbidDuplicateValues, variant.span); @@ -1401,10 +1402,10 @@ pub impl Resolver { /// Constructs the reduced graph for one 'view item'. View items consist /// of imports and use directives. - fn build_reduced_graph_for_view_item(@mut self, - view_item: @view_item, - parent: ReducedGraphParent, - _visitor: vt) { + pub fn build_reduced_graph_for_view_item(@mut self, + view_item: @view_item, + parent: ReducedGraphParent, + _: vt) { let privacy = visibility_to_privacy(view_item.vis); match view_item.node { view_item_use(ref view_paths) => { @@ -1497,10 +1498,10 @@ pub impl Resolver { } /// Constructs the reduced graph for one foreign item. - fn build_reduced_graph_for_foreign_item(@mut self, - foreign_item: @foreign_item, - parent: ReducedGraphParent, - visitor: + pub fn build_reduced_graph_for_foreign_item(@mut self, + foreign_item: @foreign_item, + parent: ReducedGraphParent, + visitor: vt) { let name = foreign_item.ident; let (name_bindings, new_parent) = @@ -1528,10 +1529,10 @@ pub impl Resolver { } } - fn build_reduced_graph_for_block(@mut self, - block: &blk, - parent: ReducedGraphParent, - visitor: vt) { + pub fn build_reduced_graph_for_block(@mut self, + block: &blk, + parent: ReducedGraphParent, + visitor: vt) { let new_parent; if self.block_needs_anonymous_module(block) { let block_id = block.node.id; @@ -1554,14 +1555,14 @@ pub impl Resolver { visit_block(block, new_parent, visitor); } - fn handle_external_def(@mut self, - def: def, - visibility: ast::visibility, - modules: &mut HashMap, - child_name_bindings: @mut NameBindings, - final_ident: &str, - ident: ident, - new_parent: ReducedGraphParent) { + pub fn handle_external_def(@mut self, + def: def, + visibility: ast::visibility, + modules: &mut HashMap, + child_name_bindings: @mut NameBindings, + final_ident: &str, + ident: ident, + new_parent: ReducedGraphParent) { let privacy = visibility_to_privacy(visibility); match def { def_mod(def_id) | def_foreign_mod(def_id) => { @@ -1702,7 +1703,8 @@ pub impl Resolver { * Builds the reduced graph rooted at the 'use' directive for an external * crate. */ - fn build_reduced_graph_for_external_crate(@mut self, root: @mut Module) { + pub fn build_reduced_graph_for_external_crate(@mut self, + root: @mut Module) { let mut modules = HashMap::new(); // Create all the items reachable by paths. @@ -1879,13 +1881,13 @@ pub impl Resolver { } /// Creates and adds an import directive to the given module. - fn build_import_directive(@mut self, - privacy: Privacy, - module_: @mut Module, - module_path: ~[ident], - subclass: @ImportDirectiveSubclass, - span: span, - id: node_id) { + pub fn build_import_directive(@mut self, + privacy: Privacy, + module_: @mut Module, + module_path: ~[ident], + subclass: @ImportDirectiveSubclass, + span: span, + id: node_id) { let directive = @ImportDirective(privacy, module_path, subclass, span, id); module_.imports.push(directive); @@ -1940,7 +1942,7 @@ pub impl Resolver { /// Resolves all imports for the crate. This method performs the fixed- /// point iteration. - fn resolve_imports(@mut self) { + pub fn resolve_imports(@mut self) { let mut i = 0; let mut prev_unresolved_imports = 0; loop { @@ -1967,7 +1969,8 @@ pub impl Resolver { /// Attempts to resolve imports for the given module and all of its /// submodules. - fn resolve_imports_for_module_subtree(@mut self, module_: @mut Module) { + pub fn resolve_imports_for_module_subtree(@mut self, + module_: @mut Module) { debug!("(resolving imports for module subtree) resolving %s", self.module_to_str(module_)); self.resolve_imports_for_module(module_); @@ -1989,7 +1992,7 @@ pub impl Resolver { } /// Attempts to resolve imports for the given module only. - fn resolve_imports_for_module(@mut self, module: @mut Module) { + pub fn resolve_imports_for_module(@mut self, module: @mut Module) { if module.all_imports_resolved() { debug!("(resolving imports for module) all imports resolved for \ %s", @@ -2024,7 +2027,7 @@ pub impl Resolver { } } - fn idents_to_str(@mut self, idents: &[ident]) -> ~str { + pub fn idents_to_str(@mut self, idents: &[ident]) -> ~str { let mut first = true; let mut result = ~""; for idents.each |ident| { @@ -2034,19 +2037,19 @@ pub impl Resolver { return result; } - fn import_directive_subclass_to_str(@mut self, - subclass: ImportDirectiveSubclass) - -> @~str { + pub fn import_directive_subclass_to_str(@mut self, + subclass: ImportDirectiveSubclass) + -> @~str { match subclass { SingleImport(_target, source) => self.session.str_of(source), GlobImport => @~"*" } } - fn import_path_to_str(@mut self, - idents: &[ident], - subclass: ImportDirectiveSubclass) - -> @~str { + pub fn import_path_to_str(@mut self, + idents: &[ident], + subclass: ImportDirectiveSubclass) + -> @~str { if idents.is_empty() { self.import_directive_subclass_to_str(subclass) } else { @@ -2061,10 +2064,10 @@ pub impl Resolver { /// don't know whether the name exists at the moment due to other /// currently-unresolved imports, or success if we know the name exists. /// If successful, the resolved bindings are written into the module. - fn resolve_import_for_module(@mut self, - module_: @mut Module, - import_directive: @ImportDirective) - -> ResolveResult<()> { + pub fn resolve_import_for_module(@mut self, + module_: @mut Module, + import_directive: @ImportDirective) + -> ResolveResult<()> { let mut resolution_result = Failed; let module_path = &import_directive.module_path; @@ -2151,7 +2154,8 @@ pub impl Resolver { return resolution_result; } - fn create_name_bindings_from_module(module: @mut Module) -> NameBindings { + pub fn create_name_bindings_from_module(module: @mut Module) + -> NameBindings { NameBindings { type_def: Some(TypeNsDef { privacy: Public, @@ -2163,13 +2167,13 @@ pub impl Resolver { } } - fn resolve_single_import(@mut self, - module_: @mut Module, - containing_module: @mut Module, - target: ident, - source: ident, - span: span) - -> ResolveResult<()> { + pub fn resolve_single_import(@mut self, + module_: @mut Module, + containing_module: @mut Module, + target: ident, + source: ident, + span: span) + -> ResolveResult<()> { debug!("(resolving single import) resolving `%s` = `%s::%s` from \ `%s`", *self.session.str_of(target), @@ -2392,12 +2396,12 @@ pub impl Resolver { // Resolves a glob import. Note that this function cannot fail; it either // succeeds or bails out (as importing * from an empty module or a module // that exports nothing is valid). - fn resolve_glob_import(@mut self, - privacy: Privacy, - module_: @mut Module, - containing_module: @mut Module, - id: node_id) - -> ResolveResult<()> { + pub fn resolve_glob_import(@mut self, + privacy: Privacy, + module_: @mut Module, + containing_module: @mut Module, + id: node_id) + -> ResolveResult<()> { // This function works in a highly imperative manner; it eagerly adds // everything it can to the list of import resolutions of the module // node. @@ -2516,13 +2520,13 @@ pub impl Resolver { } /// Resolves the given module path from the given root `module_`. - fn resolve_module_path_from_root(@mut self, - module_: @mut Module, - module_path: &[ident], - index: uint, - span: span, - mut name_search_type: NameSearchType) - -> ResolveResult<@mut Module> { + pub fn resolve_module_path_from_root(@mut self, + module_: @mut Module, + module_path: &[ident], + index: uint, + span: span, + mut name_search_type: NameSearchType) + -> ResolveResult<@mut Module> { let mut search_module = module_; let mut index = index; let module_path_len = module_path.len(); @@ -2625,13 +2629,13 @@ pub impl Resolver { /// Attempts to resolve the module part of an import directive or path /// rooted at the given module. - fn resolve_module_path(@mut self, - module_: @mut Module, - module_path: &[ident], - use_lexical_scope: UseLexicalScopeFlag, - span: span, - name_search_type: NameSearchType) - -> ResolveResult<@mut Module> { + pub fn resolve_module_path(@mut self, + module_: @mut Module, + module_path: &[ident], + use_lexical_scope: UseLexicalScopeFlag, + span: span, + name_search_type: NameSearchType) + -> ResolveResult<@mut Module> { let module_path_len = module_path.len(); assert!(module_path_len > 0); @@ -2719,13 +2723,13 @@ pub impl Resolver { /// Invariant: This must only be called during main resolution, not during /// import resolution. - fn resolve_item_in_lexical_scope(@mut self, - module_: @mut Module, - name: ident, - namespace: Namespace, - search_through_modules: - SearchThroughModulesFlag) - -> ResolveResult { + pub fn resolve_item_in_lexical_scope(@mut self, + module_: @mut Module, + name: ident, + namespace: Namespace, + search_through_modules: + SearchThroughModulesFlag) + -> ResolveResult { debug!("(resolving item in lexical scope) resolving `%s` in \ namespace %? in `%s`", *self.session.str_of(name), @@ -2846,11 +2850,11 @@ pub impl Resolver { } } - /** Resolves a module name in the current lexical scope. */ - fn resolve_module_in_lexical_scope(@mut self, - module_: @mut Module, - name: ident) - -> ResolveResult<@mut Module> { + /// Resolves a module name in the current lexical scope. + pub fn resolve_module_in_lexical_scope(@mut self, + module_: @mut Module, + name: ident) + -> ResolveResult<@mut Module> { // If this module is an anonymous module, resolve the item in the // lexical scope. Otherwise, resolve the item from the crate root. let resolve_result = self.resolve_item_in_lexical_scope( @@ -2892,11 +2896,9 @@ pub impl Resolver { } } - /** - * Returns the nearest normal module parent of the given module. - */ - fn get_nearest_normal_module_parent(@mut self, module_: @mut Module) - -> Option<@mut Module> { + /// Returns the nearest normal module parent of the given module. + pub fn get_nearest_normal_module_parent(@mut self, module_: @mut Module) + -> Option<@mut Module> { let mut module_ = module_; loop { match module_.parent_link { @@ -2915,13 +2917,11 @@ pub impl Resolver { } } - /** - * Returns the nearest normal module parent of the given module, or the - * module itself if it is a normal module. - */ - fn get_nearest_normal_module_parent_or_self(@mut self, - module_: @mut Module) - -> @mut Module { + /// Returns the nearest normal module parent of the given module, or the + /// module itself if it is a normal module. + pub fn get_nearest_normal_module_parent_or_self(@mut self, + module_: @mut Module) + -> @mut Module { match module_.kind { NormalModuleKind => return module_, ExternModuleKind | @@ -2936,14 +2936,12 @@ pub impl Resolver { } } - /** - * Resolves a "module prefix". A module prefix is one of (a) `self::`; - * (b) some chain of `super::`. - */ - fn resolve_module_prefix(@mut self, - module_: @mut Module, - module_path: &[ident]) - -> ResolveResult { + /// Resolves a "module prefix". A module prefix is one of (a) `self::`; + /// (b) some chain of `super::`. + pub fn resolve_module_prefix(@mut self, + module_: @mut Module, + module_path: &[ident]) + -> ResolveResult { let interner = self.session.parse_sess.interner; // Start at the current module if we see `self` or `super`, or at the @@ -2985,12 +2983,12 @@ pub impl Resolver { /// Attempts to resolve the supplied name in the given module for the /// given namespace. If successful, returns the target corresponding to /// the name. - fn resolve_name_in_module(@mut self, - module_: @mut Module, - name: ident, - namespace: Namespace, - name_search_type: NameSearchType) - -> ResolveResult { + pub fn resolve_name_in_module(@mut self, + module_: @mut Module, + name: ident, + namespace: Namespace, + name_search_type: NameSearchType) + -> ResolveResult { debug!("(resolving name in module) resolving `%s` in `%s`", *self.session.str_of(name), self.module_to_str(module_)); @@ -3069,7 +3067,7 @@ pub impl Resolver { return Failed; } - fn report_unresolved_imports(@mut self, module_: @mut Module) { + pub fn report_unresolved_imports(@mut self, module_: @mut Module) { let index = module_.resolved_import_count; let imports: &mut ~[@ImportDirective] = &mut *module_.imports; let import_count = imports.len(); @@ -3110,12 +3108,13 @@ pub impl Resolver { // Then this operation can simply be performed as part of item (or import) // processing. - fn record_exports(@mut self) { + pub fn record_exports(@mut self) { let root_module = self.graph_root.get_module(); self.record_exports_for_module_subtree(root_module); } - fn record_exports_for_module_subtree(@mut self, module_: @mut Module) { + pub fn record_exports_for_module_subtree(@mut self, + module_: @mut Module) { // If this isn't a local crate, then bail out. We don't need to record // exports for nonlocal crates. @@ -3157,7 +3156,7 @@ pub impl Resolver { } } - fn record_exports_for_module(@mut self, module_: @mut Module) { + pub fn record_exports_for_module(@mut self, module_: @mut Module) { let mut exports2 = ~[]; self.add_exports_for_module(&mut exports2, module_); @@ -3171,12 +3170,12 @@ pub impl Resolver { } } - fn add_exports_of_namebindings(@mut self, - exports2: &mut ~[Export2], - ident: ident, - namebindings: @mut NameBindings, - ns: Namespace, - reexport: bool) { + pub fn add_exports_of_namebindings(@mut self, + exports2: &mut ~[Export2], + ident: ident, + namebindings: @mut NameBindings, + ns: Namespace, + reexport: bool) { match (namebindings.def_for_namespace(ns), namebindings.privacy_for_namespace(ns)) { (Some(d), Some(Public)) => { @@ -3199,9 +3198,9 @@ pub impl Resolver { } } - fn add_exports_for_module(@mut self, - exports2: &mut ~[Export2], - module_: @mut Module) { + pub fn add_exports_for_module(@mut self, + exports2: &mut ~[Export2], + module_: @mut Module) { for module_.children.each |ident, namebindings| { debug!("(computing exports) maybe export '%s'", *self.session.str_of(*ident)); @@ -3258,7 +3257,7 @@ pub impl Resolver { // generate a fake "implementation scope" containing all the // implementations thus found, for compatibility with old resolve pass. - fn with_scope(@mut self, name: Option, f: &fn()) { + pub fn with_scope(@mut self, name: Option, f: &fn()) { let orig_module = self.current_module; // Move down in the graph. @@ -3295,16 +3294,15 @@ pub impl Resolver { self.current_module = orig_module; } - // Wraps the given definition in the appropriate number of `def_upvar` - // wrappers. - - fn upvarify(@mut self, - ribs: &mut ~[@Rib], - rib_index: uint, - def_like: def_like, - span: span, - allow_capturing_self: AllowCapturingSelfFlag) - -> Option { + /// Wraps the given definition in the appropriate number of `def_upvar` + /// wrappers. + pub fn upvarify(@mut self, + ribs: &mut ~[@Rib], + rib_index: uint, + def_like: def_like, + span: span, + allow_capturing_self: AllowCapturingSelfFlag) + -> Option { let mut def; let is_ty_param; @@ -3408,12 +3406,12 @@ pub impl Resolver { return Some(dl_def(def)); } - fn search_ribs(@mut self, - ribs: &mut ~[@Rib], - name: ident, - span: span, - allow_capturing_self: AllowCapturingSelfFlag) - -> Option { + pub fn search_ribs(@mut self, + ribs: &mut ~[@Rib], + name: ident, + span: span, + allow_capturing_self: AllowCapturingSelfFlag) + -> Option { // FIXME #4950: This should not use a while loop. // FIXME #4950: Try caching? @@ -3434,7 +3432,7 @@ pub impl Resolver { return None; } - fn resolve_crate(@mut self) { + pub fn resolve_crate(@mut self) { debug!("(resolving crate) starting"); visit_crate(self.crate, (), mk_vt(@Visitor { @@ -3454,7 +3452,7 @@ pub impl Resolver { })); } - fn resolve_item(@mut self, item: @item, visitor: ResolveVisitor) { + pub fn resolve_item(@mut self, item: @item, visitor: ResolveVisitor) { debug!("(resolving item) resolving %s", *self.session.str_of(item.ident)); @@ -3652,9 +3650,9 @@ pub impl Resolver { self.xray_context = orig_xray_flag; } - fn with_type_parameter_rib(@mut self, - type_parameters: TypeParameters, - f: &fn()) { + pub fn with_type_parameter_rib(@mut self, + type_parameters: TypeParameters, + f: &fn()) { match type_parameters { HasTypeParameters(generics, node_id, initial_index, rib_kind) => { @@ -3695,25 +3693,25 @@ pub impl Resolver { } } - fn with_label_rib(@mut self, f: &fn()) { + pub fn with_label_rib(@mut self, f: &fn()) { self.label_ribs.push(@Rib(NormalRibKind)); f(); self.label_ribs.pop(); } - fn with_constant_rib(@mut self, f: &fn()) { + pub fn with_constant_rib(@mut self, f: &fn()) { self.value_ribs.push(@Rib(ConstantItemRibKind)); f(); self.value_ribs.pop(); } - fn resolve_function(@mut self, - rib_kind: RibKind, - optional_declaration: Option<&fn_decl>, - type_parameters: TypeParameters, - block: &blk, - self_binding: SelfBinding, - visitor: ResolveVisitor) { + pub fn resolve_function(@mut self, + rib_kind: RibKind, + optional_declaration: Option<&fn_decl>, + type_parameters: TypeParameters, + block: &blk, + self_binding: SelfBinding, + visitor: ResolveVisitor) { // Create a value rib for the function. let function_value_rib = @Rib(rib_kind); self.value_ribs.push(function_value_rib); @@ -3782,9 +3780,9 @@ pub impl Resolver { self.value_ribs.pop(); } - fn resolve_type_parameters(@mut self, - type_parameters: &OptVec, - visitor: ResolveVisitor) { + pub fn resolve_type_parameters(@mut self, + type_parameters: &OptVec, + visitor: ResolveVisitor) { for type_parameters.each |type_parameter| { for type_parameter.bounds.each |bound| { self.resolve_type_parameter_bound(bound, visitor); @@ -3792,9 +3790,9 @@ pub impl Resolver { } } - fn resolve_type_parameter_bound(@mut self, - type_parameter_bound: &TyParamBound, - visitor: ResolveVisitor) { + pub fn resolve_type_parameter_bound(@mut self, + type_parameter_bound: &TyParamBound, + visitor: ResolveVisitor) { match *type_parameter_bound { TraitTyParamBound(tref) => { self.resolve_trait_reference(tref, visitor) @@ -3803,9 +3801,9 @@ pub impl Resolver { } } - fn resolve_trait_reference(@mut self, - trait_reference: &trait_ref, - visitor: ResolveVisitor) { + pub fn resolve_trait_reference(@mut self, + trait_reference: &trait_ref, + visitor: ResolveVisitor) { match self.resolve_path(trait_reference.path, TypeNS, true, visitor) { None => { self.session.span_err(trait_reference.path.span, @@ -3818,11 +3816,11 @@ pub impl Resolver { } } - fn resolve_struct(@mut self, - id: node_id, - generics: &Generics, - fields: &[@struct_field], - visitor: ResolveVisitor) { + pub fn resolve_struct(@mut self, + id: node_id, + generics: &Generics, + fields: &[@struct_field], + visitor: ResolveVisitor) { // If applicable, create a rib for the type parameters. do self.with_type_parameter_rib(HasTypeParameters (generics, id, 0, @@ -3840,11 +3838,11 @@ pub impl Resolver { // Does this really need to take a RibKind or is it always going // to be NormalRibKind? - fn resolve_method(@mut self, - rib_kind: RibKind, - method: @method, - outer_type_parameter_count: uint, - visitor: ResolveVisitor) { + pub fn resolve_method(@mut self, + rib_kind: RibKind, + method: @method, + outer_type_parameter_count: uint, + visitor: ResolveVisitor) { let method_generics = &method.generics; let type_parameters = HasTypeParameters(method_generics, @@ -3865,13 +3863,13 @@ pub impl Resolver { visitor); } - fn resolve_implementation(@mut self, - id: node_id, - generics: &Generics, - opt_trait_reference: Option<@trait_ref>, - self_type: @Ty, - methods: &[@method], - visitor: ResolveVisitor) { + pub fn resolve_implementation(@mut self, + id: node_id, + generics: &Generics, + opt_trait_reference: Option<@trait_ref>, + self_type: @Ty, + methods: &[@method], + visitor: ResolveVisitor) { // If applicable, create a rib for the type parameters. let outer_type_parameter_count = generics.ty_params.len(); do self.with_type_parameter_rib(HasTypeParameters @@ -3938,18 +3936,18 @@ pub impl Resolver { } } - fn resolve_module(@mut self, - module_: &_mod, - span: span, - _name: ident, - id: node_id, - visitor: ResolveVisitor) { + pub fn resolve_module(@mut self, + module_: &_mod, + span: span, + _name: ident, + id: node_id, + visitor: ResolveVisitor) { // Write the implementations in scope into the module metadata. debug!("(resolving module) resolving module ID %d", id); visit_mod(module_, span, id, (), visitor); } - fn resolve_local(@mut self, local: @local, visitor: ResolveVisitor) { + pub fn resolve_local(@mut self, local: @local, visitor: ResolveVisitor) { let mutability = if local.node.is_mutbl {Mutable} else {Immutable}; // Resolve the type. @@ -3970,7 +3968,7 @@ pub impl Resolver { None, visitor); } - fn binding_mode_map(@mut self, pat: @pat) -> BindingMap { + pub fn binding_mode_map(@mut self, pat: @pat) -> BindingMap { let mut result = HashMap::new(); do pat_bindings(self.def_map, pat) |binding_mode, _id, sp, path| { let ident = path_to_ident(path); @@ -3981,7 +3979,7 @@ pub impl Resolver { return result; } - fn check_consistent_bindings(@mut self, arm: &arm) { + pub fn check_consistent_bindings(@mut self, arm: &arm) { if arm.pats.len() == 0 { return; } let map_0 = self.binding_mode_map(arm.pats[0]); for arm.pats.eachi() |i, p| { @@ -4020,7 +4018,7 @@ pub impl Resolver { } } - fn resolve_arm(@mut self, arm: &arm, visitor: ResolveVisitor) { + pub fn resolve_arm(@mut self, arm: &arm, visitor: ResolveVisitor) { self.value_ribs.push(@Rib(NormalRibKind)); let bindings_list = @mut HashMap::new(); @@ -4039,7 +4037,7 @@ pub impl Resolver { self.value_ribs.pop(); } - fn resolve_block(@mut self, block: &blk, visitor: ResolveVisitor) { + pub fn resolve_block(@mut self, block: &blk, visitor: ResolveVisitor) { debug!("(resolving block) entering block"); self.value_ribs.push(@Rib(NormalRibKind)); @@ -4064,7 +4062,7 @@ pub impl Resolver { debug!("(resolving block) leaving block"); } - fn resolve_type(@mut self, ty: @Ty, visitor: ResolveVisitor) { + pub fn resolve_type(@mut self, ty: @Ty, visitor: ResolveVisitor) { match ty.node { // Like path expressions, the interpretation of path types depends // on whether the path has multiple elements in it or not. @@ -4144,14 +4142,14 @@ pub impl Resolver { } } - fn resolve_pattern(@mut self, - pattern: @pat, - mode: PatternBindingMode, - mutability: Mutability, - // Maps idents to the node ID for the (outermost) - // pattern that binds them - bindings_list: Option<@mut HashMap>, - visitor: ResolveVisitor) { + pub fn resolve_pattern(@mut self, + pattern: @pat, + mode: PatternBindingMode, + mutability: Mutability, + // Maps idents to the node ID for the (outermost) + // pattern that binds them + bindings_list: Option<@mut HashMap>, + visitor: ResolveVisitor) { let pat_id = pattern.id; for walk_pat(pattern) |pattern| { match pattern.node { @@ -4386,8 +4384,9 @@ pub impl Resolver { } } - fn resolve_bare_identifier_pattern(@mut self, name: ident) - -> BareIdentifierPatternResolution { + pub fn resolve_bare_identifier_pattern(@mut self, name: ident) + -> + BareIdentifierPatternResolution { match self.resolve_item_in_lexical_scope(self.current_module, name, ValueNS, @@ -4426,12 +4425,12 @@ pub impl Resolver { /// If `check_ribs` is true, checks the local definitions first; i.e. /// doesn't skip straight to the containing module. - fn resolve_path(@mut self, - path: @Path, - namespace: Namespace, - check_ribs: bool, - visitor: ResolveVisitor) - -> Option { + pub fn resolve_path(@mut self, + path: @Path, + namespace: Namespace, + check_ribs: bool, + visitor: ResolveVisitor) + -> Option { // First, resolve the types. for path.types.each |ty| { self.resolve_type(*ty, visitor); @@ -4455,12 +4454,12 @@ pub impl Resolver { path.span); } - fn resolve_identifier(@mut self, - identifier: ident, - namespace: Namespace, - check_ribs: bool, - span: span) - -> Option { + pub fn resolve_identifier(@mut self, + identifier: ident, + namespace: Namespace, + check_ribs: bool, + span: span) + -> Option { if check_ribs { match self.resolve_identifier_in_local_ribs(identifier, namespace, @@ -4479,12 +4478,12 @@ pub impl Resolver { } // FIXME #4952: Merge me with resolve_name_in_module? - fn resolve_definition_of_name_in_module(@mut self, - containing_module: @mut Module, - name: ident, - namespace: Namespace, - xray: XrayFlag) - -> NameDefinition { + pub fn resolve_definition_of_name_in_module(@mut self, + containing_module: @mut Module, + name: ident, + namespace: Namespace, + xray: XrayFlag) + -> NameDefinition { // First, search children. match containing_module.children.find(&name) { Some(child_name_bindings) => { @@ -4552,7 +4551,7 @@ pub impl Resolver { return NoNameDefinition; } - fn intern_module_part_of_path(@mut self, path: @Path) -> ~[ident] { + pub fn intern_module_part_of_path(@mut self, path: @Path) -> ~[ident] { let mut module_path_idents = ~[]; for path.idents.eachi |index, ident| { if index == path.idents.len() - 1 { @@ -4565,11 +4564,11 @@ pub impl Resolver { return module_path_idents; } - fn resolve_module_relative_path(@mut self, - path: @Path, - xray: XrayFlag, - namespace: Namespace) - -> Option { + pub fn resolve_module_relative_path(@mut self, + path: @Path, + xray: XrayFlag, + namespace: Namespace) + -> Option { let module_path_idents = self.intern_module_part_of_path(path); let containing_module; @@ -4612,11 +4611,11 @@ pub impl Resolver { /// Invariant: This must be called only during main resolution, not during /// import resolution. - fn resolve_crate_relative_path(@mut self, - path: @Path, - xray: XrayFlag, - namespace: Namespace) - -> Option { + pub fn resolve_crate_relative_path(@mut self, + path: @Path, + xray: XrayFlag, + namespace: Namespace) + -> Option { let module_path_idents = self.intern_module_part_of_path(path); let root_module = self.graph_root.get_module(); @@ -4659,11 +4658,11 @@ pub impl Resolver { } } - fn resolve_identifier_in_local_ribs(@mut self, - ident: ident, - namespace: Namespace, - span: span) - -> Option { + pub fn resolve_identifier_in_local_ribs(@mut self, + ident: ident, + namespace: Namespace, + span: span) + -> Option { // Check the local set of ribs. let search_result; match namespace { @@ -4692,8 +4691,8 @@ pub impl Resolver { } } - fn resolve_self_value_in_local_ribs(@mut self, span: span) - -> Option { + pub fn resolve_self_value_in_local_ribs(@mut self, span: span) + -> Option { // FIXME #4950: This should not use a while loop. let ribs = &mut self.value_ribs; let mut i = ribs.len(); @@ -4721,10 +4720,10 @@ pub impl Resolver { None } - fn resolve_item_by_identifier_in_lexical_scope(@mut self, - ident: ident, - namespace: Namespace) - -> Option { + pub fn resolve_item_by_identifier_in_lexical_scope(@mut self, + ident: ident, + namespace: Namespace) + -> Option { // Check the items. match self.resolve_item_in_lexical_scope(self.current_module, ident, @@ -4754,7 +4753,10 @@ pub impl Resolver { } } - fn find_best_match_for_name(@mut self, name: &str, max_distance: uint) -> Option<~str> { + pub fn find_best_match_for_name(@mut self, + name: &str, + max_distance: uint) + -> Option<~str> { let this = &mut *self; let mut maybes: ~[~str] = ~[]; @@ -4792,7 +4794,7 @@ pub impl Resolver { } } - fn name_exists_in_scope_struct(@mut self, name: &str) -> bool { + pub fn name_exists_in_scope_struct(@mut self, name: &str) -> bool { let this = &mut *self; let mut i = this.type_ribs.len(); @@ -4826,7 +4828,7 @@ pub impl Resolver { return false; } - fn resolve_expr(@mut self, expr: @expr, visitor: ResolveVisitor) { + pub fn resolve_expr(@mut self, expr: @expr, visitor: ResolveVisitor) { // First, record candidate traits for this expression if it could // result in the invocation of a method call. @@ -4963,7 +4965,8 @@ pub impl Resolver { } } - fn record_candidate_traits_for_expr_if_necessary(@mut self, expr: @expr) { + pub fn record_candidate_traits_for_expr_if_necessary(@mut self, + expr: @expr) { match expr.node { expr_field(_, ident, _) => { let traits = self.search_for_traits_containing_method(ident); @@ -5040,9 +5043,8 @@ pub impl Resolver { } } - fn search_for_traits_containing_method(@mut self, - name: ident) - -> ~[def_id] { + pub fn search_for_traits_containing_method(@mut self, name: ident) + -> ~[def_id] { debug!("(searching for traits containing method) looking for '%s'", *self.session.str_of(name)); @@ -5142,10 +5144,10 @@ pub impl Resolver { return found_traits; } - fn add_trait_info(&self, - found_traits: &mut ~[def_id], - trait_def_id: def_id, - name: ident) { + pub fn add_trait_info(&self, + found_traits: &mut ~[def_id], + trait_def_id: def_id, + name: ident) { debug!("(adding trait info) found trait %d:%d for method '%s'", trait_def_id.crate, trait_def_id.node, @@ -5153,21 +5155,21 @@ pub impl Resolver { found_traits.push(trait_def_id); } - fn add_fixed_trait_for_expr(@mut self, - expr_id: node_id, - trait_id: def_id) { + pub fn add_fixed_trait_for_expr(@mut self, + expr_id: node_id, + trait_id: def_id) { self.trait_map.insert(expr_id, @mut ~[trait_id]); } - fn record_def(@mut self, node_id: node_id, def: def) { + pub fn record_def(@mut self, node_id: node_id, def: def) { debug!("(recording def) recording %? for %?", def, node_id); self.def_map.insert(node_id, def); } - fn enforce_default_binding_mode(@mut self, - pat: @pat, - pat_binding_mode: binding_mode, - descr: &str) { + pub fn enforce_default_binding_mode(@mut self, + pat: @pat, + pat_binding_mode: binding_mode, + descr: &str) { match pat_binding_mode { bind_infer => {} bind_by_ref(*) => { @@ -5186,7 +5188,7 @@ pub impl Resolver { // resolve data structures. // - fn check_for_unused_imports(@mut self) { + pub fn check_for_unused_imports(@mut self) { let vt = mk_simple_visitor(@SimpleVisitor { visit_view_item: |vi| self.check_for_item_unused_imports(vi), .. *default_simple_visitor() @@ -5194,7 +5196,7 @@ pub impl Resolver { visit_crate(self.crate, (), vt); } - fn check_for_item_unused_imports(&mut self, vi: @view_item) { + pub fn check_for_item_unused_imports(&mut self, vi: @view_item) { // Ignore public import statements because there's no way to be sure // whether they're used or not. Also ignore imports with a dummy span // because this means that they were generated in some fashion by the @@ -5238,7 +5240,7 @@ pub impl Resolver { // /// A somewhat inefficient routine to obtain the name of a module. - fn module_to_str(@mut self, module_: @mut Module) -> ~str { + pub fn module_to_str(@mut self, module_: @mut Module) -> ~str { let mut idents = ~[]; let mut current_module = module_; loop { @@ -5263,7 +5265,7 @@ pub impl Resolver { return self.idents_to_str(vec::reversed(idents)); } - fn dump_module(@mut self, module_: @mut Module) { + pub fn dump_module(@mut self, module_: @mut Module) { debug!("Dump of module `%s`:", self.module_to_str(module_)); debug!("Children:"); diff --git a/src/librustc/middle/trans/cabi.rs b/src/librustc/middle/trans/cabi.rs index 629d9ca629bf5..acc3293f26783 100644 --- a/src/librustc/middle/trans/cabi.rs +++ b/src/librustc/middle/trans/cabi.rs @@ -36,8 +36,8 @@ pub struct FnType { sret: bool } -pub impl FnType { - fn decl_fn(&self, decl: &fn(fnty: TypeRef) -> ValueRef) -> ValueRef { +impl FnType { + pub fn decl_fn(&self, decl: &fn(fnty: TypeRef) -> ValueRef) -> ValueRef { let atys = vec::map(self.arg_tys, |t| t.ty); let rty = self.ret_ty.ty; let fnty = T_fn(atys, rty); @@ -57,9 +57,11 @@ pub impl FnType { return llfn; } - fn build_shim_args(&self, bcx: block, - arg_tys: &[TypeRef], - llargbundle: ValueRef) -> ~[ValueRef] { + pub fn build_shim_args(&self, + bcx: block, + arg_tys: &[TypeRef], + llargbundle: ValueRef) + -> ~[ValueRef] { let mut atys: &[LLVMType] = self.arg_tys; let mut attrs: &[option::Option] = self.attrs; @@ -92,12 +94,12 @@ pub impl FnType { return llargvals; } - fn build_shim_ret(&self, - bcx: block, - arg_tys: &[TypeRef], - ret_def: bool, - llargbundle: ValueRef, - llretval: ValueRef) { + pub fn build_shim_ret(&self, + bcx: block, + arg_tys: &[TypeRef], + ret_def: bool, + llargbundle: ValueRef, + llretval: ValueRef) { for vec::eachi(self.attrs) |i, a| { match *a { option::Some(attr) => { @@ -128,11 +130,11 @@ pub impl FnType { }; } - fn build_wrap_args(&self, - bcx: block, - ret_ty: TypeRef, - llwrapfn: ValueRef, - llargbundle: ValueRef) { + pub fn build_wrap_args(&self, + bcx: block, + ret_ty: TypeRef, + llwrapfn: ValueRef, + llargbundle: ValueRef) { let mut atys: &[LLVMType] = self.arg_tys; let mut attrs: &[option::Option] = self.attrs; let mut j = 0u; @@ -167,10 +169,10 @@ pub impl FnType { store_inbounds(bcx, llretptr, llargbundle, [0u, n]); } - fn build_wrap_ret(&self, - bcx: block, - arg_tys: &[TypeRef], - llargbundle: ValueRef) { + pub fn build_wrap_ret(&self, + bcx: block, + arg_tys: &[TypeRef], + llargbundle: ValueRef) { unsafe { if llvm::LLVMGetTypeKind(self.ret_ty.ty) == Void { return; diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index 1a78019f289f0..a5b44d1a43fc1 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -118,8 +118,8 @@ pub struct EnvValue { datum: Datum } -pub impl EnvAction { - fn to_str(&self) -> ~str { +impl EnvAction { + pub fn to_str(&self) -> ~str { match *self { EnvCopy => ~"EnvCopy", EnvMove => ~"EnvMove", @@ -128,8 +128,8 @@ pub impl EnvAction { } } -pub impl EnvValue { - fn to_str(&self, ccx: @CrateContext) -> ~str { +impl EnvValue { + pub fn to_str(&self, ccx: @CrateContext) -> ~str { fmt!("%s(%s)", self.action.to_str(), self.datum.to_str(ccx)) } } diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index a2fa840ad79b9..7080487e7f886 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -249,8 +249,8 @@ pub struct param_substs { self_ty: Option } -pub impl param_substs { - fn validate(&self) { +impl param_substs { + pub fn validate(&self) { for self.tys.each |t| { assert!(!ty::type_needs_infer(*t)); } for self.self_ty.each |t| { assert!(!ty::type_needs_infer(*t)); } } @@ -353,7 +353,7 @@ pub struct fn_ctxt_ { ccx: @@CrateContext } -pub impl fn_ctxt_ { +impl fn_ctxt_ { pub fn arg_pos(&self, arg: uint) -> uint { if self.has_immediate_return_value { arg + 1u @@ -598,8 +598,8 @@ pub struct scope_info { landing_pad: Option, } -pub impl scope_info { - fn empty_cleanups(&mut self) -> bool { +impl scope_info { + pub fn empty_cleanups(&mut self) -> bool { self.cleanups.is_empty() } } @@ -695,8 +695,8 @@ pub fn rslt(bcx: block, val: ValueRef) -> Result { Result {bcx: bcx, val: val} } -pub impl Result { - fn unpack(&self, bcx: &mut block) -> ValueRef { +impl Result { + pub fn unpack(&self, bcx: &mut block) -> ValueRef { *bcx = self.bcx; return self.val; } @@ -742,28 +742,28 @@ pub fn block_parent(cx: block) -> block { // Accessors -pub impl block_ { - fn ccx(@mut self) -> @CrateContext { *self.fcx.ccx } - fn tcx(@mut self) -> ty::ctxt { self.fcx.ccx.tcx } - fn sess(@mut self) -> Session { self.fcx.ccx.sess } +impl block_ { + pub fn ccx(@mut self) -> @CrateContext { *self.fcx.ccx } + pub fn tcx(@mut self) -> ty::ctxt { self.fcx.ccx.tcx } + pub fn sess(@mut self) -> Session { self.fcx.ccx.sess } - fn node_id_to_str(@mut self, id: ast::node_id) -> ~str { + pub fn node_id_to_str(@mut self, id: ast::node_id) -> ~str { ast_map::node_id_to_str(self.tcx().items, id, self.sess().intr()) } - fn expr_to_str(@mut self, e: @ast::expr) -> ~str { + pub fn expr_to_str(@mut self, e: @ast::expr) -> ~str { e.repr(self.tcx()) } - fn expr_is_lval(@mut self, e: @ast::expr) -> bool { + pub fn expr_is_lval(@mut self, e: @ast::expr) -> bool { ty::expr_is_lval(self.tcx(), self.ccx().maps.method_map, e) } - fn expr_kind(@mut self, e: @ast::expr) -> ty::ExprKind { + pub fn expr_kind(@mut self, e: @ast::expr) -> ty::ExprKind { ty::expr_kind(self.tcx(), self.ccx().maps.method_map, e) } - fn def(@mut self, nid: ast::node_id) -> ast::def { + pub fn def(@mut self, nid: ast::node_id) -> ast::def { match self.tcx().def_map.find(&nid) { Some(&v) => v, None => { @@ -773,18 +773,19 @@ pub impl block_ { } } - fn val_str(@mut self, val: ValueRef) -> @str { + pub fn val_str(@mut self, val: ValueRef) -> @str { val_str(self.ccx().tn, val) } - fn llty_str(@mut self, llty: TypeRef) -> @str { + pub fn llty_str(@mut self, llty: TypeRef) -> @str { ty_str(self.ccx().tn, llty) } - fn ty_to_str(@mut self, t: ty::t) -> ~str { + pub fn ty_to_str(@mut self, t: ty::t) -> ~str { t.repr(self.tcx()) } - fn to_str(@mut self) -> ~str { + + pub fn to_str(@mut self) -> ~str { unsafe { match self.node_info { Some(node_info) => fmt!("[block %d]", node_info.id), diff --git a/src/librustc/middle/trans/datum.rs b/src/librustc/middle/trans/datum.rs index c0403083ce1c9..1c94d16b15834 100644 --- a/src/librustc/middle/trans/datum.rs +++ b/src/librustc/middle/trans/datum.rs @@ -145,12 +145,12 @@ pub enum DatumMode { ByValue, } -pub impl DatumMode { - fn is_by_ref(&self) -> bool { +impl DatumMode { + pub fn is_by_ref(&self) -> bool { match *self { ByRef(_) => true, ByValue => false } } - fn is_by_value(&self) -> bool { + pub fn is_by_value(&self) -> bool { match *self { ByRef(_) => false, ByValue => true } } } @@ -205,9 +205,13 @@ pub fn appropriate_mode(ty: ty::t) -> DatumMode { } } -pub impl Datum { - fn store_to(&self, bcx: block, id: ast::node_id, - action: CopyAction, dst: ValueRef) -> block { +impl Datum { + pub fn store_to(&self, + bcx: block, + id: ast::node_id, + action: CopyAction, + dst: ValueRef) + -> block { /*! * * Stores this value into its final home. This moves if @@ -221,8 +225,11 @@ pub impl Datum { } } - fn store_to_dest(&self, bcx: block, id: ast::node_id, - dest: expr::Dest) -> block { + pub fn store_to_dest(&self, + bcx: block, + id: ast::node_id, + dest: expr::Dest) + -> block { match dest { expr::Ignore => { return bcx; @@ -233,28 +240,32 @@ pub impl Datum { } } - fn store_to_datum(&self, bcx: block, id: ast::node_id, - action: CopyAction, datum: Datum) -> block { + pub fn store_to_datum(&self, + bcx: block, + id: ast::node_id, + action: CopyAction, + datum: Datum) + -> block { debug!("store_to_datum(self=%s, action=%?, datum=%s)", self.to_str(bcx.ccx()), action, datum.to_str(bcx.ccx())); assert!(datum.mode.is_by_ref()); self.store_to(bcx, id, action, datum.val) } - fn move_to_datum(&self, bcx: block, action: CopyAction, datum: Datum) - -> block { + pub fn move_to_datum(&self, bcx: block, action: CopyAction, datum: Datum) + -> block { assert!(datum.mode.is_by_ref()); self.move_to(bcx, action, datum.val) } - fn copy_to_datum(&self, bcx: block, action: CopyAction, datum: Datum) - -> block { + pub fn copy_to_datum(&self, bcx: block, action: CopyAction, datum: Datum) + -> block { assert!(datum.mode.is_by_ref()); self.copy_to(bcx, action, datum.val) } - fn copy_to(&self, bcx: block, action: CopyAction, dst: ValueRef) - -> block { + pub fn copy_to(&self, bcx: block, action: CopyAction, dst: ValueRef) + -> block { /*! * * Copies the value into `dst`, which should be a pointer to a @@ -296,9 +307,11 @@ pub impl Datum { } } - fn copy_to_no_check(&self, bcx: block, action: CopyAction, - dst: ValueRef) -> block - { + pub fn copy_to_no_check(&self, + bcx: block, + action: CopyAction, + dst: ValueRef) + -> block { /*! * * A helper for `copy_to()` which does not check to see if we @@ -326,8 +339,8 @@ pub impl Datum { // This works like copy_val, except that it deinitializes the source. // Since it needs to zero out the source, src also needs to be an lval. // - fn move_to(&self, bcx: block, action: CopyAction, dst: ValueRef) - -> block { + pub fn move_to(&self, bcx: block, action: CopyAction, dst: ValueRef) + -> block { let _icx = bcx.insn_ctxt("move_to"); let mut bcx = bcx; @@ -356,7 +369,7 @@ pub impl Datum { return bcx; } - fn add_clean(&self, bcx: block) { + pub fn add_clean(&self, bcx: block) { /*! * Schedules this datum for cleanup in `bcx`. The datum * must be an rvalue. @@ -376,7 +389,7 @@ pub impl Datum { } } - fn cancel_clean(&self, bcx: block) { + pub fn cancel_clean(&self, bcx: block) { if ty::type_needs_drop(bcx.tcx(), self.ty) { match self.mode { ByValue | @@ -394,14 +407,14 @@ pub impl Datum { } } - fn to_str(&self, ccx: &CrateContext) -> ~str { + pub fn to_str(&self, ccx: &CrateContext) -> ~str { fmt!("Datum { val=%s, ty=%s, mode=%? }", val_str(ccx.tn, self.val), ty_to_str(ccx.tcx, self.ty), self.mode) } - fn to_value_datum(&self, bcx: block) -> Datum { + pub fn to_value_datum(&self, bcx: block) -> Datum { /*! * * Yields a by-ref form of this datum. This may involve @@ -418,7 +431,7 @@ pub impl Datum { } } - fn to_value_llval(&self, bcx: block) -> ValueRef { + pub fn to_value_llval(&self, bcx: block) -> ValueRef { /*! * * Yields the value itself. */ @@ -439,7 +452,7 @@ pub impl Datum { } } - fn to_ref_datum(&self, bcx: block) -> Datum { + pub fn to_ref_datum(&self, bcx: block) -> Datum { /*! * Yields a by-ref form of this datum. This may involve * creation of a temporary stack slot. The value returned by @@ -456,7 +469,7 @@ pub impl Datum { } } - fn to_ref_llval(&self, bcx: block) -> ValueRef { + pub fn to_ref_llval(&self, bcx: block) -> ValueRef { match self.mode { ByRef(_) => self.val, ByValue => { @@ -471,7 +484,7 @@ pub impl Datum { } } - fn to_zeroable_ref_llval(&self, bcx: block) -> ValueRef { + pub fn to_zeroable_ref_llval(&self, bcx: block) -> ValueRef { /*! * Returns a by-ref llvalue that can be zeroed in order to * cancel cleanup. This is a kind of hokey bridge used @@ -496,13 +509,13 @@ pub impl Datum { } } - fn appropriate_mode(&self) -> DatumMode { + pub fn appropriate_mode(&self) -> DatumMode { /*! See the `appropriate_mode()` function */ appropriate_mode(self.ty) } - fn to_appropriate_llval(&self, bcx: block) -> ValueRef { + pub fn to_appropriate_llval(&self, bcx: block) -> ValueRef { /*! * * Yields an llvalue with the `appropriate_mode()`. */ @@ -513,7 +526,7 @@ pub impl Datum { } } - fn to_appropriate_datum(&self, bcx: block) -> Datum { + pub fn to_appropriate_datum(&self, bcx: block) -> Datum { /*! * * Yields a datum with the `appropriate_mode()`. */ @@ -524,10 +537,12 @@ pub impl Datum { } } - fn get_element(&self, bcx: block, - ty: ty::t, - source: DatumCleanup, - gep: &fn(ValueRef) -> ValueRef) -> Datum { + pub fn get_element(&self, + bcx: block, + ty: ty::t, + source: DatumCleanup, + gep: &fn(ValueRef) -> ValueRef) + -> Datum { let base_val = self.to_ref_llval(bcx); Datum { val: gep(base_val), @@ -536,7 +551,7 @@ pub impl Datum { } } - fn drop_val(&self, bcx: block) -> block { + pub fn drop_val(&self, bcx: block) -> block { if !ty::type_needs_drop(bcx.tcx(), self.ty) { return bcx; } @@ -547,7 +562,7 @@ pub impl Datum { }; } - fn box_body(&self, bcx: block) -> Datum { + pub fn box_body(&self, bcx: block) -> Datum { /*! * * This datum must represent an @T or ~T box. Returns a new @@ -567,7 +582,7 @@ pub impl Datum { Datum {val: body, ty: content_ty, mode: ByRef(ZeroMem)} } - fn to_rptr(&self, bcx: block) -> Datum { + pub fn to_rptr(&self, bcx: block) -> Datum { //! Returns a new datum of region-pointer type containing the //! the same ptr as this datum (after converting to by-ref //! using `to_ref_llval()`). @@ -582,14 +597,18 @@ pub impl Datum { Datum {val: llval, ty: rptr_ty, mode: ByValue} } - fn try_deref(&self, - bcx: block, // block wherein to generate insn's - span: span, // location where deref occurs - expr_id: ast::node_id, // id of deref expr - derefs: uint, // number of times deref'd already - is_auto: bool) // if true, only deref if auto-derefable - -> (Option, block) - { + /// bcx: Block wherein to generate insns. + /// span: Location where deref occurs. + /// expr_id: ID of deref expr. + /// derefs: Number of times deref'd already. + /// is_auto: If true, only deref if auto-derefable. + pub fn try_deref(&self, + bcx: block, + span: span, + expr_id: ast::node_id, + derefs: uint, + is_auto: bool) + -> (Option, block) { let ccx = bcx.ccx(); debug!("try_deref(expr_id=%?, derefs=%?, is_auto=%b, self=%?)", @@ -703,10 +722,9 @@ pub impl Datum { } } - fn deref(&self, bcx: block, - expr: @ast::expr, // the deref expression - derefs: uint) - -> DatumBlock { + /// expr: The deref expression. + pub fn deref(&self, bcx: block, expr: @ast::expr, derefs: uint) + -> DatumBlock { match self.try_deref(bcx, expr.span, expr.id, derefs, false) { (Some(lvres), bcx) => DatumBlock { bcx: bcx, datum: lvres }, (None, _) => { @@ -716,11 +734,12 @@ pub impl Datum { } } - fn autoderef(&self, bcx: block, - span: span, - expr_id: ast::node_id, - max: uint) - -> DatumBlock { + pub fn autoderef(&self, + bcx: block, + span: span, + expr_id: ast::node_id, + max: uint) + -> DatumBlock { let _icx = bcx.insn_ctxt("autoderef"); debug!("autoderef(expr_id=%d, max=%?, self=%?)", @@ -748,12 +767,12 @@ pub impl Datum { DatumBlock { bcx: bcx, datum: datum } } - fn get_vec_base_and_len(&self, - mut bcx: block, - span: span, - expr_id: ast::node_id, - derefs: uint) - -> (block, ValueRef, ValueRef) { + pub fn get_vec_base_and_len(&self, + mut bcx: block, + span: span, + expr_id: ast::node_id, + derefs: uint) + -> (block, ValueRef, ValueRef) { //! Converts a vector into the slice pair. Performs rooting //! and write guards checks. @@ -763,7 +782,8 @@ pub impl Datum { (bcx, base, len) } - fn get_vec_base_and_len_no_root(&self, bcx: block) -> (ValueRef, ValueRef) { + pub fn get_vec_base_and_len_no_root(&self, bcx: block) + -> (ValueRef, ValueRef) { //! Converts a vector into the slice pair. Des not root //! nor perform write guard checks. @@ -771,64 +791,68 @@ pub impl Datum { tvec::get_base_and_len(bcx, llval, self.ty) } - fn root_and_write_guard(&self, - bcx: block, - span: span, - expr_id: ast::node_id, - derefs: uint) -> block { + pub fn root_and_write_guard(&self, + bcx: block, + span: span, + expr_id: ast::node_id, + derefs: uint) + -> block { write_guard::root_and_write_guard(self, bcx, span, expr_id, derefs) } - fn to_result(&self, bcx: block) -> common::Result { + pub fn to_result(&self, bcx: block) -> common::Result { rslt(bcx, self.to_appropriate_llval(bcx)) } } -pub impl DatumBlock { - fn unpack(&self, bcx: &mut block) -> Datum { +impl DatumBlock { + pub fn unpack(&self, bcx: &mut block) -> Datum { *bcx = self.bcx; return self.datum; } - fn assert_by_ref(&self) -> DatumBlock { + pub fn assert_by_ref(&self) -> DatumBlock { assert!(self.datum.mode.is_by_ref()); *self } - fn drop_val(&self) -> block { + pub fn drop_val(&self) -> block { self.datum.drop_val(self.bcx) } - fn store_to(&self, id: ast::node_id, action: CopyAction, - dst: ValueRef) -> block { + pub fn store_to(&self, + id: ast::node_id, + action: CopyAction, + dst: ValueRef) + -> block { self.datum.store_to(self.bcx, id, action, dst) } - fn copy_to(&self, action: CopyAction, dst: ValueRef) -> block { + pub fn copy_to(&self, action: CopyAction, dst: ValueRef) -> block { self.datum.copy_to(self.bcx, action, dst) } - fn move_to(&self, action: CopyAction, dst: ValueRef) -> block { + pub fn move_to(&self, action: CopyAction, dst: ValueRef) -> block { self.datum.move_to(self.bcx, action, dst) } - fn to_value_llval(&self) -> ValueRef { + pub fn to_value_llval(&self) -> ValueRef { self.datum.to_value_llval(self.bcx) } - fn to_result(&self) -> common::Result { + pub fn to_result(&self) -> common::Result { rslt(self.bcx, self.datum.to_appropriate_llval(self.bcx)) } - fn ccx(&self) -> @CrateContext { + pub fn ccx(&self) -> @CrateContext { self.bcx.ccx() } - fn tcx(&self) -> ty::ctxt { + pub fn tcx(&self) -> ty::ctxt { self.bcx.tcx() } - fn to_str(&self) -> ~str { + pub fn to_str(&self) -> ~str { self.datum.to_str(self.ccx()) } } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 42ba06aad764e..fa8c3cd8879a2 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -170,8 +170,8 @@ pub enum Dest { Ignore, } -pub impl Dest { - fn to_str(&self, ccx: @CrateContext) -> ~str { +impl Dest { + pub fn to_str(&self, ccx: @CrateContext) -> ~str { match *self { SaveIn(v) => fmt!("SaveIn(%s)", val_str(ccx.tn, v)), Ignore => ~"Ignore" diff --git a/src/librustc/middle/trans/reflect.rs b/src/librustc/middle/trans/reflect.rs index 839c9a96b78e8..38cc9ba69de92 100644 --- a/src/librustc/middle/trans/reflect.rs +++ b/src/librustc/middle/trans/reflect.rs @@ -41,16 +41,16 @@ pub struct Reflector { bcx: block } -pub impl Reflector { - fn c_uint(&mut self, u: uint) -> ValueRef { +impl Reflector { + pub fn c_uint(&mut self, u: uint) -> ValueRef { C_uint(self.bcx.ccx(), u) } - fn c_int(&mut self, i: int) -> ValueRef { + pub fn c_int(&mut self, i: int) -> ValueRef { C_int(self.bcx.ccx(), i) } - fn c_slice(&mut self, s: @~str) -> ValueRef { + pub fn c_slice(&mut self, s: @~str) -> ValueRef { // We're careful to not use first class aggregates here because that // will kick us off fast isel. (Issue #4352.) let bcx = self.bcx; @@ -64,7 +64,7 @@ pub impl Reflector { scratch.val } - fn c_size_and_align(&mut self, t: ty::t) -> ~[ValueRef] { + pub fn c_size_and_align(&mut self, t: ty::t) -> ~[ValueRef] { let tr = type_of(self.bcx.ccx(), t); let s = machine::llsize_of_real(self.bcx.ccx(), tr); let a = machine::llalign_of_min(self.bcx.ccx(), tr); @@ -72,19 +72,19 @@ pub impl Reflector { self.c_uint(a)]; } - fn c_tydesc(&mut self, t: ty::t) -> ValueRef { + pub fn c_tydesc(&mut self, t: ty::t) -> ValueRef { let bcx = self.bcx; let static_ti = get_tydesc(bcx.ccx(), t); glue::lazily_emit_all_tydesc_glue(bcx.ccx(), static_ti); PointerCast(bcx, static_ti.tydesc, T_ptr(self.tydesc_ty)) } - fn c_mt(&mut self, mt: &ty::mt) -> ~[ValueRef] { + pub fn c_mt(&mut self, mt: &ty::mt) -> ~[ValueRef] { ~[self.c_uint(mt.mutbl as uint), self.c_tydesc(mt.ty)] } - fn visit(&mut self, ty_name: ~str, args: &[ValueRef]) { + pub fn visit(&mut self, ty_name: ~str, args: &[ValueRef]) { let tcx = self.bcx.tcx(); let mth_idx = ty::method_idx( tcx.sess.ident_of(~"visit_" + ty_name), @@ -119,19 +119,19 @@ pub impl Reflector { self.bcx = next_bcx } - fn bracketed(&mut self, - bracket_name: ~str, - extra: &[ValueRef], - inner: &fn(&mut Reflector)) { + pub fn bracketed(&mut self, + bracket_name: ~str, + extra: &[ValueRef], + inner: &fn(&mut Reflector)) { self.visit(~"enter_" + bracket_name, extra); inner(self); self.visit(~"leave_" + bracket_name, extra); } - fn vstore_name_and_extra(&mut self, - t: ty::t, - vstore: ty::vstore) -> (~str, ~[ValueRef]) - { + pub fn vstore_name_and_extra(&mut self, + t: ty::t, + vstore: ty::vstore) + -> (~str, ~[ValueRef]) { match vstore { ty::vstore_fixed(n) => { let extra = vec::append(~[self.c_uint(n)], @@ -144,12 +144,12 @@ pub impl Reflector { } } - fn leaf(&mut self, name: ~str) { + pub fn leaf(&mut self, name: ~str) { self.visit(name, []); } // Entrypoint - fn visit_ty(&mut self, t: ty::t) { + pub fn visit_ty(&mut self, t: ty::t) { let bcx = self.bcx; debug!("reflect::visit_ty %s", ty_to_str(bcx.ccx().tcx, t)); @@ -351,7 +351,7 @@ pub impl Reflector { } } - fn visit_sig(&mut self, retval: uint, sig: &ty::FnSig) { + pub fn visit_sig(&mut self, retval: uint, sig: &ty::FnSig) { for sig.inputs.eachi |i, arg| { let modeval = 5u; // "by copy" let extra = ~[self.c_uint(i), diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index 278a73558926c..e3c0c3a04d896 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -149,8 +149,8 @@ pub struct VecTypes { llunit_size: ValueRef } -pub impl VecTypes { - fn to_str(&self, ccx: @CrateContext) -> ~str { +impl VecTypes { + pub fn to_str(&self, ccx: @CrateContext) -> ~str { fmt!("VecTypes {vec_ty=%s, unit_ty=%s, llunit_ty=%s, llunit_size=%s}", ty_to_str(ccx.tcx, self.vec_ty), ty_to_str(ccx.tcx, self.unit_ty), diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 0d180223fefc8..f02f117bd364b 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -68,14 +68,15 @@ pub struct Method { def_id: ast::def_id } -pub impl Method { - fn new(ident: ast::ident, - generics: ty::Generics, - transformed_self_ty: Option, - fty: BareFnTy, - explicit_self: ast::explicit_self_, - vis: ast::visibility, - def_id: ast::def_id) -> Method { +impl Method { + pub fn new(ident: ast::ident, + generics: ty::Generics, + transformed_self_ty: Option, + fty: BareFnTy, + explicit_self: ast::explicit_self_, + vis: ast::visibility, + def_id: ast::def_id) + -> Method { // Check the invariants. if explicit_self == ast::sty_static { assert!(transformed_self_ty.is_none()); @@ -460,8 +461,8 @@ pub enum Region { re_empty, } -pub impl Region { - fn is_bound(&self) -> bool { +impl Region { + pub fn is_bound(&self) -> bool { match self { &re_bound(*) => true, _ => false @@ -879,8 +880,8 @@ pub struct Generics { region_param: Option, } -pub impl Generics { - fn has_type_params(&self) -> bool { +impl Generics { + pub fn has_type_params(&self) -> bool { !self.type_param_defs.is_empty() } } @@ -1817,12 +1818,12 @@ pub struct TypeContents { bits: u32 } -pub impl TypeContents { - fn meets_bounds(&self, cx: ctxt, bbs: BuiltinBounds) -> bool { +impl TypeContents { + pub fn meets_bounds(&self, cx: ctxt, bbs: BuiltinBounds) -> bool { iter::all(|bb| self.meets_bound(cx, bb), |f| bbs.each(f)) } - fn meets_bound(&self, cx: ctxt, bb: BuiltinBound) -> bool { + pub fn meets_bound(&self, cx: ctxt, bb: BuiltinBound) -> bool { match bb { BoundCopy => self.is_copy(cx), BoundStatic => self.is_static(cx), @@ -1832,69 +1833,69 @@ pub impl TypeContents { } } - fn intersects(&self, tc: TypeContents) -> bool { + pub fn intersects(&self, tc: TypeContents) -> bool { (self.bits & tc.bits) != 0 } - fn is_copy(&self, cx: ctxt) -> bool { + pub fn is_copy(&self, cx: ctxt) -> bool { !self.intersects(TypeContents::noncopyable(cx)) } - fn noncopyable(_cx: ctxt) -> TypeContents { + pub fn noncopyable(_cx: ctxt) -> TypeContents { TC_DTOR + TC_BORROWED_MUT + TC_ONCE_CLOSURE + TC_OWNED_CLOSURE + TC_EMPTY_ENUM } - fn is_static(&self, cx: ctxt) -> bool { + pub fn is_static(&self, cx: ctxt) -> bool { !self.intersects(TypeContents::nonstatic(cx)) } - fn nonstatic(_cx: ctxt) -> TypeContents { + pub fn nonstatic(_cx: ctxt) -> TypeContents { TC_BORROWED_POINTER } - fn is_owned(&self, cx: ctxt) -> bool { + pub fn is_owned(&self, cx: ctxt) -> bool { !self.intersects(TypeContents::nonowned(cx)) } - fn nonowned(_cx: ctxt) -> TypeContents { + pub fn nonowned(_cx: ctxt) -> TypeContents { TC_MANAGED + TC_BORROWED_POINTER + TC_NON_OWNED } - fn contains_managed(&self) -> bool { + pub fn contains_managed(&self) -> bool { self.intersects(TC_MANAGED) } - fn is_const(&self, cx: ctxt) -> bool { + pub fn is_const(&self, cx: ctxt) -> bool { !self.intersects(TypeContents::nonconst(cx)) } - fn nonconst(_cx: ctxt) -> TypeContents { + pub fn nonconst(_cx: ctxt) -> TypeContents { TC_MUTABLE } - fn is_sized(&self, cx: ctxt) -> bool { + pub fn is_sized(&self, cx: ctxt) -> bool { !self.intersects(TypeContents::dynamically_sized(cx)) } - fn dynamically_sized(_cx: ctxt) -> TypeContents { + pub fn dynamically_sized(_cx: ctxt) -> TypeContents { TC_DYNAMIC_SIZE } - fn moves_by_default(&self, cx: ctxt) -> bool { + pub fn moves_by_default(&self, cx: ctxt) -> bool { self.intersects(TypeContents::nonimplicitly_copyable(cx)) } - fn nonimplicitly_copyable(cx: ctxt) -> TypeContents { + pub fn nonimplicitly_copyable(cx: ctxt) -> TypeContents { TypeContents::noncopyable(cx) + TC_OWNED_POINTER + TC_OWNED_VEC } - fn needs_drop(&self, cx: ctxt) -> bool { + pub fn needs_drop(&self, cx: ctxt) -> bool { let tc = TC_MANAGED + TC_DTOR + TypeContents::owned(cx); self.intersects(tc) } - fn owned(_cx: ctxt) -> TypeContents { + pub fn owned(_cx: ctxt) -> TypeContents { //! Any kind of owned contents. TC_OWNED_CLOSURE + TC_OWNED_POINTER + TC_OWNED_VEC } @@ -3120,8 +3121,8 @@ pub fn adjust_ty(cx: ctxt, } } -pub impl AutoRef { - fn map_region(&self, f: &fn(Region) -> Region) -> AutoRef { +impl AutoRef { + pub fn map_region(&self, f: &fn(Region) -> Region) -> AutoRef { match *self { ty::AutoPtr(r, m) => ty::AutoPtr(f(r), m), ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(f(r), m), @@ -3809,14 +3810,15 @@ pub enum DtorKind { TraitDtor(def_id) } -pub impl DtorKind { - fn is_not_present(&const self) -> bool { +impl DtorKind { + pub fn is_not_present(&const self) -> bool { match *self { NoDtor => true, _ => false } } - fn is_present(&const self) -> bool { + + pub fn is_present(&const self) -> bool { !self.is_not_present() } } diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 1b7368b3dbfbe..9b8393a7464bf 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -179,8 +179,8 @@ pub struct Candidate { origin: method_origin, } -pub impl<'self> LookupContext<'self> { - fn do_lookup(&self, self_ty: ty::t) -> Option { +impl<'self> LookupContext<'self> { + pub fn do_lookup(&self, self_ty: ty::t) -> Option { let self_ty = structurally_resolved_type(self.fcx, self.self_expr.span, self_ty); @@ -248,8 +248,8 @@ pub impl<'self> LookupContext<'self> { self.search_for_autosliced_method(self_ty, autoderefs) } - fn deref(&self, ty: ty::t, enum_dids: &mut ~[ast::def_id]) - -> Option { + pub fn deref(&self, ty: ty::t, enum_dids: &mut ~[ast::def_id]) + -> Option { match ty::get(ty).sty { ty_enum(did, _) => { // Watch out for newtype'd enums like "enum t = @T". @@ -275,7 +275,7 @@ pub impl<'self> LookupContext<'self> { // ______________________________________________________________________ // Candidate collection (see comment at start of file) - fn push_inherent_candidates(&self, self_ty: ty::t) { + pub fn push_inherent_candidates(&self, self_ty: ty::t) { /*! * Collect all inherent candidates into * `self.inherent_candidates`. See comment at the start of @@ -326,7 +326,7 @@ pub impl<'self> LookupContext<'self> { } } - fn push_extension_candidates(&self, self_ty: ty::t) { + pub fn push_extension_candidates(&self, self_ty: ty::t) { // If the method being called is associated with a trait, then // find all the impls of that trait. Each of those are // candidates. @@ -359,9 +359,9 @@ pub impl<'self> LookupContext<'self> { } } - fn push_inherent_candidates_from_param(&self, - rcvr_ty: ty::t, - param_ty: param_ty) { + pub fn push_inherent_candidates_from_param(&self, + rcvr_ty: ty::t, + param_ty: param_ty) { debug!("push_inherent_candidates_from_param(param_ty=%?)", param_ty); let _indenter = indenter(); @@ -417,11 +417,11 @@ pub impl<'self> LookupContext<'self> { } } - fn push_inherent_candidates_from_trait(&self, - self_ty: ty::t, - did: def_id, - substs: &ty::substs, - store: ty::TraitStore) { + pub fn push_inherent_candidates_from_trait(&self, + self_ty: ty::t, + did: def_id, + substs: &ty::substs, + store: ty::TraitStore) { debug!("push_inherent_candidates_from_trait(did=%s, substs=%s)", self.did_to_str(did), substs_to_str(self.tcx(), substs)); @@ -469,10 +469,10 @@ pub impl<'self> LookupContext<'self> { }); } - fn push_inherent_candidates_from_self(&self, - self_ty: ty::t, - did: def_id, - substs: &ty::substs) { + pub fn push_inherent_candidates_from_self(&self, + self_ty: ty::t, + did: def_id, + substs: &ty::substs) { struct MethodInfo { method_ty: @ty::Method, trait_def_id: ast::def_id, @@ -533,7 +533,7 @@ pub impl<'self> LookupContext<'self> { } } - fn push_inherent_impl_candidates_for_type(&self, did: def_id) { + pub fn push_inherent_impl_candidates_for_type(&self, did: def_id) { let opt_impl_infos = self.fcx.ccx.coherence_info.inherent_methods.find(&did); for opt_impl_infos.each |impl_infos| { @@ -544,8 +544,9 @@ pub impl<'self> LookupContext<'self> { } } - fn push_candidates_from_impl(&self, candidates: &mut ~[Candidate], - impl_info: &resolve::Impl) { + pub fn push_candidates_from_impl(&self, + candidates: &mut ~[Candidate], + impl_info: &resolve::Impl) { if !self.impl_dups.insert(impl_info.did) { return; // already visited } @@ -579,12 +580,14 @@ pub impl<'self> LookupContext<'self> { }); } - fn push_candidates_from_provided_methods( - &self, - candidates: &mut ~[Candidate], - self_ty: ty::t, - trait_def_id: def_id, - methods: &mut ~[@ProvidedMethodInfo]) { + pub fn push_candidates_from_provided_methods(&self, + candidates: + &mut ~[Candidate], + self_ty: ty::t, + trait_def_id: def_id, + methods: + &mut ~[@ProvidedMethodInfo]) + { debug!("(pushing candidates from provided methods) considering trait \ id %d:%d", trait_def_id.crate, @@ -618,12 +621,10 @@ pub impl<'self> LookupContext<'self> { // ______________________________________________________________________ // Candidate selection (see comment at start of file) - fn search_for_autoderefd_method( - &self, - self_ty: ty::t, - autoderefs: uint) - -> Option - { + pub fn search_for_autoderefd_method(&self, + self_ty: ty::t, + autoderefs: uint) + -> Option { let (self_ty, autoadjust) = self.consider_reborrow(self_ty, autoderefs); match self.search_for_method(self_ty) { @@ -639,10 +640,10 @@ pub impl<'self> LookupContext<'self> { } } - fn consider_reborrow(&self, - self_ty: ty::t, - autoderefs: uint) -> (ty::t, ty::AutoAdjustment) - { + pub fn consider_reborrow(&self, + self_ty: ty::t, + autoderefs: uint) + -> (ty::t, ty::AutoAdjustment) { /*! * * In the event that we are invoking a method with a receiver @@ -702,12 +703,10 @@ pub impl<'self> LookupContext<'self> { } } - fn search_for_autosliced_method( - &self, - self_ty: ty::t, - autoderefs: uint) - -> Option - { + pub fn search_for_autosliced_method(&self, + self_ty: ty::t, + autoderefs: uint) + -> Option { /*! * * Searches for a candidate by converting things like @@ -770,12 +769,8 @@ pub impl<'self> LookupContext<'self> { } } - fn search_for_autoptrd_method( - &self, - self_ty: ty::t, - autoderefs: uint) - -> Option - { + pub fn search_for_autoptrd_method(&self, self_ty: ty::t, autoderefs: uint) + -> Option { /*! * * Converts any type `T` to `&M T` where `M` is an @@ -806,14 +801,13 @@ pub impl<'self> LookupContext<'self> { } } - fn search_for_some_kind_of_autorefd_method( + pub fn search_for_some_kind_of_autorefd_method( &self, kind: &fn(Region, ast::mutability) -> ty::AutoRef, autoderefs: uint, mutbls: &[ast::mutability], mk_autoref_ty: &fn(ast::mutability, ty::Region) -> ty::t) - -> Option - { + -> Option { // This is hokey. We should have mutability inference as a // variable. But for now, try &const, then &, then &mut: let region = self.infcx().next_region_var_nb(self.expr.span); @@ -834,10 +828,8 @@ pub impl<'self> LookupContext<'self> { return None; } - fn search_for_method(&self, - rcvr_ty: ty::t) - -> Option - { + pub fn search_for_method(&self, rcvr_ty: ty::t) + -> Option { debug!("search_for_method(rcvr_ty=%s)", self.ty_to_str(rcvr_ty)); let _indenter = indenter(); @@ -864,11 +856,10 @@ pub impl<'self> LookupContext<'self> { } } - fn consider_candidates(&self, - rcvr_ty: ty::t, - candidates: &mut ~[Candidate]) - -> Option - { + pub fn consider_candidates(&self, + rcvr_ty: ty::t, + candidates: &mut ~[Candidate]) + -> Option { let relevant_candidates = candidates.filter_to_vec(|c| self.is_relevant(rcvr_ty, c)); @@ -890,7 +881,7 @@ pub impl<'self> LookupContext<'self> { Some(self.confirm_candidate(rcvr_ty, &relevant_candidates[0])) } - fn merge_candidates(&self, candidates: &[Candidate]) -> ~[Candidate] { + pub fn merge_candidates(&self, candidates: &[Candidate]) -> ~[Candidate] { let mut merged = ~[]; let mut i = 0; while i < candidates.len() { @@ -936,11 +927,8 @@ pub impl<'self> LookupContext<'self> { return merged; } - fn confirm_candidate(&self, - rcvr_ty: ty::t, - candidate: &Candidate) - -> method_map_entry - { + pub fn confirm_candidate(&self, rcvr_ty: ty::t, candidate: &Candidate) + -> method_map_entry { let tcx = self.tcx(); let fty = self.fn_ty_from_origin(&candidate.origin); @@ -1065,10 +1053,9 @@ pub impl<'self> LookupContext<'self> { } } - fn enforce_trait_instance_limitations(&self, - method_fty: ty::t, - candidate: &Candidate) - { + pub fn enforce_trait_instance_limitations(&self, + method_fty: ty::t, + candidate: &Candidate) { /*! * * There are some limitations to calling functions through a @@ -1099,7 +1086,7 @@ pub impl<'self> LookupContext<'self> { } } - fn enforce_drop_trait_limitations(&self, candidate: &Candidate) { + pub fn enforce_drop_trait_limitations(&self, candidate: &Candidate) { // No code can call the finalize method explicitly. let bad; match candidate.origin { @@ -1121,7 +1108,7 @@ pub impl<'self> LookupContext<'self> { // `rcvr_ty` is the type of the expression. It may be a subtype of a // candidate method's `self_ty`. - fn is_relevant(&self, rcvr_ty: ty::t, candidate: &Candidate) -> bool { + pub fn is_relevant(&self, rcvr_ty: ty::t, candidate: &Candidate) -> bool { debug!("is_relevant(rcvr_ty=%s, candidate=%s)", self.ty_to_str(rcvr_ty), self.cand_to_str(candidate)); @@ -1208,7 +1195,7 @@ pub impl<'self> LookupContext<'self> { } } - fn fn_ty_from_origin(&self, origin: &method_origin) -> ty::t { + pub fn fn_ty_from_origin(&self, origin: &method_origin) -> ty::t { return match *origin { method_static(did) => { ty::lookup_item_type(self.tcx(), did).ty @@ -1230,7 +1217,7 @@ pub impl<'self> LookupContext<'self> { } } - fn report_candidate(&self, idx: uint, origin: &method_origin) { + pub fn report_candidate(&self, idx: uint, origin: &method_origin) { match *origin { method_static(impl_did) => { self.report_static_candidate(idx, impl_did) @@ -1245,7 +1232,7 @@ pub impl<'self> LookupContext<'self> { } } - fn report_static_candidate(&self, idx: uint, did: def_id) { + pub fn report_static_candidate(&self, idx: uint, did: def_id) { let span = if did.crate == ast::local_crate { match self.tcx().items.find(&did.node) { Some(&ast_map::node_method(m, _, _)) => m.span, @@ -1261,7 +1248,7 @@ pub impl<'self> LookupContext<'self> { ty::item_path_str(self.tcx(), did))); } - fn report_param_candidate(&self, idx: uint, did: def_id) { + pub fn report_param_candidate(&self, idx: uint, did: def_id) { self.tcx().sess.span_note( self.expr.span, fmt!("candidate #%u derives from the bound `%s`", @@ -1269,7 +1256,7 @@ pub impl<'self> LookupContext<'self> { ty::item_path_str(self.tcx(), did))); } - fn report_trait_candidate(&self, idx: uint, did: def_id) { + pub fn report_trait_candidate(&self, idx: uint, did: def_id) { self.tcx().sess.span_note( self.expr.span, fmt!("candidate #%u derives from the type of the receiver, \ @@ -1278,30 +1265,30 @@ pub impl<'self> LookupContext<'self> { ty::item_path_str(self.tcx(), did))); } - fn infcx(&self) -> @mut infer::InferCtxt { + pub fn infcx(&self) -> @mut infer::InferCtxt { self.fcx.inh.infcx } - fn tcx(&self) -> ty::ctxt { + pub fn tcx(&self) -> ty::ctxt { self.fcx.tcx() } - fn ty_to_str(&self, t: ty::t) -> ~str { + pub fn ty_to_str(&self, t: ty::t) -> ~str { self.fcx.infcx().ty_to_str(t) } - fn cand_to_str(&self, cand: &Candidate) -> ~str { + pub fn cand_to_str(&self, cand: &Candidate) -> ~str { fmt!("Candidate(rcvr_ty=%s, rcvr_substs=%s, origin=%?)", self.ty_to_str(cand.rcvr_ty), ty::substs_to_str(self.tcx(), &cand.rcvr_substs), cand.origin) } - fn did_to_str(&self, did: def_id) -> ~str { + pub fn did_to_str(&self, did: def_id) -> ~str { ty::item_path_str(self.tcx(), did) } - fn bug(&self, s: ~str) -> ! { + pub fn bug(&self, s: ~str) -> ! { self.tcx().sess.bug(s) } } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index f8481d4cf904d..ac39e6141653b 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -186,7 +186,7 @@ pub struct PurityState { priv from_fn: bool } -pub impl PurityState { +impl PurityState { pub fn function(purity: ast::purity, def: ast::node_id) -> PurityState { PurityState { def: def, purity: purity, from_fn: true } } @@ -658,18 +658,17 @@ impl AstConv for FnCtxt { } } -pub impl FnCtxt { - fn infcx(&self) -> @mut infer::InferCtxt { +impl FnCtxt { + pub fn infcx(&self) -> @mut infer::InferCtxt { self.inh.infcx } - fn err_count_since_creation(&self) -> uint { + pub fn err_count_since_creation(&self) -> uint { self.ccx.tcx.sess.err_count() - self.err_count_on_creation } - fn search_in_scope_regions( - &self, - span: span, - br: ty::bound_region) -> Result - { + pub fn search_in_scope_regions(&self, + span: span, + br: ty::bound_region) + -> Result { let in_scope_regions = self.in_scope_regions; match in_scope_regions.find(br) { Some(r) => result::Ok(r), @@ -703,14 +702,14 @@ impl region_scope for FnCtxt { } } -pub impl FnCtxt { - fn tag(&self) -> ~str { +impl FnCtxt { + pub fn tag(&self) -> ~str { unsafe { fmt!("%x", transmute(self)) } } - fn local_ty(&self, span: span, nid: ast::node_id) -> ty::t { + pub fn local_ty(&self, span: span, nid: ast::node_id) -> ty::t { match self.inh.locals.find(&nid) { Some(&t) => t, None => { @@ -721,23 +720,23 @@ pub impl FnCtxt { } } - fn expr_to_str(&self, expr: @ast::expr) -> ~str { + pub fn expr_to_str(&self, expr: @ast::expr) -> ~str { fmt!("expr(%?:%s)", expr.id, pprust::expr_to_str(expr, self.tcx().sess.intr())) } - fn block_region(&self) -> ty::Region { + pub fn block_region(&self) -> ty::Region { ty::re_scope(self.region_lb) } #[inline(always)] - fn write_ty(&self, node_id: ast::node_id, ty: ty::t) { + pub fn write_ty(&self, node_id: ast::node_id, ty: ty::t) { debug!("write_ty(%d, %s) in fcx %s", node_id, ppaux::ty_to_str(self.tcx(), ty), self.tag()); self.inh.node_types.insert(node_id, ty); } - fn write_substs(&self, node_id: ast::node_id, substs: ty::substs) { + pub fn write_substs(&self, node_id: ast::node_id, substs: ty::substs) { if !ty::substs_is_noop(&substs) { debug!("write_substs(%d, %s) in fcx %s", node_id, @@ -747,18 +746,18 @@ pub impl FnCtxt { } } - fn write_ty_substs(&self, - node_id: ast::node_id, - ty: ty::t, - substs: ty::substs) { + pub fn write_ty_substs(&self, + node_id: ast::node_id, + ty: ty::t, + substs: ty::substs) { let ty = ty::subst(self.tcx(), &substs, ty); self.write_ty(node_id, ty); self.write_substs(node_id, substs); } - fn write_autoderef_adjustment(&self, - node_id: ast::node_id, - derefs: uint) { + pub fn write_autoderef_adjustment(&self, + node_id: ast::node_id, + derefs: uint) { if derefs == 0 { return; } self.write_adjustment( node_id, @@ -768,36 +767,36 @@ pub impl FnCtxt { ); } - fn write_adjustment(&self, - node_id: ast::node_id, - adj: @ty::AutoAdjustment) { + pub fn write_adjustment(&self, + node_id: ast::node_id, + adj: @ty::AutoAdjustment) { debug!("write_adjustment(node_id=%?, adj=%?)", node_id, adj); self.inh.adjustments.insert(node_id, adj); } - fn write_nil(&self, node_id: ast::node_id) { + pub fn write_nil(&self, node_id: ast::node_id) { self.write_ty(node_id, ty::mk_nil()); } - fn write_bot(&self, node_id: ast::node_id) { + pub fn write_bot(&self, node_id: ast::node_id) { self.write_ty(node_id, ty::mk_bot()); } - fn write_error(@mut self, node_id: ast::node_id) { + pub fn write_error(@mut self, node_id: ast::node_id) { self.write_ty(node_id, ty::mk_err()); } - fn to_ty(&self, ast_t: @ast::Ty) -> ty::t { + pub fn to_ty(&self, ast_t: @ast::Ty) -> ty::t { ast_ty_to_ty(self, self, ast_t) } - fn expr_to_str(&self, expr: @ast::expr) -> ~str { + pub fn expr_to_str(&self, expr: @ast::expr) -> ~str { expr.repr(self.tcx()) } - fn pat_to_str(&self, pat: @ast::pat) -> ~str { + pub fn pat_to_str(&self, pat: @ast::pat) -> ~str { pat.repr(self.tcx()) } - fn expr_ty(&self, ex: @ast::expr) -> ty::t { + pub fn expr_ty(&self, ex: @ast::expr) -> ty::t { match self.inh.node_types.find(&ex.id) { Some(&t) => t, None => { @@ -807,7 +806,8 @@ pub impl FnCtxt { } } } - fn node_ty(&self, id: ast::node_id) -> ty::t { + + pub fn node_ty(&self, id: ast::node_id) -> ty::t { match self.inh.node_types.find(&id) { Some(&t) => t, None => { @@ -820,7 +820,8 @@ pub impl FnCtxt { } } } - fn node_ty_substs(&self, id: ast::node_id) -> ty::substs { + + pub fn node_ty_substs(&self, id: ast::node_id) -> ty::substs { match self.inh.node_type_substs.find(&id) { Some(ts) => (/*bad*/copy *ts), None => { @@ -834,32 +835,32 @@ pub impl FnCtxt { } } - fn opt_node_ty_substs(&self, id: ast::node_id, - f: &fn(&ty::substs) -> bool) -> bool { + pub fn opt_node_ty_substs(&self, + id: ast::node_id, + f: &fn(&ty::substs) -> bool) + -> bool { match self.inh.node_type_substs.find(&id) { Some(s) => f(s), None => true } } - fn mk_subty(&self, - a_is_expected: bool, - span: span, - sub: ty::t, - sup: ty::t) - -> Result<(), ty::type_err> { + pub fn mk_subty(&self, + a_is_expected: bool, + span: span, + sub: ty::t, + sup: ty::t) + -> Result<(), ty::type_err> { infer::mk_subty(self.infcx(), a_is_expected, span, sub, sup) } - fn can_mk_subty(&self, - sub: ty::t, - sup: ty::t) - -> Result<(), ty::type_err> { + pub fn can_mk_subty(&self, sub: ty::t, sup: ty::t) + -> Result<(), ty::type_err> { infer::can_mk_subty(self.infcx(), sub, sup) } - fn mk_assignty(&self, expr: @ast::expr, sub: ty::t, sup: ty::t) - -> Result<(), ty::type_err> { + pub fn mk_assignty(&self, expr: @ast::expr, sub: ty::t, sup: ty::t) + -> Result<(), ty::type_err> { match infer::mk_coercety(self.infcx(), false, expr.span, sub, sup) { Ok(None) => result::Ok(()), Err(ref e) => result::Err((*e)), @@ -870,32 +871,31 @@ pub impl FnCtxt { } } - fn can_mk_assignty(&self, - sub: ty::t, - sup: ty::t) - -> Result<(), ty::type_err> { + pub fn can_mk_assignty(&self, sub: ty::t, sup: ty::t) + -> Result<(), ty::type_err> { infer::can_mk_coercety(self.infcx(), sub, sup) } - fn mk_eqty(&self, - a_is_expected: bool, - span: span, - sub: ty::t, - sup: ty::t) - -> Result<(), ty::type_err> { + pub fn mk_eqty(&self, + a_is_expected: bool, + span: span, + sub: ty::t, + sup: ty::t) + -> Result<(), ty::type_err> { infer::mk_eqty(self.infcx(), a_is_expected, span, sub, sup) } - fn mk_subr(&self, - a_is_expected: bool, - span: span, - sub: ty::Region, - sup: ty::Region) - -> Result<(), ty::type_err> { + pub fn mk_subr(&self, + a_is_expected: bool, + span: span, + sub: ty::Region, + sup: ty::Region) + -> Result<(), ty::type_err> { infer::mk_subr(self.infcx(), a_is_expected, span, sub, sup) } - fn with_region_lb(@mut self, lb: ast::node_id, f: &fn() -> R) -> R { + pub fn with_region_lb(@mut self, lb: ast::node_id, f: &fn() -> R) + -> R { let old_region_lb = self.region_lb; self.region_lb = lb; let v = f(); @@ -903,26 +903,26 @@ pub impl FnCtxt { v } - fn region_var_if_parameterized(&self, - rp: Option, - span: span) - -> Option { + pub fn region_var_if_parameterized(&self, + rp: Option, + span: span) + -> Option { rp.map(|_rp| self.infcx().next_region_var_nb(span)) } - fn type_error_message(&self, - sp: span, - mk_msg: &fn(~str) -> ~str, - actual_ty: ty::t, - err: Option<&ty::type_err>) { + pub fn type_error_message(&self, + sp: span, + mk_msg: &fn(~str) -> ~str, + actual_ty: ty::t, + err: Option<&ty::type_err>) { self.infcx().type_error_message(sp, mk_msg, actual_ty, err); } - fn report_mismatched_return_types(&self, - sp: span, - e: ty::t, - a: ty::t, - err: &ty::type_err) { + pub fn report_mismatched_return_types(&self, + sp: span, + e: ty::t, + a: ty::t, + err: &ty::type_err) { // Derived error if ty::type_is_error(e) || ty::type_is_error(a) { return; @@ -943,11 +943,11 @@ pub impl FnCtxt { } } - fn report_mismatched_types(&self, - sp: span, - e: ty::t, - a: ty::t, - err: &ty::type_err) { + pub fn report_mismatched_types(&self, + sp: span, + e: ty::t, + a: ty::t, + err: &ty::type_err) { self.infcx().report_mismatched_types(sp, e, a, err) } } diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index 13b9c59e2d9cc..4c088cd9cbdc4 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -74,12 +74,12 @@ fn encl_region_of_def(fcx: @mut FnCtxt, def: ast::def) -> ty::Region { } } -pub impl Rcx { - fn tcx(&self) -> ty::ctxt { +impl Rcx { + pub fn tcx(&self) -> ty::ctxt { self.fcx.ccx.tcx } - fn resolve_type(&mut self, unresolved_ty: ty::t) -> ty::t { + pub fn resolve_type(&mut self, unresolved_ty: ty::t) -> ty::t { /*! * Try to resolve the type for the given node, returning * t_err if an error results. Note that we never care @@ -116,12 +116,12 @@ pub impl Rcx { } /// Try to resolve the type for the given node. - fn resolve_node_type(@mut self, id: ast::node_id) -> ty::t { + pub fn resolve_node_type(@mut self, id: ast::node_id) -> ty::t { self.resolve_type(self.fcx.node_ty(id)) } /// Try to resolve the type for the given node. - fn resolve_expr_type_adjusted(@mut self, expr: @ast::expr) -> ty::t { + pub fn resolve_expr_type_adjusted(@mut self, expr: @ast::expr) -> ty::t { let ty_unadjusted = self.resolve_node_type(expr.id); if ty::type_is_error(ty_unadjusted) || ty::type_is_bot(ty_unadjusted) { ty_unadjusted diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 37497e9a2bb2d..9333d2e7b9d8d 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -65,8 +65,8 @@ pub struct VtableContext { infcx: @mut infer::InferCtxt } -pub impl VtableContext { - fn tcx(&const self) -> ty::ctxt { self.ccx.tcx } +impl VtableContext { + pub fn tcx(&const self) -> ty::ctxt { self.ccx.tcx } } fn has_trait_bounds(type_param_defs: &[ty::TypeParameterDef]) -> bool { diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 3cb028b811e22..00454d658489b 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -199,8 +199,8 @@ pub struct CoherenceChecker { base_type_def_ids: @mut HashMap, } -pub impl CoherenceChecker { - fn check_coherence(self, crate: @crate) { +impl CoherenceChecker { + pub fn check_coherence(self, crate: @crate) { // Check implementations and traits. This populates the tables // containing the inherent methods and extension methods. It also // builds up the trait inheritance table. @@ -239,8 +239,9 @@ pub impl CoherenceChecker { self.populate_destructor_table(); } - fn check_implementation(&self, - item: @item, associated_traits: ~[@trait_ref]) { + pub fn check_implementation(&self, + item: @item, + associated_traits: ~[@trait_ref]) { let tcx = self.crate_context.tcx; let self_type = ty::lookup_item_type(tcx, local_def(item.id)); @@ -325,9 +326,9 @@ pub impl CoherenceChecker { // Creates default method IDs and performs type substitutions for an impl // and trait pair. Then, for each provided method in the trait, inserts a // `ProvidedMethodInfo` instance into the `provided_method_sources` map. - fn instantiate_default_methods(&self, - impl_id: ast::node_id, - trait_ref: &ty::TraitRef) { + pub fn instantiate_default_methods(&self, + impl_id: ast::node_id, + trait_ref: &ty::TraitRef) { let tcx = self.crate_context.tcx; debug!("instantiate_default_methods(impl_id=%?, trait_ref=%s)", impl_id, trait_ref.repr(tcx)); @@ -416,8 +417,9 @@ pub impl CoherenceChecker { } } - fn add_inherent_method(&self, - base_def_id: def_id, implementation: @Impl) { + pub fn add_inherent_method(&self, + base_def_id: def_id, + implementation: @Impl) { let implementation_list; match self.crate_context.coherence_info.inherent_methods .find(&base_def_id) { @@ -434,7 +436,7 @@ pub impl CoherenceChecker { implementation_list.push(implementation); } - fn add_trait_method(&self, trait_id: def_id, implementation: @Impl) { + pub fn add_trait_method(&self, trait_id: def_id, implementation: @Impl) { let implementation_list; match self.crate_context.coherence_info.extension_methods .find(&trait_id) { @@ -451,15 +453,14 @@ pub impl CoherenceChecker { implementation_list.push(implementation); } - fn check_implementation_coherence(&self) { + pub fn check_implementation_coherence(&self) { let coherence_info = self.crate_context.coherence_info; for coherence_info.extension_methods.each_key |&trait_id| { self.check_implementation_coherence_of(trait_id); } } - fn check_implementation_coherence_of(&self, trait_def_id: def_id) { - + pub fn check_implementation_coherence_of(&self, trait_def_id: def_id) { // Unify pairs of polytypes. do self.iter_impls_of_trait(trait_def_id) |a| { let implementation_a = a; @@ -492,8 +493,10 @@ pub impl CoherenceChecker { // Adds an impl of trait trait_t for self type self_t; that impl // is the_impl - fn add_impl_for_trait(&self, - trait_t: def_id, self_t: t, the_impl: @Impl) { + pub fn add_impl_for_trait(&self, + trait_t: def_id, + self_t: t, + the_impl: @Impl) { debug!("Adding impl %? of %? for %s", the_impl.did, trait_t, ty_to_str(self.crate_context.tcx, self_t)); @@ -509,7 +512,7 @@ pub impl CoherenceChecker { } } - fn iter_impls_of_trait(&self, trait_def_id: def_id, f: &fn(@Impl)) { + pub fn iter_impls_of_trait(&self, trait_def_id: def_id, f: &fn(@Impl)) { let coherence_info = self.crate_context.coherence_info; let extension_methods = &*coherence_info.extension_methods; @@ -527,9 +530,10 @@ pub impl CoherenceChecker { } } - fn each_provided_trait_method(&self, - trait_did: ast::def_id, - f: &fn(x: @ty::Method) -> bool) -> bool { + pub fn each_provided_trait_method(&self, + trait_did: ast::def_id, + f: &fn(x: @ty::Method) -> bool) + -> bool { // Make a list of all the names of the provided methods. // XXX: This is horrible. let mut provided_method_idents = HashSet::new(); @@ -548,9 +552,10 @@ pub impl CoherenceChecker { return true; } - fn polytypes_unify(&self, polytype_a: ty_param_bounds_and_ty, - polytype_b: ty_param_bounds_and_ty) - -> bool { + pub fn polytypes_unify(&self, + polytype_a: ty_param_bounds_and_ty, + polytype_b: ty_param_bounds_and_ty) + -> bool { let universally_quantified_a = self.universally_quantify_polytype(polytype_a); let universally_quantified_b = @@ -564,8 +569,9 @@ pub impl CoherenceChecker { // Converts a polytype to a monotype by replacing all parameters with // type variables. Returns the monotype and the type variables created. - fn universally_quantify_polytype(&self, polytype: ty_param_bounds_and_ty) - -> UniversalQuantificationResult { + pub fn universally_quantify_polytype(&self, + polytype: ty_param_bounds_and_ty) + -> UniversalQuantificationResult { // NDM--this span is bogus. let self_region = polytype.generics.region_param.map( @@ -594,11 +600,12 @@ pub impl CoherenceChecker { } } - fn can_unify_universally_quantified<'a> - (&self, - a: &'a UniversalQuantificationResult, - b: &'a UniversalQuantificationResult) - -> bool { + pub fn can_unify_universally_quantified<'a>(&self, + a: &'a + UniversalQuantificationResult, + b: &'a + UniversalQuantificationResult) + -> bool { let mut might_unify = true; let _ = do self.inference_context.probe { let result = self.inference_context.sub(true, dummy_sp()) @@ -642,13 +649,13 @@ pub impl CoherenceChecker { might_unify } - fn get_self_type_for_implementation(&self, implementation: @Impl) - -> ty_param_bounds_and_ty { + pub fn get_self_type_for_implementation(&self, implementation: @Impl) + -> ty_param_bounds_and_ty { return self.crate_context.tcx.tcache.get_copy(&implementation.did); } // Privileged scope checking - fn check_privileged_scopes(self, crate: @crate) { + pub fn check_privileged_scopes(self, crate: @crate) { visit_crate(crate, (), mk_vt(@Visitor { visit_item: |item, _context, visitor| { match item.node { @@ -698,7 +705,7 @@ pub impl CoherenceChecker { })); } - fn trait_ref_to_trait_def_id(&self, trait_ref: @trait_ref) -> def_id { + pub fn trait_ref_to_trait_def_id(&self, trait_ref: @trait_ref) -> def_id { let def_map = self.crate_context.tcx.def_map; let trait_def = def_map.get_copy(&trait_ref.ref_id); let trait_id = def_id_of_def(trait_def); @@ -707,10 +714,13 @@ pub impl CoherenceChecker { // This check doesn't really have anything to do with coherence. It's // here for historical reasons - fn please_check_that_trait_methods_are_implemented(&self, - all_methods: &mut ~[@MethodInfo], - trait_did: def_id, - trait_ref_span: span) { + pub fn please_check_that_trait_methods_are_implemented(&self, + all_methods: + &mut + ~[@MethodInfo], + trait_did: def_id, + trait_ref_span: + span) { let tcx = self.crate_context.tcx; @@ -774,7 +784,7 @@ pub impl CoherenceChecker { } // Converts an implementation in the AST to an Impl structure. - fn create_impl_from_item(&self, item: @item) -> @Impl { + pub fn create_impl_from_item(&self, item: @item) -> @Impl { fn add_provided_methods(all_methods: &mut ~[@MethodInfo], all_provided_methods: &mut ~[@ProvidedMethodInfo], sess: driver::session::Session) { @@ -844,7 +854,7 @@ pub impl CoherenceChecker { } } - fn span_of_impl(&self, implementation: @Impl) -> span { + pub fn span_of_impl(&self, implementation: @Impl) -> span { assert_eq!(implementation.did.crate, local_crate); match self.crate_context.tcx.items.find(&implementation.did.node) { Some(&node_item(item, _)) => { @@ -859,9 +869,10 @@ pub impl CoherenceChecker { // External crate handling - fn add_impls_for_module(&self, impls_seen: &mut HashSet, - crate_store: @mut CStore, - module_def_id: def_id) { + pub fn add_impls_for_module(&self, + impls_seen: &mut HashSet, + crate_store: @mut CStore, + module_def_id: def_id) { let implementations = get_impls_for_mod(crate_store, module_def_id, None); @@ -934,8 +945,8 @@ pub impl CoherenceChecker { } } - fn add_default_methods_for_external_trait(&self, - trait_def_id: ast::def_id) { + pub fn add_default_methods_for_external_trait(&self, + trait_def_id: ast::def_id) { let tcx = self.crate_context.tcx; let pmm = tcx.provided_methods; @@ -968,7 +979,7 @@ pub impl CoherenceChecker { // Adds implementations and traits from external crates to the coherence // info. - fn add_external_crates(&self) { + pub fn add_external_crates(&self) { let mut impls_seen = HashSet::new(); let crate_store = self.crate_context.tcx.sess.cstore; @@ -1001,7 +1012,7 @@ pub impl CoherenceChecker { // Destructors // - fn populate_destructor_table(&self) { + pub fn populate_destructor_table(&self) { let coherence_info = self.crate_context.coherence_info; let tcx = self.crate_context.tcx; let drop_trait = tcx.lang_items.drop_trait(); @@ -1050,13 +1061,12 @@ pub impl CoherenceChecker { } } -fn subst_receiver_types_in_method_ty( - tcx: ty::ctxt, - impl_id: ast::node_id, - trait_ref: &ty::TraitRef, - new_def_id: ast::def_id, - method: &ty::Method) -> ty::Method -{ +fn subst_receiver_types_in_method_ty(tcx: ty::ctxt, + impl_id: ast::node_id, + trait_ref: &ty::TraitRef, + new_def_id: ast::def_id, + method: &ty::Method) + -> ty::Method { /*! * Substitutes the values for the receiver's type parameters * that are found in method, leaving the method's type parameters diff --git a/src/librustc/middle/typeck/infer/coercion.rs b/src/librustc/middle/typeck/infer/coercion.rs index 64f0d439223b7..47f49ade336d1 100644 --- a/src/librustc/middle/typeck/infer/coercion.rs +++ b/src/librustc/middle/typeck/infer/coercion.rs @@ -86,8 +86,8 @@ use syntax::ast; // function. pub struct Coerce(CombineFields); -pub impl Coerce { - fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult { +impl Coerce { + pub fn tys(&self, a: ty::t, b: ty::t) -> CoerceResult { debug!("Coerce.tys(%s => %s)", a.inf_str(self.infcx), b.inf_str(self.infcx)); @@ -149,17 +149,17 @@ pub impl Coerce { } } - fn subtype(&self, a: ty::t, b: ty::t) -> CoerceResult { + pub fn subtype(&self, a: ty::t, b: ty::t) -> CoerceResult { match Sub(**self).tys(a, b) { Ok(_) => Ok(None), // No coercion required. Err(ref e) => Err(*e) } } - fn unpack_actual_value(&self, - a: ty::t, - f: &fn(&ty::sty) -> CoerceResult) -> CoerceResult - { + pub fn unpack_actual_value(&self, + a: ty::t, + f: &fn(&ty::sty) -> CoerceResult) + -> CoerceResult { match resolve_type(self.infcx, a, try_resolve_tvar_shallow) { Ok(t) => { f(&ty::get(t).sty) @@ -173,12 +173,12 @@ pub impl Coerce { } } - fn coerce_borrowed_pointer(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t, - mt_b: ty::mt) -> CoerceResult - { + pub fn coerce_borrowed_pointer(&self, + a: ty::t, + sty_a: &ty::sty, + b: ty::t, + mt_b: ty::mt) + -> CoerceResult { debug!("coerce_borrowed_pointer(a=%s, sty_a=%?, b=%s, mt_b=%?)", a.inf_str(self.infcx), sty_a, b.inf_str(self.infcx), mt_b); @@ -211,11 +211,11 @@ pub impl Coerce { }))) } - fn coerce_borrowed_string(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t) -> CoerceResult - { + pub fn coerce_borrowed_string(&self, + a: ty::t, + sty_a: &ty::sty, + b: ty::t) + -> CoerceResult { debug!("coerce_borrowed_string(a=%s, sty_a=%?, b=%s)", a.inf_str(self.infcx), sty_a, b.inf_str(self.infcx)); @@ -237,12 +237,12 @@ pub impl Coerce { }))) } - fn coerce_borrowed_vector(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t, - mt_b: ty::mt) -> CoerceResult - { + pub fn coerce_borrowed_vector(&self, + a: ty::t, + sty_a: &ty::sty, + b: ty::t, + mt_b: ty::mt) + -> CoerceResult { debug!("coerce_borrowed_vector(a=%s, sty_a=%?, b=%s)", a.inf_str(self.infcx), sty_a, b.inf_str(self.infcx)); @@ -266,11 +266,11 @@ pub impl Coerce { }))) } - fn coerce_borrowed_fn(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t) -> CoerceResult - { + pub fn coerce_borrowed_fn(&self, + a: ty::t, + sty_a: &ty::sty, + b: ty::t) + -> CoerceResult { debug!("coerce_borrowed_fn(a=%s, sty_a=%?, b=%s)", a.inf_str(self.infcx), sty_a, b.inf_str(self.infcx)); @@ -302,22 +302,22 @@ pub impl Coerce { }))) } - fn coerce_from_bare_fn(&self, - a: ty::t, - fn_ty_a: &ty::BareFnTy, - b: ty::t) -> CoerceResult - { + pub fn coerce_from_bare_fn(&self, + a: ty::t, + fn_ty_a: &ty::BareFnTy, + b: ty::t) + -> CoerceResult { do self.unpack_actual_value(b) |sty_b| { self.coerce_from_bare_fn_post_unpack(a, fn_ty_a, b, sty_b) } } - fn coerce_from_bare_fn_post_unpack(&self, - a: ty::t, - fn_ty_a: &ty::BareFnTy, - b: ty::t, - sty_b: &ty::sty) -> CoerceResult - { + pub fn coerce_from_bare_fn_post_unpack(&self, + a: ty::t, + fn_ty_a: &ty::BareFnTy, + b: ty::t, + sty_b: &ty::sty) + -> CoerceResult { /*! * * Attempts to coerce from a bare Rust function (`extern @@ -346,12 +346,12 @@ pub impl Coerce { Ok(Some(adj)) } - fn coerce_unsafe_ptr(&self, - a: ty::t, - sty_a: &ty::sty, - b: ty::t, - mt_b: ty::mt) -> CoerceResult - { + pub fn coerce_unsafe_ptr(&self, + a: ty::t, + sty_a: &ty::sty, + b: ty::t, + mt_b: ty::mt) + -> CoerceResult { debug!("coerce_unsafe_ptr(a=%s, sty_a=%?, b=%s)", a.inf_str(self.infcx), sty_a, b.inf_str(self.infcx)); diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index 3640748b20b54..cf3c64e5cd633 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -71,13 +71,15 @@ impl LatticeValue for ty::t { } } -pub impl CombineFields { - fn var_sub_var>>( - &self, - a_id: V, - b_id: V) -> ures - { +impl CombineFields { + pub fn var_sub_var>>(&self, + a_id: + V, + b_id: + V) + -> + ures { /*! * * Make one variable a subtype of another variable. This is a @@ -125,12 +127,12 @@ pub impl CombineFields { } /// make variable a subtype of T - fn var_sub_t>>( - &self, - a_id: V, - b: T) -> ures - { + pub fn var_sub_t>>(&self, + a_id: V, + b: T) + -> ures + { /*! * * Make a variable (`a_id`) a subtype of the concrete type `b` */ @@ -149,12 +151,12 @@ pub impl CombineFields { a_id, a_bounds, b_bounds, node_a.rank) } - fn t_sub_var>>( - &self, - a: T, - b_id: V) -> ures - { + pub fn t_sub_var>>(&self, + a: T, + b_id: V) + -> ures + { /*! * * Make a concrete type (`a`) a subtype of the variable `b_id` */ @@ -173,13 +175,12 @@ pub impl CombineFields { b_id, a_bounds, b_bounds, node_b.rank) } - fn merge_bnd( - &self, - a: &Bound, - b: &Bound, - lattice_op: LatticeOp) - -> cres> - { + pub fn merge_bnd(&self, + a: &Bound, + b: &Bound, + lattice_op: + LatticeOp) + -> cres> { /*! * * Combines two bounds into a more general bound. */ @@ -201,14 +202,14 @@ pub impl CombineFields { } } - fn set_var_to_merged_bounds>>( - &self, - v_id: V, - a: &Bounds, - b: &Bounds, - rank: uint) -> ures - { + pub fn set_var_to_merged_bounds>>( + &self, + v_id: V, + a: &Bounds, + b: &Bounds, + rank: uint) + -> ures { /*! * * Updates the bounds for the variable `v_id` to be the intersection @@ -263,11 +264,10 @@ pub impl CombineFields { uok() } - fn bnds( - &self, - a: &Bound, - b: &Bound) -> ures - { + pub fn bnds(&self, + a: &Bound, + b: &Bound) + -> ures { debug!("bnds(%s <: %s)", a.inf_str(self.infcx), b.inf_str(self.infcx)); let _r = indenter(); diff --git a/src/librustc/middle/typeck/infer/lub.rs b/src/librustc/middle/typeck/infer/lub.rs index f5eb0bc26351a..1a73d5bd36bbb 100644 --- a/src/librustc/middle/typeck/infer/lub.rs +++ b/src/librustc/middle/typeck/infer/lub.rs @@ -34,10 +34,11 @@ use syntax::codemap::span; pub struct Lub(CombineFields); // least-upper-bound: common supertype -pub impl Lub { - fn bot_ty(&self, b: ty::t) -> cres { Ok(b) } - fn ty_bot(&self, b: ty::t) - -> cres { self.bot_ty(b) } // commutative +impl Lub { + pub fn bot_ty(&self, b: ty::t) -> cres { Ok(b) } + pub fn ty_bot(&self, b: ty::t) -> cres { + self.bot_ty(b) // commutative + } } impl Combine for Lub { diff --git a/src/librustc/middle/typeck/infer/mod.rs b/src/librustc/middle/typeck/infer/mod.rs index 6a1fd05baf745..00e5415e0414a 100644 --- a/src/librustc/middle/typeck/infer/mod.rs +++ b/src/librustc/middle/typeck/infer/mod.rs @@ -535,24 +535,23 @@ struct Snapshot { region_vars_snapshot: uint, } -pub impl InferCtxt { - fn combine_fields(@mut self, - a_is_expected: bool, - span: span) -> CombineFields { +impl InferCtxt { + pub fn combine_fields(@mut self, a_is_expected: bool, span: span) + -> CombineFields { CombineFields {infcx: self, a_is_expected: a_is_expected, span: span} } - fn sub(@mut self, a_is_expected: bool, span: span) -> Sub { + pub fn sub(@mut self, a_is_expected: bool, span: span) -> Sub { Sub(self.combine_fields(a_is_expected, span)) } - fn in_snapshot(&self) -> bool { + pub fn in_snapshot(&self) -> bool { self.region_vars.in_snapshot() } - fn start_snapshot(&mut self) -> Snapshot { + pub fn start_snapshot(&mut self) -> Snapshot { Snapshot { ty_var_bindings_len: self.ty_var_bindings.bindings.len(), @@ -565,7 +564,7 @@ pub impl InferCtxt { } } - fn rollback_to(&mut self, snapshot: &Snapshot) { + pub fn rollback_to(&mut self, snapshot: &Snapshot) { debug!("rollback!"); rollback_to(&mut self.ty_var_bindings, snapshot.ty_var_bindings_len); @@ -578,7 +577,7 @@ pub impl InferCtxt { } /// Execute `f` and commit the bindings if successful - fn commit(@mut self, f: &fn() -> Result) -> Result { + pub fn commit(@mut self, f: &fn() -> Result) -> Result { assert!(!self.in_snapshot()); debug!("commit()"); @@ -593,7 +592,7 @@ pub impl InferCtxt { } /// Execute `f`, unroll bindings on failure - fn try(@mut self, f: &fn() -> Result) -> Result { + pub fn try(@mut self, f: &fn() -> Result) -> Result { debug!("try()"); do indent { let snapshot = self.start_snapshot(); @@ -607,7 +606,7 @@ pub impl InferCtxt { } /// Execute `f` then unroll any bindings it creates - fn probe(@mut self, f: &fn() -> Result) -> Result { + pub fn probe(@mut self, f: &fn() -> Result) -> Result { debug!("probe()"); do indent { let snapshot = self.start_snapshot(); @@ -628,8 +627,8 @@ fn next_simple_var( return id; } -pub impl InferCtxt { - fn next_ty_var_id(&mut self) -> TyVid { +impl InferCtxt { + pub fn next_ty_var_id(&mut self) -> TyVid { let id = self.ty_var_counter; self.ty_var_counter += 1; { @@ -639,38 +638,40 @@ pub impl InferCtxt { return TyVid(id); } - fn next_ty_var(&mut self) -> ty::t { + pub fn next_ty_var(&mut self) -> ty::t { ty::mk_var(self.tcx, self.next_ty_var_id()) } - fn next_ty_vars(&mut self, n: uint) -> ~[ty::t] { + pub fn next_ty_vars(&mut self, n: uint) -> ~[ty::t] { vec::from_fn(n, |_i| self.next_ty_var()) } - fn next_int_var_id(&mut self) -> IntVid { + pub fn next_int_var_id(&mut self) -> IntVid { IntVid(next_simple_var(&mut self.int_var_counter, &mut self.int_var_bindings)) } - fn next_int_var(&mut self) -> ty::t { + pub fn next_int_var(&mut self) -> ty::t { ty::mk_int_var(self.tcx, self.next_int_var_id()) } - fn next_float_var_id(&mut self) -> FloatVid { + pub fn next_float_var_id(&mut self) -> FloatVid { FloatVid(next_simple_var(&mut self.float_var_counter, &mut self.float_var_bindings)) } - fn next_float_var(&mut self) -> ty::t { + pub fn next_float_var(&mut self) -> ty::t { ty::mk_float_var(self.tcx, self.next_float_var_id()) } - fn next_region_var_nb(&mut self, span: span) -> ty::Region { + pub fn next_region_var_nb(&mut self, span: span) -> ty::Region { ty::re_infer(ty::ReVar(self.region_vars.new_region_var(span))) } - fn next_region_var_with_lb(&mut self, span: span, - lb_region: ty::Region) -> ty::Region { + pub fn next_region_var_with_lb(&mut self, + span: span, + lb_region: ty::Region) + -> ty::Region { let region_var = self.next_region_var_nb(span); // add lb_region as a lower bound on the newly built variable @@ -681,35 +682,36 @@ pub impl InferCtxt { return region_var; } - fn next_region_var(&mut self, span: span, scope_id: ast::node_id) - -> ty::Region { + pub fn next_region_var(&mut self, span: span, scope_id: ast::node_id) + -> ty::Region { self.next_region_var_with_lb(span, ty::re_scope(scope_id)) } - fn resolve_regions(&mut self) { + pub fn resolve_regions(&mut self) { self.region_vars.resolve_regions(); } - fn ty_to_str(@mut self, t: ty::t) -> ~str { + pub fn ty_to_str(@mut self, t: ty::t) -> ~str { ty_to_str(self.tcx, self.resolve_type_vars_if_possible(t)) } - fn trait_ref_to_str(@mut self, t: &ty::TraitRef) -> ~str { + pub fn trait_ref_to_str(@mut self, t: &ty::TraitRef) -> ~str { let t = self.resolve_type_vars_in_trait_ref_if_possible(t); trait_ref_to_str(self.tcx, &t) } - fn resolve_type_vars_if_possible(@mut self, typ: ty::t) -> ty::t { + pub fn resolve_type_vars_if_possible(@mut self, typ: ty::t) -> ty::t { match resolve_type(self, typ, resolve_nested_tvar | resolve_ivar) { result::Ok(new_type) => new_type, result::Err(_) => typ } } - fn resolve_type_vars_in_trait_ref_if_possible(@mut self, - trait_ref: &ty::TraitRef) - -> ty::TraitRef - { + + pub fn resolve_type_vars_in_trait_ref_if_possible(@mut self, + trait_ref: + &ty::TraitRef) + -> ty::TraitRef { // make up a dummy type just to reuse/abuse the resolve machinery let dummy0 = ty::mk_trait(self.tcx, trait_ref.def_id, @@ -732,18 +734,22 @@ pub impl InferCtxt { } } - fn type_error_message_str(@mut self, - sp: span, - mk_msg: &fn(Option<~str>, ~str) -> ~str, - actual_ty: ~str, err: Option<&ty::type_err>) { + pub fn type_error_message_str(@mut self, + sp: span, + mk_msg: &fn(Option<~str>, ~str) -> ~str, + actual_ty: ~str, + err: Option<&ty::type_err>) { self.type_error_message_str_with_expected(sp, mk_msg, None, actual_ty, err) } - fn type_error_message_str_with_expected(@mut self, - sp: span, - mk_msg: &fn(Option<~str>, ~str) -> ~str, - expected_ty: Option, actual_ty: ~str, - err: Option<&ty::type_err>) { + pub fn type_error_message_str_with_expected(@mut self, + sp: span, + mk_msg: + &fn(Option<~str>, ~str) -> + ~str, + expected_ty: Option, + actual_ty: ~str, + err: Option<&ty::type_err>) { debug!("hi! expected_ty = %?, actual_ty = %s", expected_ty, actual_ty); let error_str = err.map_default(~"", |t_err| @@ -766,11 +772,11 @@ pub impl InferCtxt { } } - fn type_error_message(@mut self, - sp: span, - mk_msg: &fn(~str) -> ~str, - actual_ty: ty::t, - err: Option<&ty::type_err>) { + pub fn type_error_message(@mut self, + sp: span, + mk_msg: &fn(~str) -> ~str, + actual_ty: ty::t, + err: Option<&ty::type_err>) { let actual_ty = self.resolve_type_vars_if_possible(actual_ty); // Don't report an error if actual type is ty_err. @@ -781,8 +787,11 @@ pub impl InferCtxt { self.type_error_message_str(sp, |_e, a| { mk_msg(a) }, self.ty_to_str(actual_ty), err); } - fn report_mismatched_types(@mut self, sp: span, e: ty::t, a: ty::t, - err: &ty::type_err) { + pub fn report_mismatched_types(@mut self, + sp: span, + e: ty::t, + a: ty::t, + err: &ty::type_err) { let resolved_expected = self.resolve_type_vars_if_possible(e); let mk_msg = match ty::get(resolved_expected).sty { @@ -799,10 +808,11 @@ pub impl InferCtxt { self.type_error_message(sp, mk_msg, a, Some(err)); } - fn replace_bound_regions_with_fresh_regions(&mut self, - span: span, - fsig: &ty::FnSig) - -> (ty::FnSig, isr_alist) { + pub fn replace_bound_regions_with_fresh_regions(&mut self, + span: span, + fsig: &ty::FnSig) + -> (ty::FnSig, + isr_alist) { let(isr, _, fn_sig) = replace_bound_regions_in_fn_sig(self.tcx, @Nil, None, fsig, |br| { // N.B.: The name of the bound region doesn't have anything to diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index 556fcfeac99a5..f99d096f03d75 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -643,12 +643,12 @@ pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings { } } -pub impl RegionVarBindings { - fn in_snapshot(&self) -> bool { +impl RegionVarBindings { + pub fn in_snapshot(&self) -> bool { self.undo_log.len() > 0 } - fn start_snapshot(&mut self) -> uint { + pub fn start_snapshot(&mut self) -> uint { debug!("RegionVarBindings: snapshot()=%u", self.undo_log.len()); if self.in_snapshot() { self.undo_log.len() @@ -658,14 +658,14 @@ pub impl RegionVarBindings { } } - fn commit(&mut self) { + pub fn commit(&mut self) { debug!("RegionVarBindings: commit()"); while self.undo_log.len() > 0 { self.undo_log.pop(); } } - fn rollback_to(&mut self, snapshot: uint) { + pub fn rollback_to(&mut self, snapshot: uint) { debug!("RegionVarBindings: rollback_to(%u)", snapshot); while self.undo_log.len() > snapshot { let undo_item = self.undo_log.pop(); @@ -689,11 +689,11 @@ pub impl RegionVarBindings { } } - fn num_vars(&mut self) -> uint { + pub fn num_vars(&mut self) -> uint { self.var_spans.len() } - fn new_region_var(&mut self, span: span) -> RegionVid { + pub fn new_region_var(&mut self, span: span) -> RegionVid { let id = self.num_vars(); self.var_spans.push(span); let vid = RegionVid { id: id }; @@ -705,13 +705,13 @@ pub impl RegionVarBindings { return vid; } - fn new_skolemized(&mut self, br: ty::bound_region) -> Region { + pub fn new_skolemized(&mut self, br: ty::bound_region) -> Region { let sc = self.skolemization_count; self.skolemization_count += 1; re_infer(ReSkolemized(sc, br)) } - fn new_bound(&mut self) -> Region { + pub fn new_bound(&mut self) -> Region { // Creates a fresh bound variable for use in GLB computations. // See discussion of GLB computation in the large comment at // the top of this file for more details. @@ -731,7 +731,7 @@ pub impl RegionVarBindings { re_bound(br_fresh(sc)) } - fn add_constraint(&mut self, constraint: Constraint, span: span) { + pub fn add_constraint(&mut self, constraint: Constraint, span: span) { // cannot add constraints once regions are resolved assert!(self.values.is_empty()); @@ -744,10 +744,8 @@ pub impl RegionVarBindings { } } - fn make_subregion(&mut self, - span: span, - sub: Region, - sup: Region) -> cres<()> { + pub fn make_subregion(&mut self, span: span, sub: Region, sup: Region) + -> cres<()> { // cannot add constraints once regions are resolved assert!(self.values.is_empty()); @@ -785,11 +783,8 @@ pub impl RegionVarBindings { } } - fn lub_regions(&mut self, - span: span, - a: Region, - b: Region) - -> cres { + pub fn lub_regions(&mut self, span: span, a: Region, b: Region) + -> cres { // cannot add constraints once regions are resolved assert!(self.values.is_empty()); @@ -811,11 +806,8 @@ pub impl RegionVarBindings { } } - fn glb_regions(&mut self, - span: span, - a: Region, - b: Region) - -> cres { + pub fn glb_regions(&mut self, span: span, a: Region, b: Region) + -> cres { // cannot add constraints once regions are resolved assert!(self.values.is_empty()); @@ -838,7 +830,7 @@ pub impl RegionVarBindings { } } - fn resolve_var(&mut self, rid: RegionVid) -> ty::Region { + pub fn resolve_var(&mut self, rid: RegionVid) -> ty::Region { if self.values.is_empty() { self.tcx.sess.span_bug( self.var_spans[rid.to_uint()], @@ -864,15 +856,15 @@ pub impl RegionVarBindings { } } - fn combine_vars(&mut self, - t: CombineMapType, - a: Region, - b: Region, - span: span, - relate: &fn(this: &mut RegionVarBindings, - old_r: Region, - new_r: Region) -> cres<()>) - -> cres { + pub fn combine_vars(&mut self, + t: CombineMapType, + a: Region, + b: Region, + span: span, + relate: &fn(this: &mut RegionVarBindings, + old_r: Region, + new_r: Region) -> cres<()>) + -> cres { let vars = TwoRegions { a: a, b: b }; let c; { @@ -906,9 +898,8 @@ pub impl RegionVarBindings { } } - fn vars_created_since_snapshot(&mut self, - snapshot: uint) - -> ~[RegionVid] { + pub fn vars_created_since_snapshot(&mut self, snapshot: uint) + -> ~[RegionVid] { do vec::build |push| { for uint::range(snapshot, self.undo_log.len()) |i| { match self.undo_log[i] { @@ -919,7 +910,7 @@ pub impl RegionVarBindings { } } - fn tainted(&mut self, snapshot: uint, r0: Region) -> ~[Region] { + pub fn tainted(&mut self, snapshot: uint, r0: Region) -> ~[Region] { /*! * * Computes all regions that have been related to `r0` in any @@ -1003,14 +994,14 @@ pub impl RegionVarBindings { constraints, assuming such values can be found; if they cannot, errors are reported. */ - fn resolve_regions(&mut self) { + pub fn resolve_regions(&mut self) { debug!("RegionVarBindings: resolve_regions()"); let v = self.infer_variable_values(); self.values.put_back(v); } } -priv impl RegionVarBindings { +impl RegionVarBindings { fn is_subregion_of(&self, sub: Region, sup: Region) -> bool { let rm = self.tcx.region_maps; rm.is_subregion_of(sub, sup) @@ -1266,15 +1257,15 @@ struct SpannedRegion { span: span, } -pub impl RegionVarBindings { - fn infer_variable_values(&mut self) -> ~[GraphNodeValue] { +impl RegionVarBindings { + pub fn infer_variable_values(&mut self) -> ~[GraphNodeValue] { let mut graph = self.construct_graph(); self.expansion(&mut graph); self.contraction(&mut graph); self.extract_values_and_report_conflicts(&graph) } - fn construct_graph(&mut self) -> Graph { + pub fn construct_graph(&mut self) -> Graph { let num_vars = self.num_vars(); let num_edges = self.constraints.len(); @@ -1339,7 +1330,7 @@ pub impl RegionVarBindings { } } - fn expansion(&mut self, graph: &mut Graph) { + pub fn expansion(&mut self, graph: &mut Graph) { do iterate_until_fixed_point(~"Expansion", graph) |nodes, edge| { match edge.constraint { ConstrainRegSubVar(a_region, b_vid) => { @@ -1363,11 +1354,11 @@ pub impl RegionVarBindings { } } - fn expand_node(&mut self, - a_region: Region, - b_vid: RegionVid, - b_node: &mut GraphNode) - -> bool { + pub fn expand_node(&mut self, + a_region: Region, + b_vid: RegionVid, + b_node: &mut GraphNode) + -> bool { debug!("expand_node(%?, %? == %?)", a_region, b_vid, b_node.value); @@ -1399,7 +1390,7 @@ pub impl RegionVarBindings { } } - fn contraction(&mut self, graph: &mut Graph) { + pub fn contraction(&mut self, graph: &mut Graph) { do iterate_until_fixed_point(~"Contraction", graph) |nodes, edge| { match edge.constraint { ConstrainRegSubVar(*) => { @@ -1423,11 +1414,11 @@ pub impl RegionVarBindings { } } - fn contract_node(&mut self, - a_vid: RegionVid, - a_node: &mut GraphNode, - b_region: Region) - -> bool { + pub fn contract_node(&mut self, + a_vid: RegionVid, + a_node: &mut GraphNode, + b_region: Region) + -> bool { debug!("contract_node(%? == %?/%?, %?)", a_vid, a_node.value, a_node.classification, b_region); @@ -1495,10 +1486,8 @@ pub impl RegionVarBindings { } } - fn extract_values_and_report_conflicts( - &mut self, - graph: &Graph) -> ~[GraphNodeValue] - { + pub fn extract_values_and_report_conflicts(&mut self, graph: &Graph) + -> ~[GraphNodeValue] { debug!("extract_values_and_report_conflicts()"); // This is the best way that I have found to suppress @@ -1567,10 +1556,10 @@ pub impl RegionVarBindings { }) } - fn report_error_for_expanding_node(&mut self, - graph: &Graph, - dup_vec: &mut [uint], - node_idx: RegionVid) { + pub fn report_error_for_expanding_node(&mut self, + graph: &Graph, + dup_vec: &mut [uint], + node_idx: RegionVid) { // Errors in expanding nodes result from a lower-bound that is // not contained by an upper-bound. let (lower_bounds, lower_dup) = @@ -1626,10 +1615,10 @@ pub impl RegionVarBindings { upper_bounds.map(|x| x.region).repr(self.tcx))); } - fn report_error_for_contracting_node(&mut self, - graph: &Graph, - dup_vec: &mut [uint], - node_idx: RegionVid) { + pub fn report_error_for_contracting_node(&mut self, + graph: &Graph, + dup_vec: &mut [uint], + node_idx: RegionVid) { // Errors in contracting nodes result from two upper-bounds // that have no intersection. let (upper_bounds, dup_found) = @@ -1685,12 +1674,12 @@ pub impl RegionVarBindings { upper_bounds.map(|x| x.region).repr(self.tcx))); } - fn collect_concrete_regions(&mut self, - graph: &Graph, - orig_node_idx: RegionVid, - dir: Direction, - dup_vec: &mut [uint]) - -> (~[SpannedRegion], bool) { + pub fn collect_concrete_regions(&mut self, + graph: &Graph, + orig_node_idx: RegionVid, + dir: Direction, + dup_vec: &mut [uint]) + -> (~[SpannedRegion], bool) { struct WalkState { set: HashSet, stack: ~[RegionVid], @@ -1766,11 +1755,12 @@ pub impl RegionVarBindings { } } - fn each_edge(&mut self, - graph: &Graph, - node_idx: RegionVid, - dir: Direction, - op: &fn(edge: &GraphEdge) -> bool) -> bool { + pub fn each_edge(&mut self, + graph: &Graph, + node_idx: RegionVid, + dir: Direction, + op: &fn(edge: &GraphEdge) -> bool) + -> bool { let mut edge_idx = graph.nodes[node_idx.to_uint()].head_edge[dir as uint]; while edge_idx != uint::max_value { diff --git a/src/librustc/middle/typeck/infer/resolve.rs b/src/librustc/middle/typeck/infer/resolve.rs index ea0bdc68ac253..c2ee7fc2647bd 100644 --- a/src/librustc/middle/typeck/infer/resolve.rs +++ b/src/librustc/middle/typeck/infer/resolve.rs @@ -98,12 +98,12 @@ pub fn resolver(infcx: @mut InferCtxt, modes: uint) -> ResolveState { } } -pub impl ResolveState { - fn should(&mut self, mode: uint) -> bool { +impl ResolveState { + pub fn should(&mut self, mode: uint) -> bool { (self.modes & mode) == mode } - fn resolve_type_chk(&mut self, typ: ty::t) -> fres { + pub fn resolve_type_chk(&mut self, typ: ty::t) -> fres { self.err = None; debug!("Resolving %s (modes=%x)", @@ -128,7 +128,8 @@ pub impl ResolveState { } } - fn resolve_region_chk(&mut self, orig: ty::Region) -> fres { + pub fn resolve_region_chk(&mut self, orig: ty::Region) + -> fres { self.err = None; let resolved = indent(|| self.resolve_region(orig) ); match self.err { @@ -137,7 +138,7 @@ pub impl ResolveState { } } - fn resolve_type(&mut self, typ: ty::t) -> ty::t { + pub fn resolve_type(&mut self, typ: ty::t) -> ty::t { debug!("resolve_type(%s)", typ.inf_str(self.infcx)); let _i = indenter(); @@ -179,7 +180,7 @@ pub impl ResolveState { } } - fn resolve_region(&mut self, orig: ty::Region) -> ty::Region { + pub fn resolve_region(&mut self, orig: ty::Region) -> ty::Region { debug!("Resolve_region(%s)", orig.inf_str(self.infcx)); match orig { ty::re_infer(ty::ReVar(rid)) => self.resolve_region_var(rid), @@ -187,14 +188,14 @@ pub impl ResolveState { } } - fn resolve_region_var(&mut self, rid: RegionVid) -> ty::Region { + pub fn resolve_region_var(&mut self, rid: RegionVid) -> ty::Region { if !self.should(resolve_rvar) { return ty::re_infer(ty::ReVar(rid)); } self.infcx.region_vars.resolve_var(rid) } - fn assert_not_rvar(&mut self, rid: RegionVid, r: ty::Region) { + pub fn assert_not_rvar(&mut self, rid: RegionVid, r: ty::Region) { match r { ty::re_infer(ty::ReVar(rid2)) => { self.err = Some(region_var_bound_by_region_var(rid, rid2)); @@ -203,7 +204,7 @@ pub impl ResolveState { } } - fn resolve_ty_var(&mut self, vid: TyVid) -> ty::t { + pub fn resolve_ty_var(&mut self, vid: TyVid) -> ty::t { if vec::contains(self.v_seen, &vid) { self.err = Some(cyclic_ty(vid)); return ty::mk_var(self.infcx.tcx, vid); @@ -237,7 +238,7 @@ pub impl ResolveState { } } - fn resolve_int_var(&mut self, vid: IntVid) -> ty::t { + pub fn resolve_int_var(&mut self, vid: IntVid) -> ty::t { if !self.should(resolve_ivar) { return ty::mk_int_var(self.infcx.tcx, vid); } @@ -260,7 +261,7 @@ pub impl ResolveState { } } - fn resolve_float_var(&mut self, vid: FloatVid) -> ty::t { + pub fn resolve_float_var(&mut self, vid: FloatVid) -> ty::t { if !self.should(resolve_fvar) { return ty::mk_float_var(self.infcx.tcx, vid); } diff --git a/src/librustc/middle/typeck/infer/test.rs b/src/librustc/middle/typeck/infer/test.rs index e39dd986c514b..e6e6753255e74 100644 --- a/src/librustc/middle/typeck/infer/test.rs +++ b/src/librustc/middle/typeck/infer/test.rs @@ -77,15 +77,15 @@ fn setup_env(test_name: &str, source_string: &str) -> Env { err_messages: messages}; } -pub impl Env { - fn create_region_hierarchy(&self, rh: &RH) { +impl Env { + pub fn create_region_hierarchy(&self, rh: &RH) { for rh.sub.each |child_rh| { self.create_region_hierarchy(child_rh); self.tcx.region_map.insert(child_rh.id, rh.id); } } - fn create_simple_region_hierarchy(&self) { + pub fn create_simple_region_hierarchy(&self) { // creates a region hierarchy where 1 is root, 10 and 11 are // children of 1, etc self.create_region_hierarchy( @@ -96,7 +96,7 @@ pub impl Env { sub: &[]}]}); } - fn lookup_item(&self, names: &[~str]) -> ast::node_id { + pub fn lookup_item(&self, names: &[~str]) -> ast::node_id { return match search_mod(self, &self.crate.node.module, 0, names) { Some(id) => id, None => { @@ -144,14 +144,14 @@ pub impl Env { } } - fn is_subtype(&self, a: ty::t, b: ty::t) -> bool { + pub fn is_subtype(&self, a: ty::t, b: ty::t) -> bool { match infer::can_mk_subty(self.infcx, a, b) { Ok(_) => true, Err(_) => false } } - fn assert_subtype(&self, a: ty::t, b: ty::t) { + pub fn assert_subtype(&self, a: ty::t, b: ty::t) { if !self.is_subtype(a, b) { fail!("%s is not a subtype of %s, but it should be", self.ty_to_str(a), @@ -159,7 +159,7 @@ pub impl Env { } } - fn assert_not_subtype(&self, a: ty::t, b: ty::t) { + pub fn assert_not_subtype(&self, a: ty::t, b: ty::t) { if self.is_subtype(a, b) { fail!("%s is a subtype of %s, but it shouldn't be", self.ty_to_str(a), @@ -167,21 +167,21 @@ pub impl Env { } } - fn assert_strict_subtype(&self, a: ty::t, b: ty::t) { + pub fn assert_strict_subtype(&self, a: ty::t, b: ty::t) { self.assert_subtype(a, b); self.assert_not_subtype(b, a); } - fn assert_eq(&self, a: ty::t, b: ty::t) { + pub fn assert_eq(&self, a: ty::t, b: ty::t) { self.assert_subtype(a, b); self.assert_subtype(b, a); } - fn ty_to_str(&self, a: ty::t) -> ~str { + pub fn ty_to_str(&self, a: ty::t) -> ~str { ty_to_str(self.tcx, a) } - fn t_fn(&self, input_tys: &[ty::t], output_ty: ty::t) -> ty::t { + pub fn t_fn(&self, input_tys: &[ty::t], output_ty: ty::t) -> ty::t { let inputs = input_tys.map(|t| {mode: ast::expl(ast::by_copy), ty: *t}); ty::mk_fn(self.tcx, FnTyBase { @@ -195,34 +195,34 @@ pub impl Env { }) } - fn t_int(&self) -> ty::t { + pub fn t_int(&self) -> ty::t { ty::mk_int(self.tcx) } - fn t_rptr_bound(&self, id: uint) -> ty::t { + pub fn t_rptr_bound(&self, id: uint) -> ty::t { ty::mk_imm_rptr(self.tcx, ty::re_bound(ty::br_anon(id)), self.t_int()) } - fn t_rptr_scope(&self, id: ast::node_id) -> ty::t { + pub fn t_rptr_scope(&self, id: ast::node_id) -> ty::t { ty::mk_imm_rptr(self.tcx, ty::re_scope(id), self.t_int()) } - fn t_rptr_free(&self, nid: ast::node_id, id: uint) -> ty::t { + pub fn t_rptr_free(&self, nid: ast::node_id, id: uint) -> ty::t { ty::mk_imm_rptr(self.tcx, ty::re_free(ty::FreeRegion {scope_id: nid, bound_region: ty::br_anon(id)}), self.t_int()) } - fn t_rptr_static(&self) -> ty::t { + pub fn t_rptr_static(&self) -> ty::t { ty::mk_imm_rptr(self.tcx, ty::re_static, self.t_int()) } - fn lub() -> Lub { Lub(self.infcx.combine_fields(true, dummy_sp())) } + pub fn lub() -> Lub { Lub(self.infcx.combine_fields(true, dummy_sp())) } - fn glb() -> Glb { Glb(self.infcx.combine_fields(true, dummy_sp())) } + pub fn glb() -> Glb { Glb(self.infcx.combine_fields(true, dummy_sp())) } - fn resolve_regions(exp_count: uint) { + pub fn resolve_regions(exp_count: uint) { debug!("resolve_regions(%u)", exp_count); self.infcx.resolve_regions(); @@ -237,7 +237,7 @@ pub impl Env { } /// Checks that `LUB(t1,t2) == t_lub` - fn check_lub(&self, t1: ty::t, t2: ty::t, t_lub: ty::t) { + pub fn check_lub(&self, t1: ty::t, t2: ty::t, t_lub: ty::t) { match self.lub().tys(t1, t2) { Err(e) => { fail!("Unexpected error computing LUB: %?", e) @@ -255,7 +255,7 @@ pub impl Env { } /// Checks that `GLB(t1,t2) == t_glb` - fn check_glb(&self, t1: ty::t, t2: ty::t, t_glb: ty::t) { + pub fn check_glb(&self, t1: ty::t, t2: ty::t, t_glb: ty::t) { debug!("check_glb(t1=%s, t2=%s, t_glb=%s)", self.ty_to_str(t1), self.ty_to_str(t2), @@ -277,7 +277,7 @@ pub impl Env { } /// Checks that `LUB(t1,t2)` is undefined - fn check_no_lub(&self, t1: ty::t, t2: ty::t) { + pub fn check_no_lub(&self, t1: ty::t, t2: ty::t) { match self.lub().tys(t1, t2) { Err(_) => {} Ok(t) => { @@ -287,7 +287,7 @@ pub impl Env { } /// Checks that `GLB(t1,t2)` is undefined - fn check_no_glb(&self, t1: ty::t, t2: ty::t) { + pub fn check_no_glb(&self, t1: ty::t, t2: ty::t) { match self.glb().tys(t1, t2) { Err(_) => {} Ok(t) => { diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index 78739bd7b04f9..c6e4b485d29b5 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -40,11 +40,9 @@ pub trait UnifyVid { -> &'v mut ValsAndBindings; } -pub impl InferCtxt { - fn get>( - &mut self, - vid: V) -> Node - { +impl InferCtxt { + pub fn get>(&mut self, vid: V) + -> Node { /*! * * Find the root node for `vid`. This uses the standard @@ -86,10 +84,10 @@ pub impl InferCtxt { } } - fn set>( - &mut self, - vid: V, - new_v: VarValue) { + pub fn set>(&mut self, + vid: V, + new_v: VarValue) { /*! * * Sets the value for `vid` to `new_v`. `vid` MUST be a root node! @@ -106,11 +104,11 @@ pub impl InferCtxt { } } - fn unify>( - &mut self, - node_a: &Node, - node_b: &Node) -> (V, uint) - { + pub fn unify>(&mut self, + node_a: &Node, + node_b: &Node) + -> (V, uint) { // Rank optimization: if you don't know what it is, check // out @@ -159,14 +157,14 @@ pub fn mk_err(a_is_expected: bool, } } -pub impl InferCtxt { - fn simple_vars>>( - &mut self, - a_is_expected: bool, - a_id: V, - b_id: V) - -> ures { +impl InferCtxt { + pub fn simple_vars>>(&mut self, + a_is_expected: + bool, + a_id: V, + b_id: V) + -> ures { /*! * * Unifies two simple variables. Because simple variables do @@ -198,13 +196,13 @@ pub impl InferCtxt { return uok(); } - fn simple_var_t>>( - &mut self, - a_is_expected: bool, - a_id: V, - b: T) - -> ures { + pub fn simple_var_t>>(&mut self, + a_is_expected + : bool, + a_id: V, + b: T) + -> ures { /*! * * Sets the value of the variable `a_id` to `b`. Because diff --git a/src/librustc/util/enum_set.rs b/src/librustc/util/enum_set.rs index 4e9b7cf00a0bd..85fceabf0ac8f 100644 --- a/src/librustc/util/enum_set.rs +++ b/src/librustc/util/enum_set.rs @@ -26,40 +26,40 @@ fn bit(e: E) -> uint { 1 << e.to_uint() } -pub impl EnumSet { - fn empty() -> EnumSet { +impl EnumSet { + pub fn empty() -> EnumSet { EnumSet {bits: 0} } - fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.bits == 0 } - fn intersects(&self, e: EnumSet) -> bool { + pub fn intersects(&self, e: EnumSet) -> bool { (self.bits & e.bits) != 0 } - fn intersection(&self, e: EnumSet) -> EnumSet { + pub fn intersection(&self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits & e.bits} } - fn contains(&self, e: EnumSet) -> bool { + pub fn contains(&self, e: EnumSet) -> bool { (self.bits & e.bits) == e.bits } - fn union(&self, e: EnumSet) -> EnumSet { + pub fn union(&self, e: EnumSet) -> EnumSet { EnumSet {bits: self.bits | e.bits} } - fn add(&mut self, e: E) { + pub fn add(&mut self, e: E) { self.bits |= bit(e); } - fn contains_elem(&self, e: E) -> bool { + pub fn contains_elem(&self, e: E) -> bool { (self.bits & bit(e)) != 0 } - fn each(&self, f: &fn(E) -> bool) -> bool { + pub fn each(&self, f: &fn(E) -> bool) -> bool { let mut bits = self.bits; let mut index = 0; while bits != 0 { diff --git a/src/librustdoc/doc.rs b/src/librustdoc/doc.rs index 2d5f60e714b50..283763c156471 100644 --- a/src/librustdoc/doc.rs +++ b/src/librustdoc/doc.rs @@ -172,8 +172,8 @@ pub struct IndexEntry { link: ~str } -pub impl Doc { - fn CrateDoc(&self) -> CrateDoc { +impl Doc { + pub fn CrateDoc(&self) -> CrateDoc { vec::foldl(None, self.pages, |_m, page| { match copy *page { doc::CratePage(doc) => Some(doc), @@ -182,14 +182,14 @@ pub impl Doc { }).get() } - fn cratemod(&self) -> ModDoc { + pub fn cratemod(&self) -> ModDoc { copy self.CrateDoc().topmod } } /// Some helper methods on ModDoc, mostly for testing -pub impl ModDoc { - fn mods(&self) -> ~[ModDoc] { +impl ModDoc { + pub fn mods(&self) -> ~[ModDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { ModTag(ModDoc) => Some(ModDoc), @@ -198,7 +198,7 @@ pub impl ModDoc { } } - fn nmods(&self) -> ~[NmodDoc] { + pub fn nmods(&self) -> ~[NmodDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { NmodTag(nModDoc) => Some(nModDoc), @@ -207,7 +207,7 @@ pub impl ModDoc { } } - fn fns(&self) -> ~[FnDoc] { + pub fn fns(&self) -> ~[FnDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { FnTag(FnDoc) => Some(FnDoc), @@ -216,7 +216,7 @@ pub impl ModDoc { } } - fn consts(&self) -> ~[ConstDoc] { + pub fn consts(&self) -> ~[ConstDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { ConstTag(ConstDoc) => Some(ConstDoc), @@ -225,7 +225,7 @@ pub impl ModDoc { } } - fn enums(&self) -> ~[EnumDoc] { + pub fn enums(&self) -> ~[EnumDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { EnumTag(EnumDoc) => Some(EnumDoc), @@ -234,7 +234,7 @@ pub impl ModDoc { } } - fn traits(&self) -> ~[TraitDoc] { + pub fn traits(&self) -> ~[TraitDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { TraitTag(TraitDoc) => Some(TraitDoc), @@ -243,7 +243,7 @@ pub impl ModDoc { } } - fn impls(&self) -> ~[ImplDoc] { + pub fn impls(&self) -> ~[ImplDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { ImplTag(ImplDoc) => Some(ImplDoc), @@ -252,7 +252,7 @@ pub impl ModDoc { } } - fn types(&self) -> ~[TyDoc] { + pub fn types(&self) -> ~[TyDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { TyTag(TyDoc) => Some(TyDoc), @@ -261,7 +261,7 @@ pub impl ModDoc { } } - fn structs(&self) -> ~[StructDoc] { + pub fn structs(&self) -> ~[StructDoc] { do vec::filter_mapped(self.items) |itemtag| { match copy *itemtag { StructTag(StructDoc) => Some(StructDoc), diff --git a/src/librustdoc/prune_private_pass.rs b/src/librustdoc/prune_private_pass.rs index 26344ebbc6139..a2fa80daa3ba2 100644 --- a/src/librustdoc/prune_private_pass.rs +++ b/src/librustdoc/prune_private_pass.rs @@ -212,8 +212,8 @@ mod test { #[test] fn should_prune_priv_associated_methods_on_pub_impls() { let doc = mk_doc( - ~"pub impl Foo {\ - fn bar() { }\ + ~"impl Foo {\ + pub fn bar() { }\ priv fn baz() { }\ }"); assert_eq!(doc.cratemod().impls()[0].methods.len(), 1); @@ -222,7 +222,7 @@ mod test { #[test] fn should_prune_associated_methods_without_vis_modifier_on_priv_impls() { let doc = mk_doc( - ~"priv impl Foo {\ + ~"impl Foo {\ pub fn bar() { }\ fn baz() { }\ }"); @@ -232,7 +232,7 @@ mod test { #[test] fn should_prune_priv_associated_methods_on_priv_impls() { let doc = mk_doc( - ~"priv impl Foo {\ + ~"impl Foo {\ pub fn bar() { }\ priv fn baz() { }\ }"); @@ -242,7 +242,7 @@ mod test { #[test] fn should_prune_associated_impls_with_no_pub_methods() { let doc = mk_doc( - ~"priv impl Foo {\ + ~"impl Foo {\ fn baz() { }\ }"); assert!(doc.cratemod().impls().is_empty()); diff --git a/src/librustdoc/sort_item_type_pass.rs b/src/librustdoc/sort_item_type_pass.rs index cdb1a49c36dd7..bf4c7027ce21b 100644 --- a/src/librustdoc/sort_item_type_pass.rs +++ b/src/librustdoc/sort_item_type_pass.rs @@ -47,7 +47,7 @@ fn test() { fn ifn() { } \ enum ienum { ivar } \ trait itrait { fn a(); } \ - pub impl int { fn a() { } } \ + impl int { fn a() { } } \ type itype = int; \ struct istruct { f: () }"; do astsrv::from_str(source) |srv| { diff --git a/src/librustpkg/rustpkg.rc b/src/librustpkg/rustpkg.rc index 6b560541e52bc..ada03e777ca63 100644 --- a/src/librustpkg/rustpkg.rc +++ b/src/librustpkg/rustpkg.rc @@ -430,9 +430,8 @@ pub struct Crate { cfgs: ~[~str] } -pub impl Crate { - - fn new(p: &Path) -> Crate { +impl Crate { + pub fn new(p: &Path) -> Crate { Crate { file: copy *p, flags: ~[], @@ -440,28 +439,28 @@ pub impl Crate { } } - fn flag(&self, flag: ~str) -> Crate { + pub fn flag(&self, flag: ~str) -> Crate { Crate { flags: vec::append(copy self.flags, [flag]), .. copy *self } } - fn flags(&self, flags: ~[~str]) -> Crate { + pub fn flags(&self, flags: ~[~str]) -> Crate { Crate { flags: vec::append(copy self.flags, flags), .. copy *self } } - fn cfg(&self, cfg: ~str) -> Crate { + pub fn cfg(&self, cfg: ~str) -> Crate { Crate { cfgs: vec::append(copy self.cfgs, [cfg]), .. copy *self } } - fn cfgs(&self, cfgs: ~[~str]) -> Crate { + pub fn cfgs(&self, cfgs: ~[~str]) -> Crate { Crate { cfgs: vec::append(copy self.cfgs, cfgs), .. copy *self diff --git a/src/librustpkg/util.rs b/src/librustpkg/util.rs index 8019b3b8afb00..34fd719fc4c6b 100644 --- a/src/librustpkg/util.rs +++ b/src/librustpkg/util.rs @@ -107,8 +107,8 @@ pub struct PkgId { version: Version } -pub impl PkgId { - fn new(s: &str) -> PkgId { +impl PkgId { + pub fn new(s: &str) -> PkgId { use conditions::bad_pkg_id::cond; let p = Path(s); @@ -129,13 +129,13 @@ pub impl PkgId { } } - fn hash(&self) -> ~str { + pub fn hash(&self) -> ~str { fmt!("%s-%s-%s", self.remote_path.to_str(), hash(self.remote_path.to_str() + self.version.to_str()), self.version.to_str()) } - fn short_name_with_version(&self) -> ~str { + pub fn short_name_with_version(&self) -> ~str { fmt!("%s-%s", self.short_name, self.version.to_str()) } } diff --git a/src/libstd/cell.rs b/src/libstd/cell.rs index 87145acbb6256..ab4752ff84770 100644 --- a/src/libstd/cell.rs +++ b/src/libstd/cell.rs @@ -10,6 +10,8 @@ //! A mutable, nullable memory location +#[missing_doc]; + use cast::transmute_mut; use prelude::*; use util::replace; @@ -37,9 +39,9 @@ pub fn empty_cell() -> Cell { Cell { value: None } } -pub impl Cell { +impl Cell { /// Yields the value, failing if the cell is empty. - fn take(&self) -> T { + pub fn take(&self) -> T { let this = unsafe { transmute_mut(self) }; if this.is_empty() { fail!("attempt to take an empty cell"); @@ -49,7 +51,7 @@ pub impl Cell { } /// Returns the value, failing if the cell is full. - fn put_back(&self, value: T) { + pub fn put_back(&self, value: T) { let this = unsafe { transmute_mut(self) }; if !this.is_empty() { fail!("attempt to put a value back into a full cell"); @@ -58,20 +60,20 @@ pub impl Cell { } /// Returns true if the cell is empty and false if the cell is full. - fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.value.is_none() } - // Calls a closure with a reference to the value. - fn with_ref(&self, op: &fn(v: &T) -> R) -> R { + /// Calls a closure with a reference to the value. + pub fn with_ref(&self, op: &fn(v: &T) -> R) -> R { let v = self.take(); let r = op(&v); self.put_back(v); r } - // Calls a closure with a mutable reference to the value. - fn with_mut_ref(&self, op: &fn(v: &mut T) -> R) -> R { + /// Calls a closure with a mutable reference to the value. + pub fn with_mut_ref(&self, op: &fn(v: &mut T) -> R) -> R { let mut v = self.take(); let r = op(&mut v); self.put_back(v); diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index e044a73b338fe..a376a71597694 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -150,14 +150,14 @@ pub struct PortSet { ports: ~[pipesy::Port], } -pub impl PortSet { - fn new() -> PortSet { +impl PortSet { + pub fn new() -> PortSet { PortSet { ports: ~[] } } - fn add(&self, port: Port) { + pub fn add(&self, port: Port) { let Port { inner } = port; let port = match inner { Left(p) => p, @@ -169,7 +169,7 @@ pub impl PortSet { } } - fn chan(&self) -> Chan { + pub fn chan(&self) -> Chan { let (po, ch) = stream(); self.add(po); ch @@ -470,20 +470,20 @@ mod pipesy { (PortOne::new(port), ChanOne::new(chan)) } - pub impl PortOne { - fn recv(self) -> T { recv_one(self) } - fn try_recv(self) -> Option { try_recv_one(self) } - fn unwrap(self) -> oneshot::server::Oneshot { + impl PortOne { + pub fn recv(self) -> T { recv_one(self) } + pub fn try_recv(self) -> Option { try_recv_one(self) } + pub fn unwrap(self) -> oneshot::server::Oneshot { match self { PortOne { contents: s } => s } } } - pub impl ChanOne { - fn send(self, data: T) { send_one(self, data) } - fn try_send(self, data: T) -> bool { try_send_one(self, data) } - fn unwrap(self) -> oneshot::client::Oneshot { + impl ChanOne { + pub fn send(self, data: T) { send_one(self, data) } + pub fn try_send(self, data: T) -> bool { try_send_one(self, data) } + pub fn unwrap(self) -> oneshot::client::Oneshot { match self { ChanOne { contents: s } => s } diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs index eed61aab5c0bc..2f150a0d1b283 100644 --- a/src/libstd/condition.rs +++ b/src/libstd/condition.rs @@ -29,8 +29,8 @@ pub struct Condition<'self, T, U> { key: local_data::LocalDataKey<'self, Handler> } -pub impl<'self, T, U> Condition<'self, T, U> { - fn trap(&'self self, h: &'self fn(T) -> U) -> Trap<'self, T, U> { +impl<'self, T, U> Condition<'self, T, U> { + pub fn trap(&'self self, h: &'self fn(T) -> U) -> Trap<'self, T, U> { unsafe { let p : *RustClosure = ::cast::transmute(&h); let prev = local_data::local_data_get(self.key); @@ -39,12 +39,12 @@ pub impl<'self, T, U> Condition<'self, T, U> { } } - fn raise(&self, t: T) -> U { + pub 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(&self, t: T, default: &fn() -> U) -> U { + pub fn raise_default(&self, t: T, default: &fn() -> U) -> U { unsafe { match local_data_pop(self.key) { None => { @@ -73,8 +73,8 @@ struct Trap<'self, T, U> { handler: @Handler } -pub impl<'self, T, U> Trap<'self, T, U> { - fn in(&self, inner: &'self fn() -> V) -> V { +impl<'self, T, U> Trap<'self, T, U> { + pub fn in(&self, inner: &'self fn() -> V) -> V { unsafe { let _g = Guard { cond: self.cond }; debug!("Trap: pushing handler to TLS"); diff --git a/src/libstd/either.rs b/src/libstd/either.rs index f89bb3b2f9064..fac0866f17e76 100644 --- a/src/libstd/either.rs +++ b/src/libstd/either.rs @@ -10,6 +10,8 @@ //! A type that represents one of two alternatives +#[allow(missing_doc)]; + use container::Container; use cmp::Eq; use kinds::Copy; @@ -137,29 +139,29 @@ pub fn unwrap_right(eith: Either) -> U { } } -pub impl Either { +impl Either { #[inline(always)] - fn either(&self, f_left: &fn(&T) -> V, f_right: &fn(&U) -> V) -> V { + pub fn either(&self, f_left: &fn(&T) -> V, f_right: &fn(&U) -> V) -> V { either(f_left, f_right, self) } #[inline(always)] - fn flip(self) -> Either { flip(self) } + pub fn flip(self) -> Either { flip(self) } #[inline(always)] - fn to_result(self) -> Result { to_result(self) } + pub fn to_result(self) -> Result { to_result(self) } #[inline(always)] - fn is_left(&self) -> bool { is_left(self) } + pub fn is_left(&self) -> bool { is_left(self) } #[inline(always)] - fn is_right(&self) -> bool { is_right(self) } + pub fn is_right(&self) -> bool { is_right(self) } #[inline(always)] - fn unwrap_left(self) -> T { unwrap_left(self) } + pub fn unwrap_left(self) -> T { unwrap_left(self) } #[inline(always)] - fn unwrap_right(self) -> U { unwrap_right(self) } + pub fn unwrap_right(self) -> U { unwrap_right(self) } } #[test] diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index 4826af20c69a1..2d56707e2f67a 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -13,6 +13,8 @@ //! The tables use a keyed hash with new random keys generated for each container, so the ordering //! of a set of keys in a hash table is randomized. +#[mutable_doc]; + use container::{Container, Mutable, Map, Set}; use cmp::{Eq, Equiv}; use hash::Hash; @@ -81,7 +83,7 @@ fn linear_map_with_capacity_and_keys( } } -priv impl HashMap { +impl HashMap { #[inline(always)] fn to_bucket(&self, h: uint) -> uint { // A good hash function with entropy spread over all of the @@ -403,20 +405,20 @@ impl Map for HashMap { } } -pub impl HashMap { +impl HashMap { /// Create an empty HashMap - fn new() -> HashMap { + pub fn new() -> HashMap { HashMap::with_capacity(INITIAL_CAPACITY) } /// Create an empty HashMap with space for at least `n` elements in /// the hash table. - fn with_capacity(capacity: uint) -> HashMap { + pub fn with_capacity(capacity: uint) -> HashMap { linear_map_with_capacity(capacity) } /// Reserve space for at least `n` elements in the hash table. - fn reserve_at_least(&mut self, n: uint) { + pub fn reserve_at_least(&mut self, n: uint) { if n > self.buckets.len() { let buckets = n * 4 / 3 + 1; self.resize(uint::next_power_of_two(buckets)); @@ -425,7 +427,7 @@ pub impl HashMap { /// Return the value corresponding to the key in the map, or insert /// and return the value if it doesn't exist. - fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V { + pub fn find_or_insert<'a>(&'a mut self, k: K, v: V) -> &'a V { if self.size >= self.resize_at { // n.b.: We could also do this after searching, so // that we do not resize if this call to insert is @@ -453,7 +455,8 @@ pub impl HashMap { /// Return the value corresponding to the key in the map, or create, /// insert, and return a new value if it doesn't exist. - fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) -> &'a V { + pub fn find_or_insert_with<'a>(&'a mut self, k: K, f: &fn(&K) -> V) + -> &'a V { if self.size >= self.resize_at { // n.b.: We could also do this after searching, so // that we do not resize if this call to insert is @@ -480,7 +483,9 @@ pub impl HashMap { self.value_for_bucket(idx) } - fn consume(&mut self, f: &fn(K, V)) { + /// Calls a function on each element of a hash map, destroying the hash + /// map in the process. + pub fn consume(&mut self, f: &fn(K, V)) { let buckets = replace(&mut self.buckets, vec::from_fn(INITIAL_CAPACITY, |_| None)); self.size = 0; @@ -495,7 +500,9 @@ pub impl HashMap { } } - fn get<'a>(&'a self, k: &K) -> &'a V { + /// Retrieves a value for the given key, failing if the key is not + /// present. + pub fn get<'a>(&'a self, k: &K) -> &'a V { match self.find(k) { Some(v) => v, None => fail!("No entry found for key: %?", k), @@ -504,7 +511,7 @@ pub impl HashMap { /// Return true if the map contains a value for the specified key, /// using equivalence - fn contains_key_equiv>(&self, key: &Q) -> bool { + pub fn contains_key_equiv>(&self, key: &Q) -> bool { match self.bucket_for_key_equiv(key) { FoundEntry(_) => {true} TableFull | FoundHole(_) => {false} @@ -513,7 +520,8 @@ pub impl HashMap { /// Return the value corresponding to the key in the map, using /// equivalence - fn find_equiv<'a, Q:Hash + Equiv>(&'a self, k: &Q) -> Option<&'a V> { + pub fn find_equiv<'a, Q:Hash + Equiv>(&'a self, k: &Q) + -> Option<&'a V> { match self.bucket_for_key_equiv(k) { FoundEntry(idx) => Some(self.value_for_bucket(idx)), TableFull | FoundHole(_) => None, @@ -521,14 +529,14 @@ pub impl HashMap { } } -pub impl HashMap { +impl HashMap { /// Like `find`, but returns a copy of the value. - fn find_copy(&self, k: &K) -> Option { + pub fn find_copy(&self, k: &K) -> Option { self.find(k).map_consume(|v| copy *v) } /// Like `get`, but returns a copy of the value. - fn get_copy(&self, k: &K) -> V { + pub fn get_copy(&self, k: &K) -> V { copy *self.get(k) } } @@ -632,29 +640,31 @@ impl Set for HashSet { } } -pub impl HashSet { +impl HashSet { /// Create an empty HashSet - fn new() -> HashSet { + pub fn new() -> HashSet { HashSet::with_capacity(INITIAL_CAPACITY) } /// Create an empty HashSet with space for at least `n` elements in /// the hash table. - fn with_capacity(capacity: uint) -> HashSet { + pub fn with_capacity(capacity: uint) -> HashSet { HashSet { map: HashMap::with_capacity(capacity) } } /// Reserve space for at least `n` elements in the hash table. - fn reserve_at_least(&mut self, n: uint) { + pub fn reserve_at_least(&mut self, n: uint) { self.map.reserve_at_least(n) } /// Consumes all of the elements in the set, emptying it out - fn consume(&mut self, f: &fn(T)) { + pub fn consume(&mut self, f: &fn(T)) { self.map.consume(|k, _| f(k)) } - fn contains_equiv>(&self, value: &Q) -> bool { + /// Returns true if the hash set contains a value equivalent to the + /// given query value. + pub fn contains_equiv>(&self, value: &Q) -> bool { self.map.contains_key_equiv(value) } } diff --git a/src/libstd/option.rs b/src/libstd/option.rs index ee6e37aeb783e..b9d04edd8a3b0 100644 --- a/src/libstd/option.rs +++ b/src/libstd/option.rs @@ -145,21 +145,20 @@ impl ExtendedIter for Option { } } -pub impl Option { +impl Option { /// Returns true if the option equals `none` - fn is_none(&const self) -> bool { + pub fn is_none(&const self) -> bool { match *self { None => true, Some(_) => false } } /// Returns true if the option contains some value #[inline(always)] - fn is_some(&const self) -> bool { !self.is_none() } + pub fn is_some(&const self) -> bool { !self.is_none() } /// Update an optional value by optionally running its content through a /// function that returns an option. #[inline(always)] - fn chain(self, f: &fn(t: T) -> Option) -> Option { - + pub fn chain(self, f: &fn(t: T) -> Option) -> Option { match self { Some(t) => f(t), None => None @@ -168,7 +167,7 @@ pub impl Option { /// Returns the leftmost Some() value, or None if both are None. #[inline(always)] - fn or(self, optb: Option) -> Option { + pub fn or(self, optb: Option) -> Option { match self { Some(opta) => Some(opta), _ => optb @@ -178,45 +177,49 @@ pub impl Option { /// Update an optional value by optionally running its content by reference /// through a function that returns an option. #[inline(always)] - fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option) -> Option { - match *self { Some(ref x) => f(x), None => None } + pub fn chain_ref<'a, U>(&'a self, f: &fn(x: &'a T) -> Option) + -> Option { + match *self { + Some(ref x) => f(x), + None => None + } } /// Maps a `some` value from one type to another by reference #[inline(always)] - fn map<'a, U>(&self, f: &fn(&'a T) -> U) -> Option { + pub fn map<'a, U>(&self, f: &fn(&'a T) -> U) -> Option { match *self { Some(ref x) => Some(f(x)), None => None } } /// As `map`, but consumes the option and gives `f` ownership to avoid /// copying. #[inline(always)] - fn map_consume(self, f: &fn(v: T) -> U) -> Option { + pub fn map_consume(self, f: &fn(v: T) -> U) -> Option { match self { None => None, Some(v) => Some(f(v)) } } /// Applies a function to the contained value or returns a default #[inline(always)] - fn map_default<'a, U>(&'a self, def: U, f: &fn(&'a T) -> U) -> U { + pub fn map_default<'a, U>(&'a self, def: U, f: &fn(&'a T) -> U) -> U { match *self { None => def, Some(ref t) => f(t) } } /// As `map_default`, but consumes the option and gives `f` /// ownership to avoid copying. #[inline(always)] - fn map_consume_default(self, def: U, f: &fn(v: T) -> U) -> U { + pub fn map_consume_default(self, def: U, f: &fn(v: T) -> U) -> U { match self { None => def, Some(v) => f(v) } } /// Apply a function to the contained value or do nothing - fn mutate(&mut self, f: &fn(T) -> T) { + pub fn mutate(&mut self, f: &fn(T) -> T) { if self.is_some() { *self = Some(f(self.swap_unwrap())); } } /// Apply a function to the contained value or set it to a default - fn mutate_default(&mut self, def: T, f: &fn(T) -> T) { + pub fn mutate_default(&mut self, def: T, f: &fn(T) -> T) { if self.is_some() { *self = Some(f(self.swap_unwrap())); } else { @@ -239,7 +242,7 @@ pub impl Option { case explicitly. */ #[inline(always)] - fn get_ref<'a>(&'a self) -> &'a T { + pub fn get_ref<'a>(&'a self) -> &'a T { match *self { Some(ref x) => x, None => fail!("option::get_ref none") @@ -261,7 +264,7 @@ pub impl Option { case explicitly. */ #[inline(always)] - fn get_mut_ref<'a>(&'a mut self) -> &'a mut T { + pub fn get_mut_ref<'a>(&'a mut self) -> &'a mut T { match *self { Some(ref mut x) => x, None => fail!("option::get_mut_ref none") @@ -269,7 +272,7 @@ pub impl Option { } #[inline(always)] - fn unwrap(self) -> T { + pub fn unwrap(self) -> T { /*! Moves a value out of an option type and returns it. @@ -301,7 +304,7 @@ pub impl Option { * Fails if the value equals `None`. */ #[inline(always)] - fn swap_unwrap(&mut self) -> T { + pub fn swap_unwrap(&mut self) -> T { if self.is_none() { fail!("option::swap_unwrap none") } util::replace(self, None).unwrap() } @@ -315,7 +318,7 @@ pub impl Option { * Fails if the value equals `none` */ #[inline(always)] - fn expect(self, reason: &str) -> T { + pub fn expect(self, reason: &str) -> T { match self { Some(val) => val, None => fail!(reason.to_owned()), @@ -323,7 +326,7 @@ pub impl Option { } } -pub impl Option { +impl Option { /** Gets the value out of an option @@ -339,7 +342,7 @@ pub impl Option { case explicitly. */ #[inline(always)] - fn get(self) -> T { + pub fn get(self) -> T { match self { Some(x) => return x, None => fail!("option::get none") @@ -348,13 +351,13 @@ pub impl Option { /// Returns the contained value or a default #[inline(always)] - fn get_or_default(self, def: T) -> T { + pub fn get_or_default(self, def: T) -> T { match self { Some(x) => x, None => def } } /// Applies a function zero or more times until the result is none. #[inline(always)] - fn while_some(self, blk: &fn(v: T) -> Option) { + pub fn while_some(self, blk: &fn(v: T) -> Option) { let mut opt = self; while opt.is_some() { opt = blk(opt.unwrap()); @@ -362,11 +365,14 @@ pub impl Option { } } -pub impl Option { +impl Option { /// Returns the contained value or zero (for this type) #[inline(always)] - fn get_or_zero(self) -> T { - match self { Some(x) => x, None => Zero::zero() } + pub fn get_or_zero(self) -> T { + match self { + Some(x) => x, + None => Zero::zero() + } } } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 9eb7b54f009a7..a551b9bf3c0b3 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -308,8 +308,8 @@ mod stat { } -pub impl Path { - fn stat(&self) -> Option { +impl Path { + pub fn stat(&self) -> Option { unsafe { do str::as_c_str(self.to_str()) |buf| { let mut st = stat::arch::default_stat(); @@ -322,7 +322,7 @@ pub impl Path { } #[cfg(unix)] - fn lstat(&self) -> Option { + pub fn lstat(&self) -> Option { unsafe { do str::as_c_str(self.to_str()) |buf| { let mut st = stat::arch::default_stat(); @@ -334,21 +334,21 @@ pub impl Path { } } - fn exists(&self) -> bool { + pub fn exists(&self) -> bool { match self.stat() { None => false, Some(_) => true, } } - fn get_size(&self) -> Option { + pub fn get_size(&self) -> Option { match self.stat() { None => None, Some(ref st) => Some(st.st_size as i64), } } - fn get_mode(&self) -> Option { + pub fn get_mode(&self) -> Option { match self.stat() { None => None, Some(ref st) => Some(st.st_mode as uint), @@ -359,8 +359,8 @@ pub impl Path { #[cfg(target_os = "freebsd")] #[cfg(target_os = "linux")] #[cfg(target_os = "macos")] -pub impl Path { - fn get_atime(&self) -> Option<(i64, int)> { +impl Path { + pub fn get_atime(&self) -> Option<(i64, int)> { match self.stat() { None => None, Some(ref st) => { @@ -370,7 +370,7 @@ pub impl Path { } } - fn get_mtime(&self) -> Option<(i64, int)> { + pub fn get_mtime(&self) -> Option<(i64, int)> { match self.stat() { None => None, Some(ref st) => { @@ -380,7 +380,7 @@ pub impl Path { } } - fn get_ctime(&self) -> Option<(i64, int)> { + pub fn get_ctime(&self) -> Option<(i64, int)> { match self.stat() { None => None, Some(ref st) => { @@ -393,8 +393,8 @@ pub impl Path { #[cfg(target_os = "freebsd")] #[cfg(target_os = "macos")] -pub impl Path { - fn get_birthtime(&self) -> Option<(i64, int)> { +impl Path { + pub fn get_birthtime(&self) -> Option<(i64, int)> { match self.stat() { None => None, Some(ref st) => { @@ -406,8 +406,8 @@ pub impl Path { } #[cfg(target_os = "win32")] -pub impl Path { - fn get_atime(&self) -> Option<(i64, int)> { +impl Path { + pub fn get_atime(&self) -> Option<(i64, int)> { match self.stat() { None => None, Some(ref st) => { @@ -416,7 +416,7 @@ pub impl Path { } } - fn get_mtime(&self) -> Option<(i64, int)> { + pub fn get_mtime(&self) -> Option<(i64, int)> { match self.stat() { None => None, Some(ref st) => { @@ -425,7 +425,7 @@ pub impl Path { } } - fn get_ctime(&self) -> Option<(i64, int)> { + pub fn get_ctime(&self) -> Option<(i64, int)> { match self.stat() { None => None, Some(ref st) => { diff --git a/src/libstd/pipes.rs b/src/libstd/pipes.rs index 5fbf97dccc877..9607d395151da 100644 --- a/src/libstd/pipes.rs +++ b/src/libstd/pipes.rs @@ -152,16 +152,16 @@ pub fn PacketHeader() -> PacketHeader { } } -pub impl PacketHeader { +impl PacketHeader { // Returns the old state. - unsafe fn mark_blocked(&mut self, this: *rust_task) -> State { + pub unsafe fn mark_blocked(&mut 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(&mut self) { + pub unsafe fn unblock(&mut self) { let old_task = swap_task(&mut self.blocked_task, ptr::null()); if !old_task.is_null() { rustrt::rust_task_deref(old_task) @@ -176,12 +176,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 probably want to forget them when you're done. - unsafe fn buf_header(&mut self) -> ~BufferHeader { + pub unsafe fn buf_header(&mut self) -> ~BufferHeader { assert!(self.buffer.is_not_null()); transmute_copy(&self.buffer) } - fn set_buffer(&mut self, b: ~Buffer) { + pub fn set_buffer(&mut self, b: ~Buffer) { unsafe { self.buffer = transmute_copy(&b); } @@ -694,12 +694,12 @@ pub fn SendPacketBuffered(p: *mut Packet) } } -pub impl SendPacketBuffered { - fn unwrap(&mut self) -> *mut Packet { +impl SendPacketBuffered { + pub fn unwrap(&mut self) -> *mut Packet { replace(&mut self.p, None).unwrap() } - fn header(&mut self) -> *mut PacketHeader { + pub fn header(&mut self) -> *mut PacketHeader { match self.p { Some(packet) => unsafe { let packet = &mut *packet; @@ -710,7 +710,7 @@ pub impl SendPacketBuffered { } } - fn reuse_buffer(&mut self) -> BufferResource { + pub fn reuse_buffer(&mut self) -> BufferResource { //error!("send reuse_buffer"); replace(&mut self.buffer, None).unwrap() } @@ -742,12 +742,12 @@ impl Drop for RecvPacketBuffered { } } -pub impl RecvPacketBuffered { - fn unwrap(&mut self) -> *mut Packet { +impl RecvPacketBuffered { + pub fn unwrap(&mut self) -> *mut Packet { replace(&mut self.p, None).unwrap() } - fn reuse_buffer(&mut self) -> BufferResource { + pub fn reuse_buffer(&mut self) -> BufferResource { replace(&mut self.buffer, None).unwrap() } } diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 07a5acbdde557..40d1744f0fb1e 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -612,9 +612,9 @@ pub struct IsaacRng { priv c: u32 } -pub impl IsaacRng { +impl IsaacRng { /// Create an ISAAC random number generator with a random seed. - fn new() -> IsaacRng { + pub fn new() -> IsaacRng { IsaacRng::new_seeded(seed()) } @@ -623,7 +623,7 @@ pub impl IsaacRng { /// will be silently ignored. A generator constructed with a given seed /// will generate the same sequence of values as all other generators /// constructed with the same seed. - fn new_seeded(seed: &[u8]) -> IsaacRng { + pub fn new_seeded(seed: &[u8]) -> IsaacRng { let mut rng = IsaacRng { cnt: 0, rsl: [0, .. RAND_SIZE], @@ -643,7 +643,7 @@ pub impl IsaacRng { /// Create an ISAAC random number generator using the default /// fixed seed. - fn new_unseeded() -> IsaacRng { + pub fn new_unseeded() -> IsaacRng { let mut rng = IsaacRng { cnt: 0, rsl: [0, .. RAND_SIZE], @@ -657,7 +657,7 @@ pub impl IsaacRng { /// Initialises `self`. If `use_rsl` is true, then use the current value /// of `rsl` as a seed, otherwise construct one algorithmically (not /// randomly). - priv fn init(&mut self, use_rsl: bool) { + fn init(&mut self, use_rsl: bool) { macro_rules! init_mut_many ( ($( $var:ident ),* = $val:expr ) => { let mut $( $var = $val ),*; @@ -715,7 +715,7 @@ pub impl IsaacRng { /// Refills the output buffer (`self.rsl`) #[inline] - priv fn isaac(&mut self) { + fn isaac(&mut self) { self.c += 1; // abbreviations let mut a = self.a, b = self.b + self.c; @@ -795,9 +795,9 @@ impl Rng for XorShiftRng { } } -pub impl XorShiftRng { +impl XorShiftRng { /// Create an xor shift random number generator with a default seed. - fn new() -> XorShiftRng { + pub fn new() -> XorShiftRng { // constants taken from http://en.wikipedia.org/wiki/Xorshift XorShiftRng::new_seeded(123456789u32, 362436069u32, @@ -807,10 +807,10 @@ pub impl XorShiftRng { /** * Create a random number generator using the specified seed. A generator - * constructed with a given seed will generate the same sequence of values as - * all other generators constructed with the same seed. + * constructed with a given seed will generate the same sequence of values + * as all other generators constructed with the same seed. */ - fn new_seeded(x: u32, y: u32, z: u32, w: u32) -> XorShiftRng { + pub fn new_seeded(x: u32, y: u32, z: u32, w: u32) -> XorShiftRng { XorShiftRng { x: x, y: y, diff --git a/src/libstd/reflect.rs b/src/libstd/reflect.rs index cadfa71e7fa9c..1eb3d3a0daaae 100644 --- a/src/libstd/reflect.rs +++ b/src/libstd/reflect.rs @@ -48,28 +48,28 @@ pub fn MovePtrAdaptor(v: V) -> MovePtrAdaptor { MovePtrAdaptor { inner: v } } -pub impl MovePtrAdaptor { +impl MovePtrAdaptor { #[inline(always)] - fn bump(&self, sz: uint) { - do self.inner.move_ptr() |p| { + pub fn bump(&self, sz: uint) { + do self.inner.move_ptr() |p| { ((p as uint) + sz) as *c_void - }; + }; } #[inline(always)] - fn align(&self, a: uint) { - do self.inner.move_ptr() |p| { + pub fn align(&self, a: uint) { + do self.inner.move_ptr() |p| { align(p as uint, a) as *c_void - }; + }; } #[inline(always)] - fn align_to(&self) { + pub fn align_to(&self) { self.align(sys::min_align_of::()); } #[inline(always)] - fn bump_past(&self) { + pub fn bump_past(&self) { self.bump(sys::size_of::()); } } diff --git a/src/libstd/repr.rs b/src/libstd/repr.rs index c50823f471ec1..14bec48782ff3 100644 --- a/src/libstd/repr.rs +++ b/src/libstd/repr.rs @@ -174,12 +174,11 @@ impl MovePtr for ReprVisitor { } } -pub impl ReprVisitor { - +impl ReprVisitor { // Various helpers for the TyVisitor impl #[inline(always)] - fn get(&self, f: &fn(&T)) -> bool { + pub fn get(&self, f: &fn(&T)) -> bool { unsafe { f(transmute::<*c_void,&T>(*self.ptr)); } @@ -187,12 +186,12 @@ pub impl ReprVisitor { } #[inline(always)] - fn visit_inner(&self, inner: *TyDesc) -> bool { + pub fn visit_inner(&self, inner: *TyDesc) -> bool { self.visit_ptr_inner(*self.ptr, inner) } #[inline(always)] - fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool { + pub fn visit_ptr_inner(&self, ptr: *c_void, inner: *TyDesc) -> bool { unsafe { let u = ReprVisitor(ptr, self.writer); let v = reflect::MovePtrAdaptor(u); @@ -202,13 +201,13 @@ pub impl ReprVisitor { } #[inline(always)] - fn write(&self) -> bool { + pub fn write(&self) -> bool { do self.get |v:&T| { v.write_repr(self.writer); } } - fn write_escaped_slice(&self, slice: &str) { + pub fn write_escaped_slice(&self, slice: &str) { self.writer.write_char('"'); for slice.each_char |ch| { self.writer.write_escaped_char(ch); @@ -216,7 +215,7 @@ pub impl ReprVisitor { self.writer.write_char('"'); } - fn write_mut_qualifier(&self, mtbl: uint) { + pub fn write_mut_qualifier(&self, mtbl: uint) { if mtbl == 0 { self.writer.write_str("mut "); } else if mtbl == 1 { @@ -227,8 +226,12 @@ pub impl ReprVisitor { } } - fn write_vec_range(&self, mtbl: uint, ptr: *u8, len: uint, - inner: *TyDesc) -> bool { + pub fn write_vec_range(&self, + mtbl: uint, + ptr: *u8, + len: uint, + inner: *TyDesc) + -> bool { let mut p = ptr; let end = ptr::offset(p, len); let (sz, al) = unsafe { ((*inner).size, (*inner).align) }; @@ -248,13 +251,14 @@ pub impl ReprVisitor { true } - fn write_unboxed_vec_repr(&self, mtbl: uint, v: &UnboxedVecRepr, - inner: *TyDesc) -> bool { + pub 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) } - - } impl TyVisitor for ReprVisitor { diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 5b40b09e98e84..8f7a0015bcf15 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -10,7 +10,7 @@ //! A type representing either success or failure -// NB: transitionary, de-mode-ing. +#[allow(missing_doc)]; use cmp::Eq; use either; @@ -227,55 +227,55 @@ pub fn map_err(res: &Result, op: &fn(&E) -> F) } } -pub impl Result { +impl Result { #[inline(always)] - fn get_ref<'a>(&'a self) -> &'a T { get_ref(self) } + pub fn get_ref<'a>(&'a self) -> &'a T { get_ref(self) } #[inline(always)] - fn is_ok(&self) -> bool { is_ok(self) } + pub fn is_ok(&self) -> bool { is_ok(self) } #[inline(always)] - fn is_err(&self) -> bool { is_err(self) } + pub fn is_err(&self) -> bool { is_err(self) } #[inline(always)] - fn iter(&self, f: &fn(&T)) { iter(self, f) } + pub fn iter(&self, f: &fn(&T)) { iter(self, f) } #[inline(always)] - fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) } + pub fn iter_err(&self, f: &fn(&E)) { iter_err(self, f) } #[inline(always)] - fn unwrap(self) -> T { unwrap(self) } + pub fn unwrap(self) -> T { unwrap(self) } #[inline(always)] - fn unwrap_err(self) -> E { unwrap_err(self) } + pub fn unwrap_err(self) -> E { unwrap_err(self) } #[inline(always)] - fn chain(self, op: &fn(T) -> Result) -> Result { + pub fn chain(self, op: &fn(T) -> Result) -> Result { chain(self, op) } #[inline(always)] - fn chain_err(self, op: &fn(E) -> Result) -> Result { + pub fn chain_err(self, op: &fn(E) -> Result) -> Result { chain_err(self, op) } } -pub impl Result { +impl Result { #[inline(always)] - fn get(&self) -> T { get(self) } + pub fn get(&self) -> T { get(self) } #[inline(always)] - fn map_err(&self, op: &fn(&E) -> F) -> Result { + pub fn map_err(&self, op: &fn(&E) -> F) -> Result { map_err(self, op) } } -pub impl Result { +impl Result { #[inline(always)] - fn get_err(&self) -> E { get_err(self) } + pub fn get_err(&self) -> E { get_err(self) } #[inline(always)] - fn map(&self, op: &fn(&T) -> U) -> Result { + pub fn map(&self, op: &fn(&T) -> U) -> Result { map(self, op) } } diff --git a/src/libstd/rt/context.rs b/src/libstd/rt/context.rs index 0d011ce42bab9..d5ca8473ceeac 100644 --- a/src/libstd/rt/context.rs +++ b/src/libstd/rt/context.rs @@ -27,8 +27,8 @@ pub struct Context { regs: ~Registers } -pub impl Context { - fn empty() -> Context { +impl Context { + pub fn empty() -> Context { Context { start: None, regs: new_regs() @@ -36,7 +36,7 @@ pub impl Context { } /// Create a new context that will resume execution by running ~fn() - fn new(start: ~fn(), stack: &mut StackSegment) -> Context { + pub fn new(start: ~fn(), stack: &mut StackSegment) -> Context { // XXX: Putting main into a ~ so it's a thin pointer and can // be passed to the spawn function. Another unfortunate // allocation @@ -71,7 +71,7 @@ pub impl Context { saving the registers values of the executing thread to a Context then loading the registers from a previously saved Context. */ - fn swap(out_context: &mut Context, in_context: &Context) { + pub fn swap(out_context: &mut Context, in_context: &Context) { let out_regs: &mut Registers = match out_context { &Context { regs: ~ref mut r, _ } => r }; diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 2d9cdaddc8433..064eb63afc627 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -57,11 +57,10 @@ enum CleanupJob { GiveTask(~Coroutine, UnsafeTaskReceiver) } -pub impl Scheduler { +impl Scheduler { + pub fn in_task_context(&self) -> bool { self.current_task.is_some() } - fn in_task_context(&self) -> bool { self.current_task.is_some() } - - fn new(event_loop: ~EventLoopObject) -> Scheduler { + pub fn new(event_loop: ~EventLoopObject) -> Scheduler { // Lazily initialize the runtime TLS key local_ptr::init_tls_key(); @@ -80,7 +79,7 @@ pub impl Scheduler { // the scheduler itself doesn't have to call event_loop.run. // That will be important for embedding the runtime into external // event loops. - fn run(~self) -> ~Scheduler { + pub fn run(~self) -> ~Scheduler { assert!(!self.in_task_context()); let mut self_sched = self; @@ -107,7 +106,7 @@ pub impl Scheduler { /// Pushes the task onto the work stealing queue and tells the event loop /// to run it later. Always use this instead of pushing to the work queue /// directly. - fn enqueue_task(&mut self, task: ~Coroutine) { + pub fn enqueue_task(&mut self, task: ~Coroutine) { self.work_queue.push(task); self.event_loop.callback(resume_task_from_queue); @@ -119,7 +118,7 @@ pub impl Scheduler { // * Scheduler-context operations - fn resume_task_from_queue(~self) { + pub fn resume_task_from_queue(~self) { assert!(!self.in_task_context()); rtdebug!("looking in work queue for task to schedule"); @@ -141,7 +140,7 @@ pub impl Scheduler { /// Called by a running task to end execution, after which it will /// be recycled by the scheduler for reuse in a new task. - fn terminate_current_task(~self) { + pub fn terminate_current_task(~self) { assert!(self.in_task_context()); rtdebug!("ending running task"); @@ -156,7 +155,7 @@ pub impl Scheduler { abort!("control reached end of task"); } - fn schedule_new_task(~self, task: ~Coroutine) { + pub fn schedule_new_task(~self, task: ~Coroutine) { assert!(self.in_task_context()); do self.switch_running_tasks_and_then(task) |last_task| { @@ -167,7 +166,7 @@ pub impl Scheduler { } } - fn schedule_task(~self, task: ~Coroutine) { + pub fn schedule_task(~self, task: ~Coroutine) { assert!(self.in_task_context()); do self.switch_running_tasks_and_then(task) |last_task| { @@ -180,7 +179,7 @@ pub impl Scheduler { // Core scheduling ops - fn resume_task_immediately(~self, task: ~Coroutine) { + pub fn resume_task_immediately(~self, task: ~Coroutine) { let mut this = self; assert!(!this.in_task_context()); @@ -218,7 +217,7 @@ pub impl Scheduler { /// The closure here is a *stack* closure that lives in the /// running task. It gets transmuted to the scheduler's lifetime /// and called while the task is blocked. - fn deschedule_running_task_and_then(~self, f: &fn(~Coroutine)) { + pub fn deschedule_running_task_and_then(~self, f: &fn(~Coroutine)) { let mut this = self; assert!(this.in_task_context()); @@ -248,7 +247,9 @@ pub impl Scheduler { /// Switch directly to another task, without going through the scheduler. /// You would want to think hard about doing this, e.g. if there are /// pending I/O events it would be a bad idea. - fn switch_running_tasks_and_then(~self, next_task: ~Coroutine, f: &fn(~Coroutine)) { + pub fn switch_running_tasks_and_then(~self, + next_task: ~Coroutine, + f: &fn(~Coroutine)) { let mut this = self; assert!(this.in_task_context()); @@ -279,12 +280,12 @@ pub impl Scheduler { // * Other stuff - fn enqueue_cleanup_job(&mut self, job: CleanupJob) { + pub fn enqueue_cleanup_job(&mut self, job: CleanupJob) { assert!(self.cleanup_job.is_none()); self.cleanup_job = Some(job); } - fn run_cleanup_job(&mut self) { + pub fn run_cleanup_job(&mut self) { rtdebug!("running cleanup job"); assert!(self.cleanup_job.is_some()); @@ -305,9 +306,9 @@ pub impl Scheduler { /// callers should first arrange for that task to be located in the /// Scheduler's current_task slot and set up the /// post-context-switch cleanup job. - fn get_contexts<'a>(&'a mut self) -> (&'a mut Context, - Option<&'a mut Context>, - Option<&'a mut Context>) { + pub fn get_contexts<'a>(&'a mut self) -> (&'a mut Context, + Option<&'a mut Context>, + Option<&'a mut Context>) { let last_task = match self.cleanup_job { Some(GiveTask(~ref task, _)) => { Some(task) @@ -349,14 +350,14 @@ pub struct Coroutine { task: ~Task } -pub impl Coroutine { - fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine { +impl Coroutine { + pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine { Coroutine::with_task(stack_pool, ~Task::new(), start) } - fn with_task(stack_pool: &mut StackPool, - task: ~Task, - start: ~fn()) -> Coroutine { + pub fn with_task(stack_pool: &mut StackPool, + task: ~Task, + start: ~fn()) -> Coroutine { let start = Coroutine::build_start_wrapper(start); let mut stack = stack_pool.take_segment(MIN_STACK_SIZE); // NB: Context holds a pointer to that ~fn @@ -368,7 +369,7 @@ pub impl Coroutine { }; } - priv fn build_start_wrapper(start: ~fn()) -> ~fn() { + fn build_start_wrapper(start: ~fn()) -> ~fn() { // XXX: The old code didn't have this extra allocation let wrapper: ~fn() = || { // This is the first code to execute after the initial @@ -391,7 +392,7 @@ pub impl Coroutine { } /// Destroy the task and try to reuse its components - fn recycle(~self, stack_pool: &mut StackPool) { + pub fn recycle(~self, stack_pool: &mut StackPool) { match self { ~Coroutine {current_stack_segment, _} => { stack_pool.give_segment(current_stack_segment); diff --git a/src/libstd/rt/stack.rs b/src/libstd/rt/stack.rs index ec56e65931c81..fa4b8f30f4e76 100644 --- a/src/libstd/rt/stack.rs +++ b/src/libstd/rt/stack.rs @@ -19,8 +19,8 @@ pub struct StackSegment { valgrind_id: c_uint } -pub impl StackSegment { - fn new(size: uint) -> StackSegment { +impl StackSegment { + pub fn new(size: uint) -> StackSegment { unsafe { // Crate a block of uninitialized values let mut stack = vec::with_capacity(size); @@ -38,12 +38,12 @@ pub impl StackSegment { } /// Point to the low end of the allocated stack - fn start(&self) -> *uint { - vec::raw::to_ptr(self.buf) as *uint + pub fn start(&self) -> *uint { + vec::raw::to_ptr(self.buf) as *uint } /// Point one word beyond the high end of the allocated stack - fn end(&self) -> *uint { + pub fn end(&self) -> *uint { vec::raw::to_ptr(self.buf).offset(self.buf.len()) as *uint } } diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index 0f1ae09bd944b..bc29019131078 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -19,8 +19,8 @@ pub struct Thread { raw_thread: *raw_thread } -pub impl Thread { - fn start(main: ~fn()) -> Thread { +impl Thread { + pub fn start(main: ~fn()) -> Thread { fn substart(main: &~fn()) -> *raw_thread { unsafe { rust_raw_thread_start(main) } } diff --git a/src/libstd/rt/uv/idle.rs b/src/libstd/rt/uv/idle.rs index 2cf0b5c487288..e1def9ffd508b 100644 --- a/src/libstd/rt/uv/idle.rs +++ b/src/libstd/rt/uv/idle.rs @@ -17,8 +17,8 @@ use rt::uv::status_to_maybe_uv_error; pub struct IdleWatcher(*uvll::uv_idle_t); impl Watcher for IdleWatcher { } -pub impl IdleWatcher { - fn new(loop_: &mut Loop) -> IdleWatcher { +impl IdleWatcher { + pub fn new(loop_: &mut Loop) -> IdleWatcher { unsafe { let handle = uvll::idle_new(); assert!(handle.is_not_null()); @@ -29,7 +29,7 @@ pub impl IdleWatcher { } } - fn start(&mut self, cb: IdleCallback) { + pub fn start(&mut self, cb: IdleCallback) { { let data = self.get_watcher_data(); data.idle_cb = Some(cb); @@ -48,16 +48,17 @@ pub impl IdleWatcher { } } - fn stop(&mut self) { - // NB: Not resetting the Rust idle_cb to None here because `stop` is likely - // called from *within* the idle callback, causing a use after free + pub fn stop(&mut self) { + // NB: Not resetting the Rust idle_cb to None here because `stop` is + // likely called from *within* the idle callback, causing a use after + // free unsafe { assert!(0 == uvll::idle_stop(self.native_handle())); } } - fn close(self, cb: NullCallback) { + pub fn close(self, cb: NullCallback) { { let mut this = self; let data = this.get_watcher_data(); diff --git a/src/libstd/rt/uv/mod.rs b/src/libstd/rt/uv/mod.rs index 2bd657fd8641f..bc968fc3d6064 100644 --- a/src/libstd/rt/uv/mod.rs +++ b/src/libstd/rt/uv/mod.rs @@ -92,18 +92,18 @@ pub trait NativeHandle { pub fn native_handle(&self) -> T; } -pub impl Loop { - fn new() -> Loop { +impl Loop { + pub fn new() -> Loop { let handle = unsafe { uvll::loop_new() }; assert!(handle.is_not_null()); NativeHandle::from_native_handle(handle) } - fn run(&mut self) { + pub fn run(&mut self) { unsafe { uvll::run(self.native_handle()) }; } - fn close(&mut self) { + pub fn close(&mut self) { unsafe { uvll::loop_delete(self.native_handle()) }; } } @@ -193,9 +193,8 @@ impl> WatcherInterop for W { pub struct UvError(uvll::uv_err_t); -pub impl UvError { - - fn name(&self) -> ~str { +impl UvError { + pub fn name(&self) -> ~str { unsafe { let inner = match self { &UvError(ref a) => a }; let name_str = uvll::err_name(inner); @@ -204,7 +203,7 @@ pub impl UvError { } } - fn desc(&self) -> ~str { + pub fn desc(&self) -> ~str { unsafe { let inner = match self { &UvError(ref a) => a }; let desc_str = uvll::strerror(inner); @@ -213,7 +212,7 @@ pub impl UvError { } } - fn is_eof(&self) -> bool { + pub fn is_eof(&self) -> bool { self.code == uvll::EOF } } diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 68b871e6b3118..563d7fd1e81a1 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -43,9 +43,8 @@ fn ip4_as_uv_ip4(addr: IpAddr, f: &fn(*sockaddr_in) -> T) -> T { pub struct StreamWatcher(*uvll::uv_stream_t); impl Watcher for StreamWatcher { } -pub impl StreamWatcher { - - fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) { +impl StreamWatcher { + pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) { { let data = self.get_watcher_data(); data.alloc_cb = Some(alloc); @@ -73,7 +72,7 @@ pub impl StreamWatcher { } } - fn read_stop(&mut self) { + pub fn read_stop(&mut self) { // It would be nice to drop the alloc and read callbacks here, // but read_stop may be called from inside one of them and we // would end up freeing the in-use environment @@ -81,7 +80,7 @@ pub impl StreamWatcher { unsafe { uvll::read_stop(handle); } } - fn write(&mut self, buf: Buf, cb: ConnectionCallback) { + pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) { { let data = self.get_watcher_data(); assert!(data.write_cb.is_none()); @@ -110,7 +109,7 @@ pub impl StreamWatcher { } } - fn accept(&mut self, stream: StreamWatcher) { + pub fn accept(&mut self, stream: StreamWatcher) { let self_handle = self.native_handle() as *c_void; let stream_handle = stream.native_handle() as *c_void; unsafe { @@ -118,7 +117,7 @@ pub impl StreamWatcher { } } - fn close(self, cb: NullCallback) { + pub fn close(self, cb: NullCallback) { { let mut this = self; let data = this.get_watcher_data(); @@ -153,8 +152,8 @@ impl NativeHandle<*uvll::uv_stream_t> for StreamWatcher { pub struct TcpWatcher(*uvll::uv_tcp_t); impl Watcher for TcpWatcher { } -pub impl TcpWatcher { - fn new(loop_: &mut Loop) -> TcpWatcher { +impl TcpWatcher { + pub fn new(loop_: &mut Loop) -> TcpWatcher { unsafe { let handle = malloc_handle(UV_TCP); assert!(handle.is_not_null()); @@ -165,7 +164,7 @@ pub impl TcpWatcher { } } - fn bind(&mut self, address: IpAddr) -> Result<(), UvError> { + pub fn bind(&mut self, address: IpAddr) -> Result<(), UvError> { match address { Ipv4(*) => { do ip4_as_uv_ip4(address) |addr| { @@ -183,7 +182,7 @@ pub impl TcpWatcher { } } - fn connect(&mut self, address: IpAddr, cb: ConnectionCallback) { + pub fn connect(&mut self, address: IpAddr, cb: ConnectionCallback) { unsafe { assert!(self.get_watcher_data().connect_cb.is_none()); self.get_watcher_data().connect_cb = Some(cb); @@ -216,7 +215,7 @@ pub impl TcpWatcher { } } - fn listen(&mut self, cb: ConnectionCallback) { + pub fn listen(&mut self, cb: ConnectionCallback) { { let data = self.get_watcher_data(); assert!(data.connect_cb.is_none()); @@ -240,7 +239,7 @@ pub impl TcpWatcher { } } - fn as_stream(&self) -> StreamWatcher { + pub fn as_stream(&self) -> StreamWatcher { NativeHandle::from_native_handle(self.native_handle() as *uvll::uv_stream_t) } } @@ -295,9 +294,8 @@ pub struct WriteRequest(*uvll::uv_write_t); impl Request for WriteRequest { } -pub impl WriteRequest { - - fn new() -> WriteRequest { +impl WriteRequest { + pub fn new() -> WriteRequest { let write_handle = unsafe { malloc_req(UV_WRITE) }; @@ -306,14 +304,14 @@ pub impl WriteRequest { WriteRequest(write_handle) } - fn stream(&self) -> StreamWatcher { + pub fn stream(&self) -> StreamWatcher { unsafe { let stream_handle = uvll::get_stream_handle_from_write_req(self.native_handle()); NativeHandle::from_native_handle(stream_handle) } } - fn delete(self) { + pub fn delete(self) { unsafe { free_req(self.native_handle() as *c_void) } } } diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index cacd67314ebac..1d4f65f1517f6 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -33,15 +33,15 @@ pub struct UvEventLoop { uvio: UvIoFactory } -pub impl UvEventLoop { - fn new() -> UvEventLoop { +impl UvEventLoop { + pub fn new() -> UvEventLoop { UvEventLoop { uvio: UvIoFactory(Loop::new()) } } /// A convenience constructor - fn new_scheduler() -> Scheduler { + pub fn new_scheduler() -> Scheduler { Scheduler::new(~UvEventLoop::new()) } } @@ -57,7 +57,6 @@ impl Drop for UvEventLoop { } impl EventLoop for UvEventLoop { - fn run(&mut self) { self.uvio.uv_loop().run(); } @@ -103,8 +102,8 @@ fn test_callback_run_once() { pub struct UvIoFactory(Loop); -pub impl UvIoFactory { - fn uv_loop<'a>(&'a mut self) -> &'a mut Loop { +impl UvIoFactory { + pub fn uv_loop<'a>(&'a mut self) -> &'a mut Loop { match self { &UvIoFactory(ref mut ptr) => ptr } } } diff --git a/src/libstd/rt/uvio.rs b/src/libstd/rt/uvio.rs index 24bffd8d1cd24..c7467364b4d9d 100644 --- a/src/libstd/rt/uvio.rs +++ b/src/libstd/rt/uvio.rs @@ -29,15 +29,15 @@ pub struct UvEventLoop { uvio: UvIoFactory } -pub impl UvEventLoop { - fn new() -> UvEventLoop { +impl UvEventLoop { + pub fn new() -> UvEventLoop { UvEventLoop { uvio: UvIoFactory(Loop::new()) } } /// A convenience constructor - fn new_scheduler() -> Scheduler { + pub fn new_scheduler() -> Scheduler { Scheduler::new(~UvEventLoop::new()) } } @@ -90,8 +90,8 @@ fn test_callback_run_once() { pub struct UvIoFactory(Loop); -pub impl UvIoFactory { - fn uv_loop<'a>(&'a mut self) -> &'a mut Loop { +impl UvIoFactory { + pub fn uv_loop<'a>(&'a mut self) -> &'a mut Loop { match self { &UvIoFactory(ref mut ptr) => ptr } } } diff --git a/src/libstd/rt/work_queue.rs b/src/libstd/rt/work_queue.rs index 4671a45aaea3a..58d36113f0e35 100644 --- a/src/libstd/rt/work_queue.rs +++ b/src/libstd/rt/work_queue.rs @@ -21,21 +21,21 @@ pub struct WorkQueue { priv queue: ~Exclusive<~[T]> } -pub impl WorkQueue { - fn new() -> WorkQueue { +impl WorkQueue { + pub fn new() -> WorkQueue { WorkQueue { queue: ~exclusive(~[]) } } - fn push(&mut self, value: T) { + pub fn push(&mut self, value: T) { unsafe { let value = Cell(value); self.queue.with(|q| q.unshift(value.take()) ); } } - fn pop(&mut self) -> Option { + pub fn pop(&mut self) -> Option { unsafe { do self.queue.with |q| { if !q.is_empty() { @@ -47,7 +47,7 @@ pub impl WorkQueue { } } - fn steal(&mut self) -> Option { + pub fn steal(&mut self) -> Option { unsafe { do self.queue.with |q| { if !q.is_empty() { @@ -59,7 +59,7 @@ pub impl WorkQueue { } } - fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { unsafe { self.queue.with_imm(|q| q.is_empty() ) } diff --git a/src/libstd/run.rs b/src/libstd/run.rs index de1148e431b84..07b521d019766 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -136,8 +136,7 @@ pub struct ProcessOutput { error: ~[u8], } -pub impl Process { - +impl Process { /** * Spawns a new Process. * @@ -148,8 +147,8 @@ pub impl Process { * * options - Options to configure the environment of the process, * the working directory and the standard IO streams. */ - pub fn new(prog: &str, args: &[~str], options: ProcessOptions) -> Process { - + pub fn new(prog: &str, args: &[~str], options: ProcessOptions) + -> Process { let (in_pipe, in_fd) = match options.in_fd { None => { let pipe = os::pipe(); @@ -192,9 +191,9 @@ pub impl Process { } /// Returns the unique id of the process - fn get_id(&self) -> pid_t { self.pid } + pub fn get_id(&self) -> pid_t { self.pid } - priv fn input_fd(&mut self) -> c_int { + fn input_fd(&mut self) -> c_int { match self.input { Some(fd) => fd, None => fail!("This Process's stdin was redirected to an \ @@ -202,7 +201,7 @@ pub impl Process { } } - priv fn output_file(&mut self) -> *libc::FILE { + fn output_file(&mut self) -> *libc::FILE { match self.output { Some(file) => file, None => fail!("This Process's stdout was redirected to an \ @@ -210,7 +209,7 @@ pub impl Process { } } - priv fn error_file(&mut self) -> *libc::FILE { + fn error_file(&mut self) -> *libc::FILE { match self.error { Some(file) => file, None => fail!("This Process's stderr was redirected to an \ @@ -225,7 +224,7 @@ pub impl Process { * * If this method returns true then self.input() will fail. */ - fn input_redirected(&self) -> bool { + pub fn input_redirected(&self) -> bool { self.input.is_none() } @@ -236,7 +235,7 @@ pub impl Process { * * If this method returns true then self.output() will fail. */ - fn output_redirected(&self) -> bool { + pub fn output_redirected(&self) -> bool { self.output.is_none() } @@ -247,7 +246,7 @@ pub impl Process { * * If this method returns true then self.error() will fail. */ - fn error_redirected(&self) -> bool { + pub fn error_redirected(&self) -> bool { self.error.is_none() } @@ -256,7 +255,7 @@ pub impl Process { * * Fails if this Process's stdin was redirected to an existing file descriptor. */ - fn input(&mut self) -> @io::Writer { + pub fn input(&mut self) -> @io::Writer { // FIXME: the Writer can still be used after self is destroyed: #2625 io::fd_writer(self.input_fd(), false) } @@ -266,7 +265,7 @@ pub impl Process { * * Fails if this Process's stdout was redirected to an existing file descriptor. */ - fn output(&mut self) -> @io::Reader { + pub fn output(&mut self) -> @io::Reader { // FIXME: the Reader can still be used after self is destroyed: #2625 io::FILE_reader(self.output_file(), false) } @@ -276,7 +275,7 @@ pub impl Process { * * Fails if this Process's stderr was redirected to an existing file descriptor. */ - fn error(&mut self) -> @io::Reader { + pub fn error(&mut self) -> @io::Reader { // FIXME: the Reader can still be used after self is destroyed: #2625 io::FILE_reader(self.error_file(), false) } @@ -287,7 +286,7 @@ pub impl Process { * If this process is reading its stdin from an existing file descriptor, then this * method does nothing. */ - fn close_input(&mut self) { + pub fn close_input(&mut self) { match self.input { Some(-1) | None => (), Some(fd) => { @@ -299,7 +298,7 @@ pub impl Process { } } - priv fn close_outputs(&mut self) { + fn close_outputs(&mut self) { fclose_and_null(&mut self.output); fclose_and_null(&mut self.error); @@ -322,7 +321,7 @@ pub impl Process { * * If the child has already been finished then the exit code is returned. */ - fn finish(&mut self) -> int { + pub fn finish(&mut self) -> int { for self.exit_code.each |&code| { return code; } @@ -342,8 +341,7 @@ pub impl Process { * This method will fail if the child process's stdout or stderr streams were * redirected to existing file descriptors. */ - fn finish_with_output(&mut self) -> ProcessOutput { - + pub fn finish_with_output(&mut self) -> ProcessOutput { let output_file = self.output_file(); let error_file = self.error_file(); @@ -378,8 +376,7 @@ pub impl Process { error: errs}; } - priv fn destroy_internal(&mut self, force: bool) { - + fn destroy_internal(&mut self, force: bool) { // if the process has finished, and therefore had waitpid called, // and we kill it, then on unix we might ending up killing a // newer process that happens to have the same (re-used) id @@ -417,7 +414,7 @@ pub impl Process { * On Posix OSs SIGTERM will be sent to the process. On Win32 * TerminateProcess(..) will be called. */ - fn destroy(&mut self) { self.destroy_internal(false); } + pub fn destroy(&mut self) { self.destroy_internal(false); } /** * Terminates the process as soon as possible without giving it a @@ -426,7 +423,7 @@ pub impl Process { * On Posix OSs SIGKILL will be sent to the process. On Win32 * TerminateProcess(..) will be called. */ - fn force_destroy(&mut self) { self.destroy_internal(true); } + pub fn force_destroy(&mut self) { self.destroy_internal(true); } } impl Drop for Process { diff --git a/src/libstd/str/ascii.rs b/src/libstd/str/ascii.rs index e48fef01df941..3b31d70f7a1bd 100644 --- a/src/libstd/str/ascii.rs +++ b/src/libstd/str/ascii.rs @@ -21,22 +21,22 @@ use vec::{CopyableVector, ImmutableVector, OwnedVector}; #[deriving(Clone, Eq)] pub struct Ascii { priv chr: u8 } -pub impl Ascii { +impl Ascii { /// Converts a ascii character into a `u8`. #[inline(always)] - fn to_byte(self) -> u8 { + pub fn to_byte(self) -> u8 { self.chr } /// Converts a ascii character into a `char`. #[inline(always)] - fn to_char(self) -> char { + pub fn to_char(self) -> char { self.chr as char } /// Convert to lowercase. #[inline(always)] - fn to_lower(self) -> Ascii { + pub fn to_lower(self) -> Ascii { if self.chr >= 65 && self.chr <= 90 { Ascii{chr: self.chr | 0x20 } } else { @@ -46,7 +46,7 @@ pub impl Ascii { /// Convert to uppercase. #[inline(always)] - fn to_upper(self) -> Ascii { + pub fn to_upper(self) -> Ascii { if self.chr >= 97 && self.chr <= 122 { Ascii{chr: self.chr & !0x20 } } else { @@ -54,9 +54,9 @@ pub impl Ascii { } } - // Compares two ascii characters of equality, ignoring case. + /// Compares two ascii characters of equality, ignoring case. #[inline(always)] - fn eq_ignore_case(self, other: Ascii) -> bool { + pub fn eq_ignore_case(self, other: Ascii) -> bool { self.to_lower().chr == other.to_lower().chr } } diff --git a/src/libstd/task/mod.rs b/src/libstd/task/mod.rs index b68abca860520..7c9639bb8f3cb 100644 --- a/src/libstd/task/mod.rs +++ b/src/libstd/task/mod.rs @@ -202,7 +202,7 @@ pub fn task() -> TaskBuilder { } } -priv impl TaskBuilder { +impl TaskBuilder { fn consume(&mut self) -> TaskBuilder { if self.consumed { fail!("Cannot copy a task_builder"); // Fake move mode on self @@ -224,24 +224,24 @@ priv impl TaskBuilder { } } -pub impl TaskBuilder { +impl TaskBuilder { /// Decouple the child task's failure from the parent's. If either fails, /// the other will not be killed. - fn unlinked(&mut self) { + pub fn unlinked(&mut self) { self.opts.linked = false; } /// Unidirectionally link the child task's failure with the parent's. The /// child's failure will not kill the parent, but the parent's will kill /// the child. - fn supervised(&mut self) { + pub fn supervised(&mut self) { self.opts.supervised = true; self.opts.linked = false; } /// Link the child task's and parent task's failures. If either fails, the /// other will be killed. - fn linked(&mut self) { + pub fn linked(&mut self) { self.opts.linked = true; self.opts.supervised = false; } @@ -263,7 +263,7 @@ pub impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - fn future_result(&mut self, blk: &fn(v: Port)) { + pub fn future_result(&mut self, blk: &fn(v: Port)) { // 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 @@ -283,7 +283,7 @@ pub impl TaskBuilder { } /// Configure a custom scheduler mode for the task. - fn sched_mode(&mut self, mode: SchedMode) { + pub fn sched_mode(&mut self, mode: SchedMode) { self.opts.sched.mode = mode; } @@ -299,7 +299,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(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) { + pub fn add_wrapper(&mut self, wrapper: ~fn(v: ~fn()) -> ~fn()) { let prev_gen_body = replace(&mut self.gen_body, None); let prev_gen_body = match prev_gen_body { Some(gen) => gen, @@ -331,7 +331,7 @@ pub impl TaskBuilder { * When spawning into a new scheduler, the number of threads requested * must be greater than zero. */ - fn spawn(&mut self, f: ~fn()) { + pub fn spawn(&mut self, f: ~fn()) { let gen_body = replace(&mut self.gen_body, None); let notify_chan = replace(&mut self.opts.notify_chan, None); let x = self.consume(); @@ -353,7 +353,7 @@ pub impl TaskBuilder { } /// Runs a task, while transfering ownership of one argument to the child. - fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { + pub fn spawn_with(&mut self, arg: A, f: ~fn(v: A)) { let arg = Cell(arg); do self.spawn { f(arg.take()); @@ -373,7 +373,7 @@ pub impl TaskBuilder { * # Failure * Fails if a future_result was already set for this task. */ - fn try(&mut self, f: ~fn() -> T) -> Result { + pub fn try(&mut self, f: ~fn() -> T) -> Result { let (po, ch) = stream::(); let mut result = None; diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index e5b1385974e23..aea03b437ca13 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -145,28 +145,28 @@ impl Map for TrieMap { } } -pub impl TrieMap { +impl TrieMap { /// Create an empty TrieMap #[inline(always)] - fn new() -> TrieMap { + pub fn new() -> TrieMap { TrieMap{root: TrieNode::new(), length: 0} } /// Visit all key-value pairs in reverse order #[inline(always)] - fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { + pub fn each_reverse<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { self.root.each_reverse(f) } /// Visit all keys in reverse order #[inline(always)] - fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool { + pub fn each_key_reverse(&self, f: &fn(&uint) -> bool) -> bool { self.each_reverse(|k, _| f(k)) } /// Visit all values in reverse order #[inline(always)] - fn each_value_reverse(&self, f: &fn(&T) -> bool) -> bool { + pub fn each_value_reverse(&self, f: &fn(&T) -> bool) -> bool { self.each_reverse(|_, v| f(v)) } } @@ -208,28 +208,32 @@ impl Mutable for TrieSet { fn clear(&mut self) { self.map.clear() } } -pub impl TrieSet { +impl TrieSet { /// Create an empty TrieSet #[inline(always)] - fn new() -> TrieSet { + pub fn new() -> TrieSet { TrieSet{map: TrieMap::new()} } /// Return true if the set contains a value #[inline(always)] - fn contains(&self, value: &uint) -> bool { + pub fn contains(&self, value: &uint) -> bool { self.map.contains_key(value) } /// Add a value to the set. Return true if the value was not already /// present in the set. #[inline(always)] - fn insert(&mut self, value: uint) -> bool { self.map.insert(value, ()) } + pub fn insert(&mut self, value: uint) -> bool { + self.map.insert(value, ()) + } /// Remove a value from the set. Return true if the value was /// present in the set. #[inline(always)] - fn remove(&mut self, value: &uint) -> bool { self.map.remove(value) } + pub fn remove(&mut self, value: &uint) -> bool { + self.map.remove(value) + } } struct TrieNode { diff --git a/src/libstd/unstable/extfmt.rs b/src/libstd/unstable/extfmt.rs index 8da378fdc97ce..07bcf6d953c3a 100644 --- a/src/libstd/unstable/extfmt.rs +++ b/src/libstd/unstable/extfmt.rs @@ -139,8 +139,8 @@ pub mod ct { next: uint } - pub impl Parsed { - fn new(val: T, next: uint) -> Parsed { + impl Parsed { + pub fn new(val: T, next: uint) -> Parsed { Parsed {val: val, next: next} } } diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index bee317a0b930e..f0b178c667013 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -117,9 +117,9 @@ fn LittleLock() -> LittleLock { } } -pub impl LittleLock { +impl LittleLock { #[inline(always)] - unsafe fn lock(&self, f: &fn() -> T) -> T { + pub unsafe fn lock(&self, f: &fn() -> T) -> T { do atomically { rust_lock_little_lock(self.l); do (|| { @@ -162,7 +162,7 @@ impl Clone for Exclusive { } } -pub impl Exclusive { +impl Exclusive { // Exactly like std::arc::mutex_arc,access(), but with the little_lock // instead of a proper mutex. Same reason for being unsafe. // @@ -170,7 +170,7 @@ pub impl Exclusive { // accessing the provided condition variable) are prohibited while inside // the exclusive. Supporting that is a work in progress. #[inline(always)] - unsafe fn with(&self, f: &fn(x: &mut T) -> U) -> U { + pub unsafe fn with(&self, f: &fn(x: &mut T) -> U) -> U { let rec = self.x.get(); do (*rec).lock.lock { if (*rec).failed { @@ -184,7 +184,7 @@ pub impl Exclusive { } #[inline(always)] - unsafe fn with_imm(&self, f: &fn(x: &T) -> U) -> U { + pub unsafe fn with_imm(&self, f: &fn(x: &T) -> U) -> U { do self.with |x| { f(cast::transmute_immut(x)) } diff --git a/src/libstd/util.rs b/src/libstd/util.rs index 21fbe2836cd68..e8e68ddd632e6 100644 --- a/src/libstd/util.rs +++ b/src/libstd/util.rs @@ -90,9 +90,9 @@ pub fn NonCopyable() -> NonCopyable { NonCopyable { i: () } } /// A type with no inhabitants pub enum Void { } -pub impl Void { +impl Void { /// A utility function for ignoring this uninhabited type - fn uninhabited(self) -> ! { + pub fn uninhabited(self) -> ! { match self { // Nothing to match on } diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 2b8d8cb3d31db..75439dfaa786c 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -109,18 +109,18 @@ pub fn all_names() -> ~[&'static str] { AbiDatas.map(|d| d.name) } -pub impl Abi { +impl Abi { #[inline] - fn index(&self) -> uint { + pub fn index(&self) -> uint { *self as uint } #[inline] - fn data(&self) -> &'static AbiData { + pub fn data(&self) -> &'static AbiData { &AbiDatas[self.index()] } - fn name(&self) -> &'static str { + pub fn name(&self) -> &'static str { self.data().name } } @@ -131,70 +131,70 @@ impl Architecture { } } -pub impl AbiSet { - fn from(abi: Abi) -> AbiSet { +impl AbiSet { + pub fn from(abi: Abi) -> AbiSet { AbiSet { bits: (1 << abi.index()) } } #[inline] - fn Rust() -> AbiSet { + pub fn Rust() -> AbiSet { AbiSet::from(Rust) } #[inline] - fn C() -> AbiSet { + pub fn C() -> AbiSet { AbiSet::from(C) } #[inline] - fn Intrinsic() -> AbiSet { + pub fn Intrinsic() -> AbiSet { AbiSet::from(RustIntrinsic) } - fn default() -> AbiSet { + pub fn default() -> AbiSet { AbiSet::C() } - fn empty() -> AbiSet { + pub fn empty() -> AbiSet { AbiSet { bits: 0 } } #[inline] - fn is_rust(&self) -> bool { + pub fn is_rust(&self) -> bool { self.bits == 1 << Rust.index() } #[inline] - fn is_c(&self) -> bool { + pub fn is_c(&self) -> bool { self.bits == 1 << C.index() } #[inline] - fn is_intrinsic(&self) -> bool { + pub fn is_intrinsic(&self) -> bool { self.bits == 1 << RustIntrinsic.index() } - fn contains(&self, abi: Abi) -> bool { + pub fn contains(&self, abi: Abi) -> bool { (self.bits & (1 << abi.index())) != 0 } - fn subset_of(&self, other_abi_set: AbiSet) -> bool { + pub fn subset_of(&self, other_abi_set: AbiSet) -> bool { (self.bits & other_abi_set.bits) == self.bits } - fn add(&mut self, abi: Abi) { + pub fn add(&mut self, abi: Abi) { self.bits |= (1 << abi.index()); } - fn each(&self, op: &fn(abi: Abi) -> bool) -> bool { + pub fn each(&self, op: &fn(abi: Abi) -> bool) -> bool { each_abi(|abi| !self.contains(abi) || op(abi)) } - fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.bits == 0 } - fn for_arch(&self, arch: Architecture) -> Option { + pub fn for_arch(&self, arch: Architecture) -> Option { // NB---Single platform ABIs come first for self.each |abi| { let data = abi.data(); @@ -208,7 +208,7 @@ pub impl AbiSet { None } - fn check_valid(&self) -> Option<(Abi, Abi)> { + pub fn check_valid(&self) -> Option<(Abi, Abi)> { let mut abis = ~[]; for self.each |abi| { abis.push(abi); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 676a57e38daa3..ac9734ebaa3bf 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -166,14 +166,14 @@ pub struct Generics { ty_params: OptVec } -pub impl Generics { - fn is_parameterized(&self) -> bool { +impl Generics { + pub fn is_parameterized(&self) -> bool { self.lifetimes.len() + self.ty_params.len() > 0 } - fn is_lt_parameterized(&self) -> bool { + pub fn is_lt_parameterized(&self) -> bool { self.lifetimes.len() > 0 } - fn is_type_parameterized(&self) -> bool { + pub fn is_type_parameterized(&self) -> bool { self.ty_params.len() > 0 } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index deff6dc5ba966..4da2d500dd847 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -373,17 +373,19 @@ pub struct id_range { max: node_id, } -pub impl id_range { - fn max() -> id_range { - id_range {min: int::max_value, - max: int::min_value} +impl id_range { + pub fn max() -> id_range { + id_range { + min: int::max_value, + max: int::min_value, + } } - fn empty(&self) -> bool { + pub fn empty(&self) -> bool { self.min >= self.max } - fn add(&mut self, id: node_id) { + pub fn add(&mut self, id: node_id) { self.min = int::min(self.min, id); self.max = int::max(self.max, id + 1); } diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index aedf30127ad49..5f8d6e73cefab 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -271,13 +271,13 @@ pub struct FileMap { multibyte_chars: @mut ~[MultiByteChar], } -pub impl FileMap { +impl FileMap { // EFFECT: register a start-of-line offset in the // table of line-beginnings. // UNCHECKED INVARIANT: these offsets must be added in the right // order and must be in the right places; there is shared knowledge // about what ends a line between this file and parse.rs - fn next_line(&self, pos: BytePos) { + pub fn next_line(&self, pos: BytePos) { // the new charpos must be > the last one (or it's the first one). let lines = &mut *self.lines; assert!((lines.len() == 0) || (lines[lines.len() - 1] < pos)) @@ -309,7 +309,7 @@ pub struct CodeMap { files: @mut ~[@FileMap] } -pub impl CodeMap { +impl CodeMap { pub fn new() -> CodeMap { CodeMap { files: @mut ~[], @@ -317,16 +317,15 @@ pub impl CodeMap { } /// Add a new FileMap to the CodeMap and return it - fn new_filemap(&self, filename: FileName, src: @~str) -> @FileMap { + pub fn new_filemap(&self, filename: FileName, src: @~str) -> @FileMap { return self.new_filemap_w_substr(filename, FssNone, src); } - fn new_filemap_w_substr( - &self, - filename: FileName, - substr: FileSubstr, - src: @~str - ) -> @FileMap { + pub fn new_filemap_w_substr(&self, + filename: FileName, + substr: FileSubstr, + src: @~str) + -> @FileMap { let files = &mut *self.files; let start_pos = if files.len() == 0 { 0 @@ -359,8 +358,7 @@ pub impl CodeMap { return self.lookup_pos(pos); } - pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt - { + pub fn lookup_char_pos_adj(&self, pos: BytePos) -> LocWithOpt { let loc = self.lookup_char_pos(pos); match (loc.file.substr) { FssNone => @@ -430,11 +428,9 @@ pub impl CodeMap { // (or expected function, found _|_) fail!(); // ("asking for " + filename + " which we don't know about"); } - } -priv impl CodeMap { - +impl CodeMap { fn lookup_filemap_idx(&self, pos: BytePos) -> uint { let files = &*self.files; let len = files.len(); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index a9b12c16b3118..5fae6ff3c18b0 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -219,8 +219,9 @@ pub struct ExtCtxt { trace_mac: @mut bool } -pub impl ExtCtxt { - fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) -> @ExtCtxt { +impl ExtCtxt { + pub fn new(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg) + -> @ExtCtxt { @ExtCtxt { parse_sess: parse_sess, cfg: cfg, @@ -230,21 +231,21 @@ pub impl ExtCtxt { } } - fn codemap(&self) -> @CodeMap { self.parse_sess.cm } - fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } - fn cfg(&self) -> ast::crate_cfg { copy self.cfg } - fn call_site(&self) -> span { + pub fn codemap(&self) -> @CodeMap { self.parse_sess.cm } + pub fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess } + pub fn cfg(&self) -> ast::crate_cfg { copy self.cfg } + pub fn call_site(&self) -> span { match *self.backtrace { Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs, None => self.bug("missing top span") } } - fn print_backtrace(&self) { } - fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace } - fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); } - fn mod_pop(&self) { self.mod_path.pop(); } - fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path } - fn bt_push(&self, ei: codemap::ExpnInfo) { + pub fn print_backtrace(&self) { } + pub fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace } + pub fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); } + pub fn mod_pop(&self) { self.mod_path.pop(); } + pub fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path } + pub fn bt_push(&self, ei: codemap::ExpnInfo) { match ei { ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => { *self.backtrace = @@ -255,7 +256,7 @@ pub impl ExtCtxt { } } } - fn bt_pop(&self) { + pub fn bt_pop(&self) { match *self.backtrace { Some(@ExpandedFrom( CallInfo { @@ -266,43 +267,43 @@ pub impl ExtCtxt { _ => self.bug("tried to pop without a push") } } - fn span_fatal(&self, sp: span, msg: &str) -> ! { + pub fn span_fatal(&self, sp: span, msg: &str) -> ! { self.print_backtrace(); self.parse_sess.span_diagnostic.span_fatal(sp, msg); } - fn span_err(&self, sp: span, msg: &str) { + pub fn span_err(&self, sp: span, msg: &str) { self.print_backtrace(); self.parse_sess.span_diagnostic.span_err(sp, msg); } - fn span_warn(&self, sp: span, msg: &str) { + pub fn span_warn(&self, sp: span, msg: &str) { self.print_backtrace(); self.parse_sess.span_diagnostic.span_warn(sp, msg); } - fn span_unimpl(&self, sp: span, msg: &str) -> ! { + pub fn span_unimpl(&self, sp: span, msg: &str) -> ! { self.print_backtrace(); self.parse_sess.span_diagnostic.span_unimpl(sp, msg); } - fn span_bug(&self, sp: span, msg: &str) -> ! { + pub fn span_bug(&self, sp: span, msg: &str) -> ! { self.print_backtrace(); self.parse_sess.span_diagnostic.span_bug(sp, msg); } - fn bug(&self, msg: &str) -> ! { + pub fn bug(&self, msg: &str) -> ! { self.print_backtrace(); self.parse_sess.span_diagnostic.handler().bug(msg); } - fn next_id(&self) -> ast::node_id { + pub fn next_id(&self) -> ast::node_id { parse::next_node_id(self.parse_sess) } - fn trace_macros(&self) -> bool { + pub fn trace_macros(&self) -> bool { *self.trace_mac } - fn set_trace_macros(&self, x: bool) { + pub fn set_trace_macros(&self, x: bool) { *self.trace_mac = x } - fn str_of(&self, id: ast::ident) -> ~str { + pub fn str_of(&self, id: ast::ident) -> ~str { copy *self.parse_sess.interner.get(id) } - fn ident_of(&self, st: &str) -> ast::ident { + pub fn ident_of(&self, st: &str) -> ast::ident { self.parse_sess.interner.intern(st) } } @@ -436,7 +437,7 @@ impl MapChain{ } // traits just don't work anywhere...? -//pub impl Map for MapChain { +//impl Map for MapChain { fn contains_key (&self, key: &K) -> bool { match *self { diff --git a/src/libsyntax/ext/deriving/ty.rs b/src/libsyntax/ext/deriving/ty.rs index f8f7dc8db5fd6..3b39cb691a629 100644 --- a/src/libsyntax/ext/deriving/ty.rs +++ b/src/libsyntax/ext/deriving/ty.rs @@ -38,15 +38,18 @@ pub struct Path<'self> { global: bool } -pub impl<'self> Path<'self> { - fn new<'r>(path: ~[&'r str]) -> Path<'r> { +impl<'self> Path<'self> { + pub fn new<'r>(path: ~[&'r str]) -> Path<'r> { Path::new_(path, None, ~[], true) } - fn new_local<'r>(path: &'r str) -> Path<'r> { + pub fn new_local<'r>(path: &'r str) -> Path<'r> { Path::new_(~[ path ], None, ~[], false) } - fn new_<'r>(path: ~[&'r str], lifetime: Option<&'r str>, params: ~[~Ty<'r>], global: bool) - -> Path<'r> { + pub fn new_<'r>(path: ~[&'r str], + lifetime: Option<&'r str>, + params: ~[~Ty<'r>], + global: bool) + -> Path<'r> { Path { path: path, lifetime: lifetime, @@ -55,13 +58,21 @@ pub impl<'self> Path<'self> { } } - fn to_ty(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> @ast::Ty { + pub fn to_ty(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> @ast::Ty { cx.ty_path(self.to_path(cx, span, self_ty, self_generics)) } - fn to_path(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> @ast::Path { + pub fn to_path(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> @ast::Path { let idents = self.path.map(|s| cx.ident_of(*s) ); let lt = mk_lifetime(cx, span, &self.lifetime); let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics)); @@ -108,9 +119,13 @@ fn mk_lifetime(cx: @ExtCtxt, span: span, lt: &Option<&str>) -> Option<@ast::Life } } -pub impl<'self> Ty<'self> { - fn to_ty(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> @ast::Ty { +impl<'self> Ty<'self> { + pub fn to_ty(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> @ast::Ty { match *self { Ptr(ref ty, ref ptr) => { let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); @@ -143,8 +158,12 @@ pub impl<'self> Ty<'self> { } } - fn to_path(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> @ast::Path { + pub fn to_path(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> @ast::Path { match *self { Self => { let self_params = do self_generics.ty_params.map |ty_param| { @@ -192,14 +211,18 @@ pub struct LifetimeBounds<'self> { bounds: ~[(&'self str, ~[Path<'self>])] } -pub impl<'self> LifetimeBounds<'self> { - fn empty() -> LifetimeBounds<'static> { +impl<'self> LifetimeBounds<'self> { + pub fn empty() -> LifetimeBounds<'static> { LifetimeBounds { lifetimes: ~[], bounds: ~[] } } - fn to_generics(&self, cx: @ExtCtxt, span: span, - self_ty: ident, self_generics: &Generics) -> Generics { + pub fn to_generics(&self, + cx: @ExtCtxt, + span: span, + self_ty: ident, + self_generics: &Generics) + -> Generics { let lifetimes = do self.lifetimes.map |lt| { cx.lifetime(span, cx.ident_of(*lt)) }; diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs index 80e4520b09419..0eb0f5c615927 100644 --- a/src/libsyntax/ext/pipes/proto.rs +++ b/src/libsyntax/ext/pipes/proto.rs @@ -28,8 +28,8 @@ impl ToStr for direction { } } -pub impl direction { - fn reverse(&self) -> direction { +impl direction { + pub fn reverse(&self) -> direction { match *self { send => recv, recv => send @@ -45,21 +45,21 @@ pub struct next_state { // name, span, data, current state, next state pub struct message(~str, span, ~[@ast::Ty], state, Option); -pub impl message { - fn name(&mut self) -> ~str { +impl message { + pub fn name(&mut self) -> ~str { match *self { message(ref id, _, _, _, _) => copy *id } } - fn span(&mut self) -> span { + pub fn span(&mut self) -> span { match *self { message(_, span, _, _, _) => span } } /// Return the type parameters actually used by this message - fn get_generics(&self) -> ast::Generics { + pub fn get_generics(&self) -> ast::Generics { match *self { message(_, _, _, this, _) => copy this.generics } @@ -79,23 +79,26 @@ pub struct state_ { proto: protocol } -pub impl state_ { - fn add_message(@self, name: ~str, span: span, - data: ~[@ast::Ty], next: Option) { +impl state_ { + pub fn add_message(@self, + name: ~str, + span: span, + data: ~[@ast::Ty], + next: Option) { self.messages.push(message(name, span, data, self, next)); } - fn filename(&self) -> ~str { + pub fn filename(&self) -> ~str { self.proto.filename() } - fn data_name(&self) -> ast::ident { + pub fn data_name(&self) -> ast::ident { self.ident } /// Returns the type that is used for the messages. - fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty { + pub fn to_ty(&self, cx: @ExtCtxt) -> @ast::Ty { cx.ty_path (path(~[cx.ident_of(self.name)],self.span).add_tys( cx.ty_vars(&self.generics.ty_params))) @@ -103,7 +106,7 @@ pub impl state_ { /// Iterate over the states that can be reached in one message /// from this state. - fn reachable(&self, f: &fn(state) -> bool) -> bool { + pub fn reachable(&self, f: &fn(state) -> bool) -> bool { for self.messages.each |m| { match *m { message(_, _, _, _, Some(next_state { state: ref id, _ })) => { @@ -140,28 +143,28 @@ pub struct protocol_ { bounded: Option, } -pub impl protocol_ { +impl protocol_ { /// Get a state. - fn get_state(&self, name: &str) -> state { + pub fn get_state(&self, name: &str) -> state { self.states.find(|i| name == i.name).get() } - fn get_state_by_id(&self, id: uint) -> state { self.states[id] } + pub fn get_state_by_id(&self, id: uint) -> state { self.states[id] } - fn has_state(&self, name: &str) -> bool { + pub fn has_state(&self, name: &str) -> bool { self.states.find(|i| name == i.name).is_some() } - fn filename(&self) -> ~str { + pub fn filename(&self) -> ~str { ~"proto://" + self.name } - fn num_states(&self) -> uint { + pub fn num_states(&self) -> uint { let states = &mut *self.states; states.len() } - fn has_ty_params(&self) -> bool { + pub fn has_ty_params(&self) -> bool { for self.states.each |s| { if s.generics.ty_params.len() > 0 { return true; @@ -169,19 +172,20 @@ pub impl protocol_ { } false } - fn is_bounded(&self) -> bool { + + pub fn is_bounded(&self) -> bool { let bounded = self.bounded.get(); bounded } } -pub impl protocol_ { - fn add_state_poly(@mut self, - name: ~str, - ident: ast::ident, - dir: direction, - generics: ast::Generics) - -> state { +impl protocol_ { + pub fn add_state_poly(@mut self, + name: ~str, + ident: ast::ident, + dir: direction, + generics: ast::Generics) + -> state { let messages = @mut ~[]; let states = &mut *self.states; diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs index bdbe91e4112b7..8a930cf9afd54 100644 --- a/src/libsyntax/parse/common.rs +++ b/src/libsyntax/parse/common.rs @@ -52,18 +52,18 @@ pub fn token_to_str(reader: @reader, token: &token::Token) -> ~str { token::to_str(reader.interner(), token) } -pub impl Parser { +impl Parser { // convert a token to a string using self's reader - fn token_to_str(&self, token: &token::Token) -> ~str { + pub fn token_to_str(&self, token: &token::Token) -> ~str { token::to_str(self.reader.interner(), token) } // convert the current token to a string using self's reader - fn this_token_to_str(&self) -> ~str { + pub fn this_token_to_str(&self) -> ~str { self.token_to_str(self.token) } - fn unexpected_last(&self, t: &token::Token) -> ! { + pub fn unexpected_last(&self, t: &token::Token) -> ! { self.span_fatal( *self.last_span, fmt!( @@ -73,7 +73,7 @@ pub impl Parser { ); } - fn unexpected(&self) -> ! { + pub fn unexpected(&self) -> ! { self.fatal( fmt!( "unexpected token: `%s`", @@ -84,7 +84,7 @@ pub impl Parser { // expect and consume the token t. Signal an error if // the next token is not t. - fn expect(&self, t: &token::Token) { + pub fn expect(&self, t: &token::Token) { if *self.token == *t { self.bump(); } else { @@ -98,7 +98,7 @@ pub impl Parser { } } - fn parse_ident(&self) -> ast::ident { + pub fn parse_ident(&self) -> ast::ident { self.check_strict_keywords(); self.check_reserved_keywords(); match *self.token { @@ -120,7 +120,7 @@ pub impl Parser { } } - fn parse_path_list_ident(&self) -> ast::path_list_ident { + pub fn parse_path_list_ident(&self) -> ast::path_list_ident { let lo = self.span.lo; let ident = self.parse_ident(); let hi = self.last_span.hi; @@ -130,17 +130,17 @@ pub impl Parser { // consume token 'tok' if it exists. Returns true if the given // token was present, false otherwise. - fn eat(&self, tok: &token::Token) -> bool { + pub fn eat(&self, tok: &token::Token) -> bool { return if *self.token == *tok { self.bump(); true } else { false }; } - fn is_keyword(&self, kw: keywords::Keyword) -> bool { + pub fn is_keyword(&self, kw: keywords::Keyword) -> bool { token::is_keyword(kw, self.token) } // if the next token is the given keyword, eat it and return // true. Otherwise, return false. - fn eat_keyword(&self, kw: keywords::Keyword) -> bool { + pub fn eat_keyword(&self, kw: keywords::Keyword) -> bool { let is_kw = match *self.token { token::IDENT(sid, false) => kw.to_ident().repr == sid.repr, _ => false @@ -152,7 +152,7 @@ pub impl Parser { // if the given word is not a keyword, signal an error. // if the next token is not the given word, signal an error. // otherwise, eat it. - fn expect_keyword(&self, kw: keywords::Keyword) { + pub fn expect_keyword(&self, kw: keywords::Keyword) { if !self.eat_keyword(kw) { self.fatal( fmt!( @@ -165,7 +165,7 @@ pub impl Parser { } // signal an error if the given string is a strict keyword - fn check_strict_keywords(&self) { + pub fn check_strict_keywords(&self) { if token::is_strict_keyword(self.token) { self.span_err(*self.last_span, fmt!("found `%s` in ident position", self.this_token_to_str())); @@ -173,7 +173,7 @@ pub impl Parser { } // signal an error if the current token is a reserved keyword - fn check_reserved_keywords(&self) { + pub fn check_reserved_keywords(&self) { if token::is_reserved_keyword(self.token) { self.fatal(fmt!("`%s` is a reserved keyword", self.this_token_to_str())); } @@ -182,7 +182,7 @@ pub impl Parser { // expect and consume a GT. if a >> is seen, replace it // with a single > and continue. If a GT is not seen, // signal an error. - fn expect_gt(&self) { + pub fn expect_gt(&self) { if *self.token == token::GT { self.bump(); } else if *self.token == token::BINOP(token::SHR) { @@ -203,11 +203,10 @@ pub impl Parser { // parse a sequence bracketed by '<' and '>', stopping // before the '>'. - fn parse_seq_to_before_gt( - &self, - sep: Option, - f: &fn(&Parser) -> T - ) -> OptVec { + pub fn parse_seq_to_before_gt(&self, + sep: Option, + f: &fn(&Parser) -> T) + -> OptVec { let mut first = true; let mut v = opt_vec::Empty; while *self.token != token::GT @@ -224,11 +223,10 @@ pub impl Parser { return v; } - fn parse_seq_to_gt( - &self, - sep: Option, - f: &fn(&Parser) -> T - ) -> OptVec { + pub fn parse_seq_to_gt(&self, + sep: Option, + f: &fn(&Parser) -> T) + -> OptVec { let v = self.parse_seq_to_before_gt(sep, f); self.expect_gt(); return v; @@ -237,12 +235,11 @@ pub impl Parser { // parse a sequence, including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - fn parse_seq_to_end( - &self, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T - ) -> ~[T] { + pub fn parse_seq_to_end(&self, + ket: &token::Token, + sep: SeqSep, + f: &fn(&Parser) -> T) + -> ~[T] { let val = self.parse_seq_to_before_end(ket, sep, f); self.bump(); val @@ -251,12 +248,11 @@ pub impl Parser { // parse a sequence, not including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - fn parse_seq_to_before_end( - &self, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T - ) -> ~[T] { + pub fn parse_seq_to_before_end(&self, + ket: &token::Token, + sep: SeqSep, + f: &fn(&Parser) -> T) + -> ~[T] { let mut first: bool = true; let mut v: ~[T] = ~[]; while *self.token != *ket { @@ -276,13 +272,12 @@ pub impl Parser { // parse a sequence, including the closing delimiter. The function // f must consume tokens until reaching the next separator or // closing bracket. - fn parse_unspanned_seq( - &self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T - ) -> ~[T] { + pub fn parse_unspanned_seq(&self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: &fn(&Parser) -> T) + -> ~[T] { self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); self.bump(); @@ -291,13 +286,12 @@ pub impl Parser { // NB: Do not use this function unless you actually plan to place the // spanned list in the AST. - fn parse_seq( - &self, - bra: &token::Token, - ket: &token::Token, - sep: SeqSep, - f: &fn(&Parser) -> T - ) -> spanned<~[T]> { + pub fn parse_seq(&self, + bra: &token::Token, + ket: &token::Token, + sep: SeqSep, + f: &fn(&Parser) -> T) + -> spanned<~[T]> { let lo = self.span.lo; self.expect(bra); let result = self.parse_seq_to_before_end(ket, sep, f); diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index 085d24d7e68b1..f11219f6c9e1e 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -73,9 +73,9 @@ impl to_bytes::IterBytes for ObsoleteSyntax { } } -pub impl Parser { +impl Parser { /// Reports an obsolete syntax non-fatal error. - fn obsolete(&self, sp: span, kind: ObsoleteSyntax) { + pub fn obsolete(&self, sp: span, kind: ObsoleteSyntax) { let (kind_str, desc) = match kind { ObsoleteLowerCaseKindBounds => ( "lower-case kind bounds", @@ -232,13 +232,16 @@ pub impl Parser { // Reports an obsolete syntax non-fatal error, and returns // a placeholder expression - fn obsolete_expr(&self, sp: span, kind: ObsoleteSyntax) -> @expr { + pub fn obsolete_expr(&self, sp: span, kind: ObsoleteSyntax) -> @expr { self.obsolete(sp, kind); self.mk_expr(sp.lo, sp.hi, expr_lit(@respan(sp, lit_nil))) } - priv fn report(&self, sp: span, kind: ObsoleteSyntax, kind_str: &str, - desc: &str) { + fn report(&self, + sp: span, + kind: ObsoleteSyntax, + kind_str: &str, + desc: &str) { self.span_err(sp, fmt!("obsolete syntax: %s", kind_str)); if !self.obsolete_set.contains(&kind) { @@ -247,7 +250,8 @@ pub impl Parser { } } - fn token_is_obsolete_ident(&self, ident: &str, token: &Token) -> bool { + pub fn token_is_obsolete_ident(&self, ident: &str, token: &Token) + -> bool { match *token { token::IDENT(sid, _) => { str::eq_slice(*self.id_to_str(sid), ident) @@ -256,11 +260,11 @@ pub impl Parser { } } - fn is_obsolete_ident(&self, ident: &str) -> bool { + pub fn is_obsolete_ident(&self, ident: &str) -> bool { self.token_is_obsolete_ident(ident, self.token) } - fn eat_obsolete_ident(&self, ident: &str) -> bool { + pub fn eat_obsolete_ident(&self, ident: &str) -> bool { if self.is_obsolete_ident(ident) { self.bump(); true @@ -269,7 +273,7 @@ pub impl Parser { } } - fn try_parse_obsolete_struct_ctor(&self) -> bool { + pub fn try_parse_obsolete_struct_ctor(&self) -> bool { if self.eat_obsolete_ident("new") { self.obsolete(*self.last_span, ObsoleteStructCtor); self.parse_fn_decl(); @@ -280,7 +284,7 @@ pub impl Parser { } } - fn try_parse_obsolete_with(&self) -> bool { + pub fn try_parse_obsolete_with(&self) -> bool { if *self.token == token::COMMA && self.token_is_obsolete_ident("with", &self.look_ahead(1u)) { @@ -295,7 +299,8 @@ pub impl Parser { } } - fn try_parse_obsolete_priv_section(&self, attrs: &[attribute]) -> bool { + pub fn try_parse_obsolete_priv_section(&self, attrs: &[attribute]) + -> bool { if self.is_keyword(keywords::Priv) && self.look_ahead(1) == token::LBRACE { self.obsolete(copy *self.span, ObsoletePrivSection); self.eat_keyword(keywords::Priv); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c47092ef61cb7..00ad12ce40241 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -272,9 +272,9 @@ impl Drop for Parser { fn finalize(&self) {} } -pub impl Parser { +impl Parser { // advance the parser by one token - fn bump(&self) { + pub fn bump(&self) { *self.last_span = copy *self.span; let next = if *self.buffer_start == *self.buffer_end { self.reader.next_token() @@ -288,17 +288,20 @@ pub impl Parser { *self.tokens_consumed += 1u; } // EFFECT: replace the current token and span with the given one - fn replace_token(&self, next: token::Token, lo: BytePos, hi: BytePos) { + pub fn replace_token(&self, + next: token::Token, + lo: BytePos, + hi: BytePos) { *self.token = next; *self.span = mk_sp(lo, hi); } - fn buffer_length(&self) -> int { + pub fn buffer_length(&self) -> int { if *self.buffer_start <= *self.buffer_end { return *self.buffer_end - *self.buffer_start; } return (4 - *self.buffer_start) + *self.buffer_end; } - fn look_ahead(&self, distance: uint) -> token::Token { + pub fn look_ahead(&self, distance: uint) -> token::Token { let dist = distance as int; while self.buffer_length() < dist { self.buffer[*self.buffer_end] = self.reader.next_token(); @@ -306,49 +309,49 @@ pub impl Parser { } return copy self.buffer[(*self.buffer_start + dist - 1) & 3].tok; } - fn fatal(&self, m: &str) -> ! { + pub fn fatal(&self, m: &str) -> ! { self.sess.span_diagnostic.span_fatal(*copy self.span, m) } - fn span_fatal(&self, sp: span, m: &str) -> ! { + pub fn span_fatal(&self, sp: span, m: &str) -> ! { self.sess.span_diagnostic.span_fatal(sp, m) } - fn span_note(&self, sp: span, m: &str) { + pub fn span_note(&self, sp: span, m: &str) { self.sess.span_diagnostic.span_note(sp, m) } - fn bug(&self, m: &str) -> ! { + pub fn bug(&self, m: &str) -> ! { self.sess.span_diagnostic.span_bug(*copy self.span, m) } - fn warn(&self, m: &str) { + pub fn warn(&self, m: &str) { self.sess.span_diagnostic.span_warn(*copy self.span, m) } - fn span_err(&self, sp: span, m: &str) { + pub fn span_err(&self, sp: span, m: &str) { self.sess.span_diagnostic.span_err(sp, m) } - fn abort_if_errors(&self) { + pub fn abort_if_errors(&self) { self.sess.span_diagnostic.handler().abort_if_errors(); } - fn get_id(&self) -> node_id { next_node_id(self.sess) } + pub fn get_id(&self) -> node_id { next_node_id(self.sess) } - fn id_to_str(&self, id: ident) -> @~str { + pub fn id_to_str(&self, id: ident) -> @~str { self.sess.interner.get(id) } // is this one of the keywords that signals a closure type? - fn token_is_closure_keyword(&self, tok: &token::Token) -> bool { + pub fn token_is_closure_keyword(&self, tok: &token::Token) -> bool { token::is_keyword(keywords::Pure, tok) || token::is_keyword(keywords::Unsafe, tok) || token::is_keyword(keywords::Once, tok) || token::is_keyword(keywords::Fn, tok) } - fn token_is_lifetime(&self, tok: &token::Token) -> bool { + pub fn token_is_lifetime(&self, tok: &token::Token) -> bool { match *tok { token::LIFETIME(*) => true, _ => false, } } - fn get_lifetime(&self, tok: &token::Token) -> ast::ident { + pub fn get_lifetime(&self, tok: &token::Token) -> ast::ident { match *tok { token::LIFETIME(ref ident) => copy *ident, _ => self.bug("not a lifetime"), @@ -356,8 +359,7 @@ pub impl Parser { } // parse a ty_bare_fun type: - fn parse_ty_bare_fn(&self) -> ty_ - { + pub fn parse_ty_bare_fn(&self) -> ty_ { /* extern "ABI" [pure|unsafe] fn <'lt> (S) -> T @@ -386,10 +388,10 @@ pub impl Parser { } // parse a ty_closure type - fn parse_ty_closure(&self, - sigil: ast::Sigil, - region: Option<@ast::Lifetime>) - -> ty_ { + pub fn parse_ty_closure(&self, + sigil: ast::Sigil, + region: Option<@ast::Lifetime>) + -> ty_ { /* (&|~|@) ['r] [pure|unsafe] [once] fn [:Bounds] <'lt> (S) -> T @@ -440,7 +442,7 @@ pub impl Parser { } // looks like this should be called parse_unsafety - fn parse_unsafety(&self) -> purity { + pub fn parse_unsafety(&self) -> purity { if self.eat_keyword(keywords::Pure) { self.obsolete(*self.last_span, ObsoletePurity); return impure_fn; @@ -452,7 +454,7 @@ pub impl Parser { } // parse a function type (following the 'fn') - fn parse_ty_fn_decl(&self) -> (fn_decl, OptVec) { + pub fn parse_ty_fn_decl(&self) -> (fn_decl, OptVec) { /* (fn) <'lt> (S) -> T @@ -487,7 +489,7 @@ pub impl Parser { } // parse the methods in a trait declaration - fn parse_trait_methods(&self) -> ~[trait_method] { + pub fn parse_trait_methods(&self) -> ~[trait_method] { do self.parse_unspanned_seq( &token::LBRACE, &token::RBRACE, @@ -563,9 +565,8 @@ pub impl Parser { } } - // parse a possibly mutable type - fn parse_mt(&self) -> mt { + pub fn parse_mt(&self) -> mt { let mutbl = self.parse_mutability(); let t = self.parse_ty(false); mt { ty: t, mutbl: mutbl } @@ -573,7 +574,7 @@ pub impl Parser { // parse [mut/const/imm] ID : TY // now used only by obsolete record syntax parser... - fn parse_ty_field(&self) -> ty_field { + pub fn parse_ty_field(&self) -> ty_field { let lo = self.span.lo; let mutbl = self.parse_mutability(); let id = self.parse_ident(); @@ -590,7 +591,7 @@ pub impl Parser { } // parse optional return type [ -> TY ] in function decl - fn parse_ret_ty(&self) -> (ret_style, @Ty) { + pub fn parse_ret_ty(&self) -> (ret_style, @Ty) { return if self.eat(&token::RARROW) { let lo = self.span.lo; if self.eat(&token::NOT) { @@ -621,7 +622,7 @@ pub impl Parser { // parse a type. // Useless second parameter for compatibility with quasiquote macros. // Bleh! - fn parse_ty(&self, _: bool) -> @Ty { + pub fn parse_ty(&self, _: bool) -> @Ty { maybe_whole!(self, nt_ty); let lo = self.span.lo; @@ -722,11 +723,9 @@ pub impl Parser { } // parse the type following a @ or a ~ - fn parse_box_or_uniq_pointee( - &self, - sigil: ast::Sigil, - ctor: &fn(v: mt) -> ty_) -> ty_ - { + pub fn parse_box_or_uniq_pointee(&self, + sigil: ast::Sigil, + ctor: &fn(v: mt) -> ty_) -> ty_ { // @'foo fn() or @foo/fn() or @fn() are parsed directly as fn types: match *self.token { token::LIFETIME(*) => { @@ -765,7 +764,7 @@ pub impl Parser { ctor(mt) } - fn parse_borrowed_pointee(&self) -> ty_ { + pub fn parse_borrowed_pointee(&self) -> ty_ { // look for `&'lt` or `&'foo ` and interpret `foo` as the region name: let opt_lifetime = self.parse_opt_lifetime(); @@ -778,7 +777,7 @@ pub impl Parser { } // parse an optional, obsolete argument mode. - fn parse_arg_mode(&self) { + pub fn parse_arg_mode(&self) { if self.eat(&token::BINOP(token::MINUS)) { self.obsolete(*self.span, ObsoleteMode); } else if self.eat(&token::ANDAND) { @@ -794,7 +793,7 @@ pub impl Parser { } } - fn is_named_argument(&self) -> bool { + pub fn is_named_argument(&self) -> bool { let offset = if *self.token == token::BINOP(token::AND) { 1 } else if *self.token == token::BINOP(token::MINUS) { @@ -819,7 +818,7 @@ pub impl Parser { // This version of parse arg doesn't necessarily require // identifier names. - fn parse_arg_general(&self, require_name: bool) -> arg { + pub fn parse_arg_general(&self, require_name: bool) -> arg { let mut is_mutbl = false; let pat = if require_name || self.is_named_argument() { self.parse_arg_mode(); @@ -844,12 +843,12 @@ pub impl Parser { } // parse a single function argument - fn parse_arg(&self) -> arg_or_capture_item { + pub fn parse_arg(&self) -> arg_or_capture_item { either::Left(self.parse_arg_general(true)) } // parse an argument in a lambda header e.g. |arg, arg| - fn parse_fn_block_arg(&self) -> arg_or_capture_item { + pub fn parse_fn_block_arg(&self) -> arg_or_capture_item { self.parse_arg_mode(); let is_mutbl = self.eat_keyword(keywords::Mut); let pat = self.parse_pat(); @@ -870,7 +869,7 @@ pub impl Parser { }) } - fn maybe_parse_fixed_vstore(&self) -> Option<@ast::expr> { + pub fn maybe_parse_fixed_vstore(&self) -> Option<@ast::expr> { if self.eat(&token::BINOP(token::STAR)) { self.obsolete(*self.last_span, ObsoleteFixedLengthVectorType); Some(self.parse_expr()) @@ -885,7 +884,7 @@ pub impl Parser { } // matches token_lit = LIT_INT | ... - fn lit_from_token(&self, tok: &token::Token) -> lit_ { + pub fn lit_from_token(&self, tok: &token::Token) -> lit_ { match *tok { token::LIT_INT(i, it) => lit_int(i, it), token::LIT_UINT(u, ut) => lit_uint(u, ut), @@ -900,7 +899,7 @@ pub impl Parser { } // matches lit = true | false | token_lit - fn parse_lit(&self) -> lit { + pub fn parse_lit(&self) -> lit { let lo = self.span.lo; let lit = if self.eat_keyword(keywords::True) { lit_bool(true) @@ -916,7 +915,7 @@ pub impl Parser { } // matches '-' lit | lit - fn parse_literal_maybe_minus(&self) -> @expr { + pub fn parse_literal_maybe_minus(&self) -> @expr { let minus_lo = self.span.lo; let minus_present = self.eat(&token::BINOP(token::MINUS)); @@ -935,7 +934,7 @@ pub impl Parser { // parse a path into a vector of idents, whether the path starts // with ::, and a span. - fn parse_path(&self) -> (~[ast::ident],bool,span) { + pub fn parse_path(&self) -> (~[ast::ident],bool,span) { let lo = self.span.lo; let is_global = self.eat(&token::MOD_SEP); let (ids,span{lo:_,hi,expn_info}) = self.parse_path_non_global(); @@ -943,7 +942,7 @@ pub impl Parser { } // parse a path beginning with an identifier into a vector of idents and a span - fn parse_path_non_global(&self) -> (~[ast::ident],span) { + pub fn parse_path_non_global(&self) -> (~[ast::ident],span) { let lo = self.span.lo; let mut ids = ~[]; // must be at least one to begin: @@ -966,8 +965,7 @@ pub impl Parser { } // parse a path that doesn't have type parameters attached - fn parse_path_without_tps(&self) - -> @ast::Path { + pub fn parse_path_without_tps(&self) -> @ast::Path { maybe_whole!(self, nt_path); let (ids,is_global,sp) = self.parse_path(); @ast::Path { span: sp, @@ -980,7 +978,7 @@ pub impl Parser { // parse a path optionally with type parameters. If 'colons' // is true, then type parameters must be preceded by colons, // as in a::t:: - fn parse_path_with_tps(&self, colons: bool) -> @ast::Path { + pub fn parse_path_with_tps(&self, colons: bool) -> @ast::Path { debug!("parse_path_with_tps(colons=%b)", colons); maybe_whole!(self, nt_path); @@ -1042,7 +1040,7 @@ pub impl Parser { } /// parses 0 or 1 lifetime - fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> { + pub fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> { match *self.token { token::LIFETIME(*) => { Some(@self.parse_lifetime()) @@ -1064,7 +1062,7 @@ pub impl Parser { } } - fn token_is_lifetime(&self, tok: &token::Token) -> bool { + pub fn token_is_lifetime(&self, tok: &token::Token) -> bool { match *tok { token::LIFETIME(_) => true, _ => false @@ -1073,7 +1071,7 @@ pub impl Parser { /// Parses a single lifetime // matches lifetime = ( LIFETIME ) | ( IDENT / ) - fn parse_lifetime(&self) -> ast::Lifetime { + pub fn parse_lifetime(&self) -> ast::Lifetime { match *self.token { token::LIFETIME(i) => { let span = copy self.span; @@ -1107,7 +1105,7 @@ pub impl Parser { // matches lifetimes = ( lifetime ) | ( lifetime , lifetimes ) // actually, it matches the empty one too, but putting that in there // messes up the grammar.... - fn parse_lifetimes(&self) -> OptVec { + pub fn parse_lifetimes(&self) -> OptVec { /*! * * Parses zero or more comma separated lifetimes. @@ -1139,13 +1137,13 @@ pub impl Parser { } } - fn token_is_mutability(&self, tok: &token::Token) -> bool { + pub fn token_is_mutability(&self, tok: &token::Token) -> bool { token::is_keyword(keywords::Mut, tok) || token::is_keyword(keywords::Const, tok) } // parse mutability declaration (mut/const/imm) - fn parse_mutability(&self) -> mutability { + pub fn parse_mutability(&self) -> mutability { if self.eat_keyword(keywords::Mut) { m_mutbl } else if self.eat_keyword(keywords::Const) { @@ -1156,7 +1154,7 @@ pub impl Parser { } // parse ident COLON expr - fn parse_field(&self) -> field { + pub fn parse_field(&self) -> field { let lo = self.span.lo; let i = self.parse_ident(); self.expect(&token::COLON); @@ -1167,7 +1165,7 @@ pub impl Parser { }) } - fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr { + pub fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr { @expr { id: self.get_id(), callee_id: self.get_id(), @@ -1176,7 +1174,7 @@ pub impl Parser { } } - fn mk_mac_expr(&self, lo: BytePos, hi: BytePos, m: mac_) -> @expr { + pub fn mk_mac_expr(&self, lo: BytePos, hi: BytePos, m: mac_) -> @expr { @expr { id: self.get_id(), callee_id: self.get_id(), @@ -1185,7 +1183,7 @@ pub impl Parser { } } - fn mk_lit_u32(&self, i: u32) -> @expr { + pub fn mk_lit_u32(&self, i: u32) -> @expr { let span = self.span; let lv_lit = @codemap::spanned { node: lit_uint(i as u64, ty_u32), @@ -1203,7 +1201,7 @@ pub impl Parser { // at the bottom (top?) of the precedence hierarchy, // parse things like parenthesized exprs, // macros, return, etc. - fn parse_bottom_expr(&self) -> @expr { + pub fn parse_bottom_expr(&self) -> @expr { maybe_whole_expr!(self); let lo = self.span.lo; @@ -1414,23 +1412,20 @@ pub impl Parser { } // parse a block or unsafe block - fn parse_block_expr( - &self, - lo: BytePos, - blk_mode: blk_check_mode - ) -> @expr { + pub fn parse_block_expr(&self, lo: BytePos, blk_mode: blk_check_mode) + -> @expr { self.expect(&token::LBRACE); let blk = self.parse_block_tail(lo, blk_mode); return self.mk_expr(blk.span.lo, blk.span.hi, expr_block(blk)); } // parse a.b or a(13) or a[4] or just a - fn parse_dot_or_call_expr(&self) -> @expr { + pub fn parse_dot_or_call_expr(&self) -> @expr { let b = self.parse_bottom_expr(); self.parse_dot_or_call_expr_with(b) } - fn parse_dot_or_call_expr_with(&self, e0: @expr) -> @expr { + pub fn parse_dot_or_call_expr_with(&self, e0: @expr) -> @expr { let mut e = e0; let lo = e.span.lo; let mut hi; @@ -1504,7 +1499,7 @@ pub impl Parser { // parse an optional separator followed by a kleene-style // repetition token (+ or *). - fn parse_sep_and_zerok(&self) -> (Option, bool) { + pub fn parse_sep_and_zerok(&self) -> (Option, bool) { if *self.token == token::BINOP(token::STAR) || *self.token == token::BINOP(token::PLUS) { let zerok = *self.token == token::BINOP(token::STAR); @@ -1525,7 +1520,7 @@ pub impl Parser { } // parse a single token tree from the input. - fn parse_token_tree(&self) -> token_tree { + pub fn parse_token_tree(&self) -> token_tree { maybe_whole!(deref self, nt_tt); // this is the fall-through for the 'match' below. @@ -1612,7 +1607,7 @@ pub impl Parser { // parse a stream of tokens into a list of token_trees, // up to EOF. - fn parse_all_token_trees(&self) -> ~[token_tree] { + pub fn parse_all_token_trees(&self) -> ~[token_tree] { let mut tts = ~[]; while *self.token != token::EOF { tts.push(self.parse_token_tree()); @@ -1620,7 +1615,7 @@ pub impl Parser { tts } - fn parse_matchers(&self) -> ~[matcher] { + pub fn parse_matchers(&self) -> ~[matcher] { // unification of matchers and token_trees would vastly improve // the interpolation of matchers maybe_whole!(self, nt_matchers); @@ -1642,12 +1637,11 @@ pub impl Parser { // This goofy function is necessary to correctly match parens in matchers. // Otherwise, `$( ( )` would be a valid matcher, and `$( () )` would be // invalid. It's similar to common::parse_seq. - fn parse_matcher_subseq( - &self, - name_idx: @mut uint, - bra: token::Token, - ket: token::Token - ) -> ~[matcher] { + pub fn parse_matcher_subseq(&self, + name_idx: @mut uint, + bra: token::Token, + ket: token::Token) + -> ~[matcher] { let mut ret_val = ~[]; let mut lparens = 0u; @@ -1664,7 +1658,7 @@ pub impl Parser { return ret_val; } - fn parse_matcher(&self, name_idx: @mut uint) -> matcher { + pub fn parse_matcher(&self, name_idx: @mut uint) -> matcher { let lo = self.span.lo; let m = if *self.token == token::DOLLAR { @@ -1699,7 +1693,7 @@ pub impl Parser { } // parse a prefix-operator expr - fn parse_prefix_expr(&self) -> @expr { + pub fn parse_prefix_expr(&self) -> @expr { let lo = self.span.lo; let hi; @@ -1791,13 +1785,12 @@ pub impl Parser { } // parse an expression of binops - fn parse_binops(&self) -> @expr { + pub fn parse_binops(&self) -> @expr { self.parse_more_binops(self.parse_prefix_expr(), 0) } // parse an expression of binops of at least min_prec precedence - fn parse_more_binops(&self, lhs: @expr, min_prec: uint) -> - @expr { + pub fn parse_more_binops(&self, lhs: @expr, min_prec: uint) -> @expr { if self.expr_is_complete(lhs) { return lhs; } let peeked = copy *self.token; if peeked == token::BINOP(token::OR) && @@ -1841,7 +1834,7 @@ pub impl Parser { // parse an assignment expression.... // actually, this seems to be the main entry point for // parsing an arbitrary expression. - fn parse_assign_expr(&self) -> @expr { + pub fn parse_assign_expr(&self) -> @expr { let lo = self.span.lo; let lhs = self.parse_binops(); match *self.token { @@ -1892,7 +1885,7 @@ pub impl Parser { } // parse an 'if' expression ('if' token already eaten) - fn parse_if_expr(&self) -> @expr { + pub fn parse_if_expr(&self) -> @expr { let lo = self.last_span.lo; let cond = self.parse_expr(); let thn = self.parse_block(); @@ -1907,7 +1900,7 @@ pub impl Parser { } // `|args| { ... }` or `{ ...}` like in `do` expressions - fn parse_lambda_block_expr(&self) -> @expr { + pub fn parse_lambda_block_expr(&self) -> @expr { self.parse_lambda_expr_( || { match *self.token { @@ -1935,7 +1928,7 @@ pub impl Parser { } // `|args| expr` - fn parse_lambda_expr(&self) -> @expr { + pub fn parse_lambda_expr(&self) -> @expr { self.parse_lambda_expr_(|| self.parse_fn_block_decl(), || self.parse_expr()) } @@ -1943,11 +1936,10 @@ pub impl Parser { // parse something of the form |args| expr // this is used both in parsing a lambda expr // and in parsing a block expr as e.g. in for... - fn parse_lambda_expr_( - &self, - parse_decl: &fn() -> fn_decl, - parse_body: &fn() -> @expr - ) -> @expr { + pub fn parse_lambda_expr_(&self, + parse_decl: &fn() -> fn_decl, + parse_body: &fn() -> @expr) + -> @expr { let lo = self.last_span.lo; let decl = parse_decl(); let body = parse_body(); @@ -1964,7 +1956,7 @@ pub impl Parser { expr_fn_block(decl, fakeblock)); } - fn parse_else_expr(&self) -> @expr { + pub fn parse_else_expr(&self) -> @expr { if self.eat_keyword(keywords::If) { return self.parse_if_expr(); } else { @@ -1976,9 +1968,11 @@ pub impl Parser { // parse a 'for' or 'do'. // the 'for' and 'do' expressions parse as calls, but look like // function calls followed by a closure expression. - fn parse_sugary_call_expr(&self, keyword: ~str, - sugar: CallSugar, - ctor: &fn(v: @expr) -> expr_) -> @expr { + pub fn parse_sugary_call_expr(&self, + keyword: ~str, + sugar: CallSugar, + ctor: &fn(v: @expr) -> expr_) + -> @expr { let lo = self.last_span; // Parse the callee `foo` in // for foo || { @@ -2035,7 +2029,7 @@ pub impl Parser { } } - fn parse_while_expr(&self) -> @expr { + pub fn parse_while_expr(&self) -> @expr { let lo = self.last_span.lo; let cond = self.parse_expr(); let body = self.parse_block(); @@ -2043,7 +2037,7 @@ pub impl Parser { return self.mk_expr(lo, hi, expr_while(cond, body)); } - fn parse_loop_expr(&self, opt_ident: Option) -> @expr { + pub fn parse_loop_expr(&self, opt_ident: Option) -> @expr { // loop headers look like 'loop {' or 'loop unsafe {' let is_loop_header = *self.token == token::LBRACE @@ -2126,7 +2120,7 @@ pub impl Parser { } // parse an expression - fn parse_expr(&self) -> @expr { + pub fn parse_expr(&self) -> @expr { return self.parse_expr_res(UNRESTRICTED); } @@ -2257,7 +2251,7 @@ pub impl Parser { } // parse a pattern. - fn parse_pat(&self) -> @pat { + pub fn parse_pat(&self) -> @pat { maybe_whole!(self, nt_pat); let lo = self.span.lo; @@ -2580,7 +2574,7 @@ pub impl Parser { // parse a statement. may include decl. // precondition: any attributes are parsed already - fn parse_stmt(&self, item_attrs: ~[attribute]) -> @stmt { + pub fn parse_stmt(&self, item_attrs: ~[attribute]) -> @stmt { maybe_whole!(self, nt_stmt); fn check_expected_item(p: &Parser, current_attrs: &[attribute]) { @@ -2674,7 +2668,7 @@ pub impl Parser { } // parse a block. No inner attrs are allowed. - fn parse_block(&self) -> blk { + pub fn parse_block(&self) -> blk { maybe_whole!(self, nt_block); let lo = self.span.lo; @@ -2924,7 +2918,7 @@ pub impl Parser { // matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > ) // | ( < lifetimes , typaramseq ( , )? > ) // where typaramseq = ( typaram ) | ( typaram , typaramseq ) - fn parse_generics(&self) -> ast::Generics { + pub fn parse_generics(&self) -> ast::Generics { if self.eat(&token::LT) { let lifetimes = self.parse_lifetimes(); let ty_params = self.parse_seq_to_gt( @@ -2958,9 +2952,7 @@ pub impl Parser { } // parse the argument list and result type of a function declaration - fn parse_fn_decl(&self) - -> fn_decl - { + pub fn parse_fn_decl(&self) -> fn_decl { let args_or_capture_items: ~[arg_or_capture_item] = self.parse_unspanned_seq( &token::LPAREN, @@ -3398,9 +3390,10 @@ pub impl Parser { } // parse a structure field declaration - fn parse_single_struct_field(&self, - vis: visibility, - attrs: ~[attribute]) -> @struct_field { + pub fn parse_single_struct_field(&self, + vis: visibility, + attrs: ~[attribute]) + -> @struct_field { if self.eat_obsolete_ident("let") { self.obsolete(*self.last_span, ObsoleteLet); } @@ -4214,7 +4207,7 @@ pub impl Parser { return iovi_none; } - fn parse_item(&self, attrs: ~[attribute]) -> Option<@ast::item> { + pub fn parse_item(&self, attrs: ~[attribute]) -> Option<@ast::item> { match self.parse_item_or_view_item(attrs, true) { iovi_none => None, @@ -4493,7 +4486,7 @@ pub impl Parser { // Parses a source module as a crate. This is the main // entry point for the parser. - fn parse_crate_mod(&self) -> @crate { + pub fn parse_crate_mod(&self) -> @crate { let lo = self.span.lo; // parse the crate's inner attrs, maybe (oops) one // of the attrs of an item: @@ -4507,7 +4500,7 @@ pub impl Parser { config: copy self.cfg }) } - fn parse_str(&self) -> @~str { + pub fn parse_str(&self) -> @~str { match *self.token { token::LIT_STR(s) => { self.bump(); diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index f50b9f8936a3a..b716384c6ccc5 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -393,21 +393,22 @@ pub struct ident_interner { priv interner: StrInterner, } -pub impl ident_interner { - fn intern(&self, val: &str) -> ast::ident { +impl ident_interner { + pub fn intern(&self, val: &str) -> ast::ident { ast::ident { repr: self.interner.intern(val), ctxt: 0 } } - fn gensym(&self, val: &str) -> ast::ident { + pub fn gensym(&self, val: &str) -> ast::ident { ast::ident { repr: self.interner.gensym(val), ctxt: 0 } } - fn get(&self, idx: ast::ident) -> @~str { + pub fn get(&self, idx: ast::ident) -> @~str { self.interner.get(idx.repr) } - fn len(&self) -> uint { + pub fn len(&self) -> uint { self.interner.len() } - fn find_equiv>(&self, val: &Q) - -> Option { + pub fn find_equiv>(&self, val: &Q) -> Option { match self.interner.find_equiv(val) { Some(v) => Some(ast::ident { repr: v, ctxt: 0 }), None => None, @@ -586,8 +587,8 @@ pub mod keywords { Be, } - pub impl Keyword { - fn to_ident(&self) -> ident { + impl Keyword { + pub fn to_ident(&self) -> ident { match *self { As => ident { repr: 35, ctxt: 0 }, Break => ident { repr: 36, ctxt: 0 }, diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 11830dc3c2908..f6059980697fa 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -87,11 +87,12 @@ pub enum token { EOF, } -pub impl token { - fn is_eof(&self) -> bool { +impl token { + pub fn is_eof(&self) -> bool { match *self { EOF => true, _ => false } } - fn is_hardbreak_tok(&self) -> bool { + + pub fn is_hardbreak_tok(&self) -> bool { match *self { BREAK(break_t { offset: 0, @@ -274,11 +275,13 @@ pub struct Printer { pending_indentation: int, } -pub impl Printer { - fn last_token(&mut self) -> token { self.token[self.right] } +impl Printer { + pub fn last_token(&mut self) -> token { self.token[self.right] } // be very careful with this! - fn replace_last_token(&mut self, t: token) { self.token[self.right] = t; } - fn pretty_print(&mut self, t: token) { + pub fn replace_last_token(&mut self, t: token) { + self.token[self.right] = t; + } + pub fn pretty_print(&mut self, t: token) { debug!("pp ~[%u,%u]", self.left, self.right); match t { EOF => { @@ -346,7 +349,7 @@ pub impl Printer { } } } - fn check_stream(&mut self) { + pub fn check_stream(&mut self) { debug!("check_stream ~[%u, %u] with left_total=%d, right_total=%d", self.left, self.right, self.left_total, self.right_total); if self.right_total - self.left_total > self.space { @@ -362,7 +365,7 @@ pub impl Printer { if self.left != self.right { self.check_stream(); } } } - fn scan_push(&mut self, x: uint) { + pub fn scan_push(&mut self, x: uint) { debug!("scan_push %u", x); if self.scan_stack_empty { self.scan_stack_empty = false; @@ -373,7 +376,7 @@ pub impl Printer { } self.scan_stack[self.top] = x; } - fn scan_pop(&mut self) -> uint { + pub fn scan_pop(&mut self) -> uint { assert!((!self.scan_stack_empty)); let x = self.scan_stack[self.top]; if self.top == self.bottom { @@ -381,11 +384,11 @@ pub impl Printer { } else { self.top += self.buf_len - 1u; self.top %= self.buf_len; } return x; } - fn scan_top(&mut self) -> uint { + pub fn scan_top(&mut self) -> uint { assert!((!self.scan_stack_empty)); return self.scan_stack[self.top]; } - fn scan_pop_bottom(&mut self) -> uint { + pub fn scan_pop_bottom(&mut self) -> uint { assert!((!self.scan_stack_empty)); let x = self.scan_stack[self.bottom]; if self.top == self.bottom { @@ -393,12 +396,12 @@ pub impl Printer { } else { self.bottom += 1u; self.bottom %= self.buf_len; } return x; } - fn advance_right(&mut self) { + pub fn advance_right(&mut self) { self.right += 1u; self.right %= self.buf_len; assert!((self.right != self.left)); } - fn advance_left(&mut self, x: token, L: int) { + pub fn advance_left(&mut self, x: token, L: int) { debug!("advnce_left ~[%u,%u], sizeof(%u)=%d", self.left, self.right, self.left, L); if L >= 0 { @@ -418,7 +421,7 @@ pub impl Printer { } } } - fn check_stack(&mut self, k: int) { + pub fn check_stack(&mut self, k: int) { if !self.scan_stack_empty { let x = self.scan_top(); match copy self.token[x] { @@ -441,17 +444,17 @@ pub impl Printer { } } } - fn print_newline(&mut self, amount: int) { + pub fn print_newline(&mut self, amount: int) { debug!("NEWLINE %d", amount); (*self.out).write_str("\n"); self.pending_indentation = 0; self.indent(amount); } - fn indent(&mut self, amount: int) { + pub fn indent(&mut self, amount: int) { debug!("INDENT %d", amount); self.pending_indentation += amount; } - fn get_top(&mut self) -> print_stack_elt { + pub fn get_top(&mut self) -> print_stack_elt { let print_stack = &mut *self.print_stack; let n = print_stack.len(); if n != 0u { @@ -463,14 +466,14 @@ pub impl Printer { } } } - fn print_str(&mut self, s: &str) { + pub fn print_str(&mut self, s: &str) { while self.pending_indentation > 0 { (*self.out).write_str(" "); self.pending_indentation -= 1; } (*self.out).write_str(s); } - fn print(&mut self, x: token, L: int) { + pub fn print(&mut self, x: token, L: int) { debug!("print %s %d (remaining line space=%d)", tok_str(x), L, self.space); debug!("%s", buf_str(copy self.token, diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index e2736a00564bd..c3deb65163ddd 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -27,21 +27,21 @@ pub struct Interner { } // when traits can extend traits, we should extend index to get [] -pub impl Interner { - fn new() -> Interner { +impl Interner { + pub fn new() -> Interner { Interner { map: @mut HashMap::new(), vect: @mut ~[], } } - fn prefill(init: &[T]) -> Interner { + pub fn prefill(init: &[T]) -> Interner { let rv = Interner::new(); for init.each() |v| { rv.intern(*v); } rv } - fn intern(&self, val: T) -> uint { + pub fn intern(&self, val: T) -> uint { match self.map.find(&val) { Some(&idx) => return idx, None => (), @@ -54,7 +54,7 @@ pub impl Interner { new_idx } - fn gensym(&self, val: T) -> uint { + pub fn gensym(&self, val: T) -> uint { let new_idx = { let vect = &*self.vect; vect.len() @@ -67,11 +67,11 @@ pub impl Interner { // this isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, // where we first check a pred and then rely on it, ceasing to fail is ok. - fn get(&self, idx: uint) -> T { self.vect[idx] } + pub fn get(&self, idx: uint) -> T { self.vect[idx] } - fn len(&self) -> uint { let vect = &*self.vect; vect.len() } + pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() } - fn find_equiv>(&self, val: &Q) + pub fn find_equiv>(&self, val: &Q) -> Option { match self.map.find_equiv(val) { Some(v) => Some(*v), @@ -88,21 +88,21 @@ pub struct StrInterner { } // when traits can extend traits, we should extend index to get [] -pub impl StrInterner { - fn new() -> StrInterner { +impl StrInterner { + pub fn new() -> StrInterner { StrInterner { map: @mut HashMap::new(), vect: @mut ~[], } } - fn prefill(init: &[&str]) -> StrInterner { + pub fn prefill(init: &[&str]) -> StrInterner { let rv = StrInterner::new(); for init.each() |v| { rv.intern(*v); } rv } - fn intern(&self, val: &str) -> uint { + pub fn intern(&self, val: &str) -> uint { match self.map.find_equiv(&StringRef(val)) { Some(&idx) => return idx, None => (), @@ -114,7 +114,7 @@ pub impl StrInterner { new_idx } - fn gensym(&self, val: &str) -> uint { + pub fn gensym(&self, val: &str) -> uint { let new_idx = self.len(); // leave out of .map to avoid colliding self.vect.push(@val.to_owned()); @@ -124,12 +124,12 @@ pub impl StrInterner { // this isn't "pure" in the traditional sense, because it can go from // failing to returning a value as items are interned. But for typestate, // where we first check a pred and then rely on it, ceasing to fail is ok. - fn get(&self, idx: uint) -> @~str { self.vect[idx] } + pub fn get(&self, idx: uint) -> @~str { self.vect[idx] } - fn len(&self) -> uint { let vect = &*self.vect; vect.len() } + pub fn len(&self) -> uint { let vect = &*self.vect; vect.len() } - fn find_equiv>(&self, val: &Q) - -> Option { + pub fn find_equiv>(&self, val: &Q) + -> Option { match self.map.find_equiv(val) { Some(v) => Some(*v), None => None, diff --git a/src/test/auxiliary/anon_trait_static_method_lib.rs b/src/test/auxiliary/anon_trait_static_method_lib.rs index 6e111381cba34..a15373a703377 100644 --- a/src/test/auxiliary/anon_trait_static_method_lib.rs +++ b/src/test/auxiliary/anon_trait_static_method_lib.rs @@ -12,8 +12,8 @@ pub struct Foo { x: int } -pub impl Foo { - fn new() -> Foo { +impl Foo { + pub fn new() -> Foo { Foo { x: 3 } } } diff --git a/src/test/auxiliary/cci_class_2.rs b/src/test/auxiliary/cci_class_2.rs index b120a4d759f90..c0275249ca6d4 100644 --- a/src/test/auxiliary/cci_class_2.rs +++ b/src/test/auxiliary/cci_class_2.rs @@ -16,8 +16,8 @@ pub mod kitties { } - pub impl cat { - fn speak(&self) {} + impl cat { + pub fn speak(&self) {} } pub fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/auxiliary/cci_class_3.rs b/src/test/auxiliary/cci_class_3.rs index a516f5398df62..7ebf5a1e75a7f 100644 --- a/src/test/auxiliary/cci_class_3.rs +++ b/src/test/auxiliary/cci_class_3.rs @@ -15,9 +15,9 @@ pub mod kitties { how_hungry : int, } - pub impl cat { - fn speak(&mut self) { self.meows += 1u; } - fn meow_count(&mut self) -> uint { self.meows } + impl cat { + pub fn speak(&mut self) { self.meows += 1u; } + pub fn meow_count(&mut self) -> uint { self.meows } } pub fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/auxiliary/cci_class_4.rs b/src/test/auxiliary/cci_class_4.rs index 68143b32741c8..98e5c8c2b5bbd 100644 --- a/src/test/auxiliary/cci_class_4.rs +++ b/src/test/auxiliary/cci_class_4.rs @@ -16,10 +16,10 @@ pub mod kitties { name : ~str, } - pub impl cat { - fn speak(&mut self) { self.meow(); } + impl cat { + pub fn speak(&mut self) { self.meow(); } - fn eat(&mut self) -> bool { + pub fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -31,8 +31,8 @@ pub mod kitties { } } - pub impl cat { - fn meow(&mut self) { + impl cat { + pub fn meow(&mut self) { error!("Meow"); self.meows += 1u; if self.meows % 5u == 0u { diff --git a/src/test/auxiliary/cci_class_5.rs b/src/test/auxiliary/cci_class_5.rs index 10dedc12399d1..d64930b3dab22 100644 --- a/src/test/auxiliary/cci_class_5.rs +++ b/src/test/auxiliary/cci_class_5.rs @@ -16,8 +16,8 @@ pub mod kitties { how_hungry : int, } - pub impl cat { - priv fn nap(&self) { for uint::range(1, 10000u) |_i|{}} + impl cat { + priv fn nap(&self) { for uint::range(1, 10000u) |_i|{}} } pub fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/auxiliary/cci_class_6.rs b/src/test/auxiliary/cci_class_6.rs index 7ad617cebdbb3..90344a544bff4 100644 --- a/src/test/auxiliary/cci_class_6.rs +++ b/src/test/auxiliary/cci_class_6.rs @@ -16,11 +16,12 @@ pub mod kitties { how_hungry : int, } - pub impl cat { - fn speak(&mut self, stuff: ~[T]) { + impl cat { + pub fn speak(&mut self, stuff: ~[T]) { self.meows += stuff.len(); } - fn meow_count(&mut self) -> uint { self.meows } + + pub fn meow_count(&mut self) -> uint { self.meows } } pub fn cat(in_x : uint, in_y : int, in_info: ~[U]) -> cat { diff --git a/src/test/auxiliary/cci_class_cast.rs b/src/test/auxiliary/cci_class_cast.rs index 56808b0d58f8d..1e82b85f728c0 100644 --- a/src/test/auxiliary/cci_class_cast.rs +++ b/src/test/auxiliary/cci_class_cast.rs @@ -21,7 +21,7 @@ pub mod kitty { fn to_str(&self) -> ~str { copy self.name } } - priv impl cat { + impl cat { fn meow(&mut self) { error!("Meow"); self.meows += 1u; @@ -32,10 +32,10 @@ pub mod kitty { } - pub impl cat { - fn speak(&mut self) { self.meow(); } + impl cat { + pub fn speak(&mut self) { self.meow(); } - fn eat(&mut self) -> bool { + pub fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; diff --git a/src/test/auxiliary/impl_privacy_xc_1.rs b/src/test/auxiliary/impl_privacy_xc_1.rs index 4d98c4d9d2b54..4752c5a3bac56 100644 --- a/src/test/auxiliary/impl_privacy_xc_1.rs +++ b/src/test/auxiliary/impl_privacy_xc_1.rs @@ -4,6 +4,6 @@ pub struct Fish { x: int } -pub impl Fish { - fn swim(&self) {} +impl Fish { + pub fn swim(&self) {} } diff --git a/src/test/auxiliary/issue_2472_b.rs b/src/test/auxiliary/issue_2472_b.rs index 7969128ce5285..1475b1a75a665 100644 --- a/src/test/auxiliary/issue_2472_b.rs +++ b/src/test/auxiliary/issue_2472_b.rs @@ -11,8 +11,8 @@ pub struct S(()); -pub impl S { - fn foo(&self) { } +impl S { + pub fn foo(&self) { } } pub trait T { diff --git a/src/test/bench/core-set.rs b/src/test/bench/core-set.rs index 5281c1b863c6a..a0b742515494c 100644 --- a/src/test/bench/core-set.rs +++ b/src/test/bench/core-set.rs @@ -35,8 +35,8 @@ fn timed(result: &mut float, op: &fn()) { *result = (end - start); } -pub impl Results { - fn bench_int, +impl Results { + pub fn bench_int, R: rand::Rng>( &mut self, rng: &mut R, @@ -79,7 +79,7 @@ pub impl Results { } } - fn bench_str, + pub fn bench_str, R:rand::Rng>( &mut self, rng: &mut R, diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 8f39ae62f9e39..25bdf7dc3feff 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -35,8 +35,8 @@ struct Noise2DContext { permutations: [int, ..256], } -pub impl Noise2DContext { - fn new() -> Noise2DContext { +impl Noise2DContext { + pub fn new() -> Noise2DContext { let mut r = rand::rng(); let mut rgradients = [ Vec2 { x: 0.0, y: 0.0 }, ..256 ]; for int::range(0, 256) |i| { @@ -55,17 +55,17 @@ pub impl Noise2DContext { } #[inline(always)] - fn get_gradient(&self, x: int, y: int) -> Vec2 { + pub fn get_gradient(&self, x: int, y: int) -> Vec2 { let idx = self.permutations[x & 255] + self.permutations[y & 255]; self.rgradients[idx & 255] } #[inline] - fn get_gradients(&self, - gradients: &mut [Vec2, ..4], - origins: &mut [Vec2, ..4], - x: f32, - y: f32) { + pub fn get_gradients(&self, + gradients: &mut [Vec2, ..4], + origins: &mut [Vec2, ..4], + x: f32, + y: f32) { let x0f = f32::floor(x); let y0f = f32::floor(y); let x0 = x0f as int; @@ -85,7 +85,7 @@ pub impl Noise2DContext { } #[inline] - fn get(&self, x: f32, y: f32) -> f32 { + pub fn get(&self, x: f32, y: f32) -> f32 { let p = Vec2 {x: x, y: y}; let mut gradients = [ Vec2 { x: 0.0, y: 0.0 }, ..4 ]; let mut origins = [ Vec2 { x: 0.0, y: 0.0 }, ..4 ]; diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 8f12f2bd58e73..3bf08cfb934f8 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -44,7 +44,7 @@ struct Sudoku { grid: grid } -pub impl Sudoku { +impl Sudoku { pub fn new(g: grid) -> Sudoku { return Sudoku { grid: g } } diff --git a/src/test/compile-fail/assign-to-method.rs b/src/test/compile-fail/assign-to-method.rs index 55a358a32e200..85bb60e05853e 100644 --- a/src/test/compile-fail/assign-to-method.rs +++ b/src/test/compile-fail/assign-to-method.rs @@ -14,9 +14,8 @@ struct cat { how_hungry : int, } -pub impl cat { - - fn speak(&self) { self.meows += 1u; } +impl cat { + pub fn speak(&self) { self.meows += 1u; } } fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs b/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs index b9758e669e07e..e2fbce6e195f5 100644 --- a/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs +++ b/src/test/compile-fail/borrowck-auto-mut-ref-to-immut-var.rs @@ -16,8 +16,8 @@ struct Foo { x: int } -pub impl Foo { - fn printme(&mut self) { +impl Foo { + pub fn printme(&mut self) { io::println(fmt!("%d", self.x)); } } diff --git a/src/test/compile-fail/borrowck-autoref-3261.rs b/src/test/compile-fail/borrowck-autoref-3261.rs index 192fe669f57ae..4bbd1b0decf57 100644 --- a/src/test/compile-fail/borrowck-autoref-3261.rs +++ b/src/test/compile-fail/borrowck-autoref-3261.rs @@ -10,11 +10,12 @@ struct X(Either<(uint,uint),extern fn()>); -pub impl X { - fn with(&self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) { +impl X { + pub fn with(&self, blk: &fn(x: &Either<(uint,uint),extern fn()>)) { blk(&**self) } } + fn main() { let mut x = X(Right(main)); do (&mut x).with |opt| { diff --git a/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs b/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs index 3abd19e5a1136..0aa7cbf50b7a3 100644 --- a/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs +++ b/src/test/compile-fail/borrowck-call-method-from-mut-aliasable.rs @@ -12,10 +12,10 @@ struct Foo { x: int, } -pub impl Foo { - fn f(&self) {} - fn g(&const self) {} - fn h(&mut self) {} +impl Foo { + pub fn f(&self) {} + pub fn g(&const self) {} + pub fn h(&mut self) {} } fn a(x: &mut Foo) { diff --git a/src/test/compile-fail/borrowck-insert-during-each.rs b/src/test/compile-fail/borrowck-insert-during-each.rs index c9bd75039693f..1a0bec7d723b3 100644 --- a/src/test/compile-fail/borrowck-insert-during-each.rs +++ b/src/test/compile-fail/borrowck-insert-during-each.rs @@ -14,12 +14,12 @@ struct Foo { n: HashSet, } -pub impl Foo { - fn foo(&mut self, fun: &fn(&int)) { - for self.n.each |f| { - fun(f); +impl Foo { + pub fn foo(&mut self, fun: &fn(&int)) { + for self.n.each |f| { + fun(f); + } } - } } fn bar(f: &mut Foo) { diff --git a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs index 443bcc921837c..b205c5be2179c 100644 --- a/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs +++ b/src/test/compile-fail/borrowck-loan-rcvr-overloaded-op.rs @@ -19,8 +19,8 @@ impl Add for Point { } } -pub impl Point { - fn times(&self, z: int) -> int { +impl Point { + pub fn times(&self, z: int) -> int { self.x * self.y * z } } diff --git a/src/test/compile-fail/class-cast-to-trait.rs b/src/test/compile-fail/class-cast-to-trait.rs index 8df9650d95077..7f7c58a60df05 100644 --- a/src/test/compile-fail/class-cast-to-trait.rs +++ b/src/test/compile-fail/class-cast-to-trait.rs @@ -19,9 +19,8 @@ struct cat { name : ~str, } -pub impl cat { - - fn eat(&self) -> bool { +impl cat { + pub fn eat(&self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -39,7 +38,7 @@ impl noisy for cat { } -priv impl cat { +impl cat { fn meow(&self) { error!("Meow"); self.meows += 1; diff --git a/src/test/compile-fail/class-missing-self.rs b/src/test/compile-fail/class-missing-self.rs index 4d1c22dfabe81..c27c27b5942e1 100644 --- a/src/test/compile-fail/class-missing-self.rs +++ b/src/test/compile-fail/class-missing-self.rs @@ -12,7 +12,7 @@ struct cat { priv meows : uint, } -priv impl cat { +impl cat { fn sleep(&self) { loop{} } fn meow(&self) { error!("Meow"); diff --git a/src/test/compile-fail/issue-2356.rs b/src/test/compile-fail/issue-2356.rs index 9a574b984ca47..cb559b91889bb 100644 --- a/src/test/compile-fail/issue-2356.rs +++ b/src/test/compile-fail/issue-2356.rs @@ -14,6 +14,6 @@ struct cat { tail: int, } -pub impl cat { - fn meow() { tail += 1; } //~ ERROR: Did you mean: `self.tail` +impl cat { + pub fn meow() { tail += 1; } //~ ERROR: Did you mean: `self.tail` } diff --git a/src/test/compile-fail/issue-2766-a.rs b/src/test/compile-fail/issue-2766-a.rs index 41527027c744b..91ae0e1c07a55 100644 --- a/src/test/compile-fail/issue-2766-a.rs +++ b/src/test/compile-fail/issue-2766-a.rs @@ -14,7 +14,7 @@ pub mod stream { use std::option; use std::pipes; - pub impl Stream { + impl Stream { pub fn recv() -> extern fn(v: Stream) -> ::stream::Stream { // resolve really should report just one error here. // Change the test case when it changes. diff --git a/src/test/compile-fail/issue-3021-b.rs b/src/test/compile-fail/issue-3021-b.rs index f9f1a27e11b2c..d3aec178c238a 100644 --- a/src/test/compile-fail/issue-3021-b.rs +++ b/src/test/compile-fail/issue-3021-b.rs @@ -16,8 +16,8 @@ fn siphash(k0 : u64) { v0: u64, } - pub impl siphash { - fn reset(&mut self) { + impl siphash { + pub fn reset(&mut self) { self.v0 = k0 ^ 0x736f6d6570736575; //~ ERROR attempted dynamic environment-capture //~^ ERROR unresolved name `k0`. } diff --git a/src/test/compile-fail/issue-3080.rs b/src/test/compile-fail/issue-3080.rs index 02df25d87d7fb..02ccf14138a35 100644 --- a/src/test/compile-fail/issue-3080.rs +++ b/src/test/compile-fail/issue-3080.rs @@ -10,8 +10,8 @@ // xfail-test struct x(()); -pub impl x { - unsafe fn with() { } // This should fail +impl x { + pub unsafe fn with() { } // This should fail } fn main() { diff --git a/src/test/compile-fail/issue-3707.rs b/src/test/compile-fail/issue-3707.rs index 5e8230686d506..4e128b63e9257 100644 --- a/src/test/compile-fail/issue-3707.rs +++ b/src/test/compile-fail/issue-3707.rs @@ -12,11 +12,11 @@ struct Obj { member: uint } -pub impl Obj { - fn boom() -> bool { +impl Obj { + pub fn boom() -> bool { return 1+1 == 2 } - fn chirp(&self) { + pub fn chirp(&self) { self.boom(); //~ ERROR `&Obj` does not implement any method in scope named `boom` } } diff --git a/src/test/compile-fail/issue-3763.rs b/src/test/compile-fail/issue-3763.rs index f6226032eeef3..9647d412d2cdb 100644 --- a/src/test/compile-fail/issue-3763.rs +++ b/src/test/compile-fail/issue-3763.rs @@ -15,7 +15,7 @@ mod my_mod { pub fn MyStruct () -> MyStruct { MyStruct {priv_field: 4} } - pub impl MyStruct { + impl MyStruct { priv fn happyfun(&self) {} } } diff --git a/src/test/compile-fail/mutable-class-fields-2.rs b/src/test/compile-fail/mutable-class-fields-2.rs index 7d41481354fa6..30c2b9eef8ca0 100644 --- a/src/test/compile-fail/mutable-class-fields-2.rs +++ b/src/test/compile-fail/mutable-class-fields-2.rs @@ -14,8 +14,8 @@ struct cat { how_hungry : int, } -pub impl cat { - fn eat(&self) { +impl cat { + pub fn eat(&self) { self.how_hungry -= 5; //~ ERROR cannot assign } diff --git a/src/test/compile-fail/private-impl-method.rs b/src/test/compile-fail/private-impl-method.rs index a6728f82ec3b3..26b7d73ab2af2 100644 --- a/src/test/compile-fail/private-impl-method.rs +++ b/src/test/compile-fail/private-impl-method.rs @@ -13,7 +13,7 @@ mod a { x: int } - pub impl Foo { + impl Foo { priv fn foo(&self) {} } } diff --git a/src/test/compile-fail/private-method.rs b/src/test/compile-fail/private-method.rs index 800bb1c570394..0c67980a5515c 100644 --- a/src/test/compile-fail/private-method.rs +++ b/src/test/compile-fail/private-method.rs @@ -19,7 +19,7 @@ mod kitties { how_hungry : int, } - pub impl cat { + impl cat { priv fn nap(&self) { uint::range(1u, 10000u, |_i| false); } } diff --git a/src/test/compile-fail/regions-addr-of-self.rs b/src/test/compile-fail/regions-addr-of-self.rs index f96ef639e756c..0516264d45797 100644 --- a/src/test/compile-fail/regions-addr-of-self.rs +++ b/src/test/compile-fail/regions-addr-of-self.rs @@ -12,13 +12,13 @@ struct dog { cats_chased: uint, } -pub impl dog { - fn chase_cat(&mut self) { +impl dog { + pub fn chase_cat(&mut self) { let p: &'static mut uint = &mut self.cats_chased; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements *p += 1u; } - fn chase_cat_2(&mut self) { + pub fn chase_cat_2(&mut self) { let p: &'blk mut uint = &mut self.cats_chased; *p += 1u; } diff --git a/src/test/compile-fail/regions-addr-of-upvar-self.rs b/src/test/compile-fail/regions-addr-of-upvar-self.rs index 1c7235743eaa8..f1172690f4dfa 100644 --- a/src/test/compile-fail/regions-addr-of-upvar-self.rs +++ b/src/test/compile-fail/regions-addr-of-upvar-self.rs @@ -14,8 +14,8 @@ struct dog { food: uint, } -pub impl dog { - fn chase_cat(&mut self) { +impl dog { + pub fn chase_cat(&mut self) { for uint::range(0u, 10u) |_i| { let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements *p = 3u; diff --git a/src/test/compile-fail/regions-glb-free-free.rs b/src/test/compile-fail/regions-glb-free-free.rs index dc3d414e91b4d..d438b55f4af79 100644 --- a/src/test/compile-fail/regions-glb-free-free.rs +++ b/src/test/compile-fail/regions-glb-free-free.rs @@ -22,8 +22,8 @@ mod argparse { Flag { name: name, desc: desc, max_count: 1, value: 0 } } - pub impl<'self> Flag<'self> { - fn set_desc(self, s: &str) -> Flag<'self> { + impl<'self> Flag<'self> { + pub fn set_desc(self, s: &str) -> Flag<'self> { Flag { //~ ERROR cannot infer an appropriate lifetime name: self.name, desc: s, diff --git a/src/test/compile-fail/trait-or-new-type-instead.rs b/src/test/compile-fail/trait-or-new-type-instead.rs index a5e37eb949d28..f687a6f97024a 100644 --- a/src/test/compile-fail/trait-or-new-type-instead.rs +++ b/src/test/compile-fail/trait-or-new-type-instead.rs @@ -9,8 +9,8 @@ // except according to those terms. // error-pattern: implement a trait or new type instead -pub impl Option { - fn foo(&self) { } +impl Option { + pub fn foo(&self) { } } fn main() { } diff --git a/src/test/compile-fail/use-after-move-self-based-on-type.rs b/src/test/compile-fail/use-after-move-self-based-on-type.rs index e4e5802fafb6f..5b4d67fb0cef2 100644 --- a/src/test/compile-fail/use-after-move-self-based-on-type.rs +++ b/src/test/compile-fail/use-after-move-self-based-on-type.rs @@ -6,13 +6,13 @@ impl Drop for S { fn finalize(&self) {} } -pub impl S { - fn foo(self) -> int { +impl S { + pub fn foo(self) -> int { self.bar(); return self.x; //~ ERROR use of moved value: `self` } - fn bar(self) {} + pub fn bar(self) {} } fn main() { diff --git a/src/test/compile-fail/use-after-move-self.rs b/src/test/compile-fail/use-after-move-self.rs index 4750a5fbd2ddc..c38f4821b881e 100644 --- a/src/test/compile-fail/use-after-move-self.rs +++ b/src/test/compile-fail/use-after-move-self.rs @@ -2,13 +2,13 @@ struct S { x: ~int } -pub impl S { - fn foo(self) -> int { +impl S { + pub fn foo(self) -> int { self.bar(); return *self.x; //~ ERROR use of moved value: `self` } - fn bar(self) {} + pub fn bar(self) {} } fn main() { diff --git a/src/test/run-pass/anon-trait-static-method.rs b/src/test/run-pass/anon-trait-static-method.rs index 10462fa4abb22..843e9436229ec 100644 --- a/src/test/run-pass/anon-trait-static-method.rs +++ b/src/test/run-pass/anon-trait-static-method.rs @@ -12,8 +12,8 @@ struct Foo { x: int } -pub impl Foo { - fn new() -> Foo { +impl Foo { + pub fn new() -> Foo { Foo { x: 3 } } } diff --git a/src/test/run-pass/auto-ref-newtype.rs b/src/test/run-pass/auto-ref-newtype.rs index 26ef339daf562..8adc2cfd57190 100644 --- a/src/test/run-pass/auto-ref-newtype.rs +++ b/src/test/run-pass/auto-ref-newtype.rs @@ -13,8 +13,8 @@ struct Foo(uint); -pub impl Foo { - fn len(&self) -> uint { **self } +impl Foo { + pub fn len(&self) -> uint { **self } } pub fn main() { diff --git a/src/test/run-pass/autoderef-and-borrow-method-receiver.rs b/src/test/run-pass/autoderef-and-borrow-method-receiver.rs index 2bc6df4703042..b00d8980c69fe 100644 --- a/src/test/run-pass/autoderef-and-borrow-method-receiver.rs +++ b/src/test/run-pass/autoderef-and-borrow-method-receiver.rs @@ -12,8 +12,8 @@ struct Foo { x: int, } -pub impl Foo { - fn f(&const self) {} +impl Foo { + pub fn f(&const self) {} } fn g(x: &mut Foo) { diff --git a/src/test/run-pass/borrowck-nested-calls.rs b/src/test/run-pass/borrowck-nested-calls.rs index 4494f5f2fa337..50e9b6d81b517 100644 --- a/src/test/run-pass/borrowck-nested-calls.rs +++ b/src/test/run-pass/borrowck-nested-calls.rs @@ -14,10 +14,10 @@ struct Foo {a: uint, b: uint} -pub impl Foo { - fn inc_a(&mut self, v: uint) { self.a += v; } +impl Foo { + pub fn inc_a(&mut self, v: uint) { self.a += v; } - fn next_b(&mut self) -> uint { + pub fn next_b(&mut self) -> uint { let b = self.b; self.b += 1; b diff --git a/src/test/run-pass/borrowck-wg-borrow-mut-to-imm-3.rs b/src/test/run-pass/borrowck-wg-borrow-mut-to-imm-3.rs index 212bc62a98afc..284db7af66be3 100644 --- a/src/test/run-pass/borrowck-wg-borrow-mut-to-imm-3.rs +++ b/src/test/run-pass/borrowck-wg-borrow-mut-to-imm-3.rs @@ -2,8 +2,8 @@ struct Wizard { spells: ~[&'static str] } -pub impl Wizard { - fn cast(&mut self) { +impl Wizard { + pub fn cast(&mut self) { for self.spells.each |&spell| { println(spell); } diff --git a/src/test/run-pass/class-cast-to-trait-multiple-types.rs b/src/test/run-pass/class-cast-to-trait-multiple-types.rs index c41a8c2b284bd..361cafc40a962 100644 --- a/src/test/run-pass/class-cast-to-trait-multiple-types.rs +++ b/src/test/run-pass/class-cast-to-trait-multiple-types.rs @@ -20,7 +20,7 @@ struct dog { volume : @mut int, } -pub impl dog { +impl dog { priv fn bark(&self) -> int { debug!("Woof %u %d", *self.barks, *self.volume); *self.barks += 1u; @@ -57,11 +57,11 @@ impl noisy for cat { fn speak(&self) -> int { self.meow() as int } } -pub impl cat { - fn meow_count(&self) -> uint { *self.meows } +impl cat { + pub fn meow_count(&self) -> uint { *self.meows } } -priv impl cat { +impl cat { fn meow(&self) -> uint { debug!("Meow"); *self.meows += 1u; diff --git a/src/test/run-pass/class-cast-to-trait.rs b/src/test/run-pass/class-cast-to-trait.rs index a15afa60c7522..a8ff906121687 100644 --- a/src/test/run-pass/class-cast-to-trait.rs +++ b/src/test/run-pass/class-cast-to-trait.rs @@ -22,8 +22,8 @@ impl noisy for cat { fn speak(&mut self) { self.meow(); } } -pub impl cat { - fn eat(&mut self) -> bool { +impl cat { + pub fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -36,7 +36,7 @@ pub impl cat { } } -priv impl cat { +impl cat { fn meow(&mut self) { error!("Meow"); self.meows += 1u; diff --git a/src/test/run-pass/class-exports.rs b/src/test/run-pass/class-exports.rs index eb2c26478b693..11ef86035c56f 100644 --- a/src/test/run-pass/class-exports.rs +++ b/src/test/run-pass/class-exports.rs @@ -21,8 +21,8 @@ mod kitty { name: ~str, } - pub impl cat { - fn get_name(&self) -> ~str { self.name.clone() } + impl cat { + pub fn get_name(&self) -> ~str { self.name.clone() } } pub fn cat(in_name: ~str) -> cat { diff --git a/src/test/run-pass/class-impl-very-parameterized-trait.rs b/src/test/run-pass/class-impl-very-parameterized-trait.rs index b8ea3bec21a65..88686bcdbfa35 100644 --- a/src/test/run-pass/class-impl-very-parameterized-trait.rs +++ b/src/test/run-pass/class-impl-very-parameterized-trait.rs @@ -37,10 +37,10 @@ struct cat { name : T, } -pub impl cat { - fn speak(&mut self) { self.meow(); } +impl cat { + pub fn speak(&mut self) { self.meow(); } - fn eat(&mut self) -> bool { + pub fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -113,20 +113,20 @@ impl Map for cat { fn swap(&mut self, _k: int, _v: T) -> Option { fail!() } } -pub impl cat { - fn get<'a>(&'a self, k: &int) -> &'a T { +impl cat { + pub fn get<'a>(&'a self, k: &int) -> &'a T { match self.find(k) { Some(v) => { v } None => { fail!("epic fail"); } } } - fn new(in_x: int, in_y: int, in_name: T) -> cat { + pub fn new(in_x: int, in_y: int, in_name: T) -> cat { cat{meows: in_x, how_hungry: in_y, name: in_name } } } -priv impl cat { +impl cat { fn meow(&mut self) { self.meows += 1; error!("Meow %d", self.meows); diff --git a/src/test/run-pass/class-implement-trait-cross-crate.rs b/src/test/run-pass/class-implement-trait-cross-crate.rs index 724f9a0f7b11e..70020b395103d 100644 --- a/src/test/run-pass/class-implement-trait-cross-crate.rs +++ b/src/test/run-pass/class-implement-trait-cross-crate.rs @@ -22,8 +22,8 @@ struct cat { name : ~str, } -pub impl cat { - fn eat(&mut self) -> bool { +impl cat { + pub fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -40,7 +40,7 @@ impl noisy for cat { fn speak(&mut self) { self.meow(); } } -priv impl cat { +impl cat { fn meow(&mut self) { error!("Meow"); self.meows += 1u; diff --git a/src/test/run-pass/class-implement-traits.rs b/src/test/run-pass/class-implement-traits.rs index d8ba7320b95bd..8c7c62ce27e3f 100644 --- a/src/test/run-pass/class-implement-traits.rs +++ b/src/test/run-pass/class-implement-traits.rs @@ -23,7 +23,7 @@ struct cat { name : ~str, } -priv impl cat { +impl cat { fn meow(&mut self) { error!("Meow"); self.meows += 1u; @@ -33,8 +33,8 @@ priv impl cat { } } -pub impl cat { - fn eat(&mut self) -> bool { +impl cat { + pub fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; diff --git a/src/test/run-pass/class-methods.rs b/src/test/run-pass/class-methods.rs index fa358f4b132aa..fca128b9a9735 100644 --- a/src/test/run-pass/class-methods.rs +++ b/src/test/run-pass/class-methods.rs @@ -14,9 +14,9 @@ struct cat { how_hungry : int, } -pub impl cat { - fn speak(&mut self) { self.meows += 1u; } - fn meow_count(&mut self) -> uint { self.meows } +impl cat { + pub fn speak(&mut self) { self.meows += 1u; } + pub fn meow_count(&mut self) -> uint { self.meows } } fn cat(in_x: uint, in_y: int) -> cat { diff --git a/src/test/run-pass/class-poly-methods.rs b/src/test/run-pass/class-poly-methods.rs index f538eb054a67f..0201501bc7c64 100644 --- a/src/test/run-pass/class-poly-methods.rs +++ b/src/test/run-pass/class-poly-methods.rs @@ -15,11 +15,11 @@ struct cat { how_hungry : int, } -pub impl cat { - fn speak(&mut self, stuff: ~[T]) { +impl cat { + pub fn speak(&mut self, stuff: ~[T]) { self.meows += stuff.len(); } - fn meow_count(&mut self) -> uint { self.meows } + pub fn meow_count(&mut self) -> uint { self.meows } } fn cat(in_x : uint, in_y : int, in_info: ~[U]) -> cat { diff --git a/src/test/run-pass/class-separate-impl.rs b/src/test/run-pass/class-separate-impl.rs index 1952520d018bc..f31b702519349 100644 --- a/src/test/run-pass/class-separate-impl.rs +++ b/src/test/run-pass/class-separate-impl.rs @@ -16,10 +16,10 @@ struct cat { name : ~str, } -pub impl cat { - fn speak(&mut self) { self.meow(); } +impl cat { + pub fn speak(&mut self) { self.meow(); } - fn eat(&mut self) -> bool { + pub fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -32,7 +32,7 @@ pub impl cat { } } -priv impl cat { +impl cat { fn meow(&mut self) { error!("Meow"); self.meows += 1u; diff --git a/src/test/run-pass/class-typarams.rs b/src/test/run-pass/class-typarams.rs index 29354c54d8ba0..8533add411949 100644 --- a/src/test/run-pass/class-typarams.rs +++ b/src/test/run-pass/class-typarams.rs @@ -14,9 +14,9 @@ struct cat { how_hungry : int, } -pub impl cat { - fn speak(&mut self) { self.meows += 1u; } - fn meow_count(&mut self) -> uint { self.meows } +impl cat { + pub fn speak(&mut self) { self.meows += 1u; } + pub fn meow_count(&mut self) -> uint { self.meows } } fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/run-pass/classes-simple-method.rs b/src/test/run-pass/classes-simple-method.rs index 9de1066ec5701..f27738cf4216e 100644 --- a/src/test/run-pass/classes-simple-method.rs +++ b/src/test/run-pass/classes-simple-method.rs @@ -14,8 +14,8 @@ struct cat { how_hungry : int, } -pub impl cat { - fn speak(&mut self) {} +impl cat { + pub fn speak(&mut self) {} } fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/run-pass/classes.rs b/src/test/run-pass/classes.rs index e3f9b65108349..89d89d116a38d 100644 --- a/src/test/run-pass/classes.rs +++ b/src/test/run-pass/classes.rs @@ -17,10 +17,10 @@ struct cat { name : ~str, } -pub impl cat { - fn speak(&mut self) { self.meow(); } +impl cat { + pub fn speak(&mut self) { self.meow(); } - fn eat(&mut self) -> bool { + pub fn eat(&mut self) -> bool { if self.how_hungry > 0 { error!("OM NOM NOM"); self.how_hungry -= 2; @@ -32,7 +32,7 @@ pub impl cat { } } -priv impl cat { +impl cat { fn meow(&mut self) { error!("Meow"); self.meows += 1u; diff --git a/src/test/run-pass/coerce-reborrow-imm-ptr-rcvr.rs b/src/test/run-pass/coerce-reborrow-imm-ptr-rcvr.rs index 6c78cd250ddd8..438c70c6583f4 100644 --- a/src/test/run-pass/coerce-reborrow-imm-ptr-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-imm-ptr-rcvr.rs @@ -2,8 +2,8 @@ struct SpeechMaker { speeches: uint } -pub impl SpeechMaker { - fn how_many(&const self) -> uint { self.speeches } +impl SpeechMaker { + pub fn how_many(&const self) -> uint { self.speeches } } fn foo(speaker: &const SpeechMaker) -> uint { diff --git a/src/test/run-pass/coerce-reborrow-mut-ptr-rcvr.rs b/src/test/run-pass/coerce-reborrow-mut-ptr-rcvr.rs index fd47c262d6a7d..3adb805581dd0 100644 --- a/src/test/run-pass/coerce-reborrow-mut-ptr-rcvr.rs +++ b/src/test/run-pass/coerce-reborrow-mut-ptr-rcvr.rs @@ -2,8 +2,8 @@ struct SpeechMaker { speeches: uint } -pub impl SpeechMaker { - fn talk(&mut self) { +impl SpeechMaker { + pub fn talk(&mut self) { self.speeches += 1; } } diff --git a/src/test/run-pass/const-enum-byref-self.rs b/src/test/run-pass/const-enum-byref-self.rs index c4e1ea727e47e..098a001cfcde9 100644 --- a/src/test/run-pass/const-enum-byref-self.rs +++ b/src/test/run-pass/const-enum-byref-self.rs @@ -11,8 +11,8 @@ enum E { V, VV(int) } static C: E = V; -pub impl E { - fn method(&self) { +impl E { + pub fn method(&self) { match *self { V => {} VV(*) => fail!() diff --git a/src/test/run-pass/explicit-self-closures.rs b/src/test/run-pass/explicit-self-closures.rs index e019140d1a015..eb62c8a91d242 100644 --- a/src/test/run-pass/explicit-self-closures.rs +++ b/src/test/run-pass/explicit-self-closures.rs @@ -14,11 +14,11 @@ struct Box { x: uint } -pub impl Box { - fn set_many(&mut self, xs: &[uint]) { +impl Box { + pub fn set_many(&mut self, xs: &[uint]) { for xs.each |x| { self.x = *x; } } - fn set_many2(@mut self, xs: &[uint]) { + pub fn set_many2(@mut self, xs: &[uint]) { for xs.each |x| { self.x = *x; } } } diff --git a/src/test/run-pass/explicit-self-generic.rs b/src/test/run-pass/explicit-self-generic.rs index c500201d65de3..80e16af922847 100644 --- a/src/test/run-pass/explicit-self-generic.rs +++ b/src/test/run-pass/explicit-self-generic.rs @@ -30,8 +30,8 @@ fn linear_map() -> HashMap { size: 0}) } -pub impl HashMap { - fn len(&mut self) -> uint { +impl HashMap { + pub fn len(&mut self) -> uint { self.size } } diff --git a/src/test/run-pass/explicit-self.rs b/src/test/run-pass/explicit-self.rs index 6ae99f64cf069..25e404021619e 100644 --- a/src/test/run-pass/explicit-self.rs +++ b/src/test/run-pass/explicit-self.rs @@ -26,10 +26,10 @@ fn compute_area(shape: &shape) -> float { } } -pub impl shape { +impl shape { // self is in the implicit self region - fn select<'r, T>(&self, threshold: float, - a: &'r T, b: &'r T) -> &'r T { + pub fn select<'r, T>(&self, threshold: float, a: &'r T, b: &'r T) + -> &'r T { if compute_area(self) > threshold {a} else {b} } } @@ -54,12 +54,12 @@ fn thing(x: A) -> thing { } } -pub impl thing { - fn foo(@self) -> int { *self.x.a } - fn bar(~self) -> int { *self.x.a } - fn quux(&self) -> int { *self.x.a } - fn baz<'a>(&'a self) -> &'a A { &self.x } - fn spam(self) -> int { *self.x.a } +impl thing { + pub fn foo(@self) -> int { *self.x.a } + pub fn bar(~self) -> int { *self.x.a } + pub fn quux(&self) -> int { *self.x.a } + pub fn baz<'a>(&'a self) -> &'a A { &self.x } + pub fn spam(self) -> int { *self.x.a } } trait Nus { fn f(&self); } diff --git a/src/test/run-pass/impl-implicit-trait.rs b/src/test/run-pass/impl-implicit-trait.rs index 10a5661a32468..a33fc4f2e7402 100644 --- a/src/test/run-pass/impl-implicit-trait.rs +++ b/src/test/run-pass/impl-implicit-trait.rs @@ -13,8 +13,8 @@ enum option_ { some_(T), } -pub impl option_ { - fn foo(&self) -> bool { true } +impl option_ { + pub fn foo(&self) -> bool { true } } enum option__ { @@ -22,8 +22,8 @@ enum option__ { some__(int) } -pub impl option__ { - fn foo(&self) -> bool { true } +impl option__ { + pub fn foo(&self) -> bool { true } } pub fn main() { diff --git a/src/test/run-pass/issue-2311-2.rs b/src/test/run-pass/issue-2311-2.rs index 5f47e7ccb9f79..155f9cff29629 100644 --- a/src/test/run-pass/issue-2311-2.rs +++ b/src/test/run-pass/issue-2311-2.rs @@ -13,8 +13,8 @@ struct foo { x: A, } -pub impl foo { - fn bar>(&self, c: C) -> B { +impl foo { + pub fn bar>(&self, c: C) -> B { fail!(); } } diff --git a/src/test/run-pass/issue-2312.rs b/src/test/run-pass/issue-2312.rs index f3aa96298f0c5..59ca02f50fc3a 100644 --- a/src/test/run-pass/issue-2312.rs +++ b/src/test/run-pass/issue-2312.rs @@ -14,8 +14,8 @@ trait clam { } struct foo(int); -pub impl foo { - fn bar>(&self, c: C) -> B { fail!(); } +impl foo { + pub fn bar>(&self, c: C) -> B { fail!(); } } pub fn main() { } diff --git a/src/test/run-pass/issue-2445-b.rs b/src/test/run-pass/issue-2445-b.rs index 55c72a41a6a32..c26038afd764f 100644 --- a/src/test/run-pass/issue-2445-b.rs +++ b/src/test/run-pass/issue-2445-b.rs @@ -12,8 +12,8 @@ struct c1 { x: T, } -pub impl c1 { - fn f1(&self, x: int) { +impl c1 { + pub fn f1(&self, x: int) { } } @@ -23,8 +23,8 @@ fn c1(x: T) -> c1 { } } -pub impl c1 { - fn f2(&self, x: int) { +impl c1 { + pub fn f2(&self, x: int) { } } diff --git a/src/test/run-pass/issue-2445.rs b/src/test/run-pass/issue-2445.rs index 5a82b53401571..64d6072597876 100644 --- a/src/test/run-pass/issue-2445.rs +++ b/src/test/run-pass/issue-2445.rs @@ -12,8 +12,8 @@ struct c1 { x: T, } -pub impl c1 { - fn f1(&self, x: T) {} +impl c1 { + pub fn f1(&self, x: T) {} } fn c1(x: T) -> c1 { @@ -22,8 +22,8 @@ fn c1(x: T) -> c1 { } } -pub impl c1 { - fn f2(&self, x: T) {} +impl c1 { + pub fn f2(&self, x: T) {} } diff --git a/src/test/run-pass/issue-2487-a.rs b/src/test/run-pass/issue-2487-a.rs index 388160e538acd..5e5fb70bcd4a5 100644 --- a/src/test/run-pass/issue-2487-a.rs +++ b/src/test/run-pass/issue-2487-a.rs @@ -17,8 +17,8 @@ impl Drop for socket { fn finalize(&self) {} } -pub impl socket { - fn set_identity(&self) { +impl socket { + pub fn set_identity(&self) { do closure { setsockopt_bytes(self.sock.clone()) } diff --git a/src/test/run-pass/issue-2502.rs b/src/test/run-pass/issue-2502.rs index 34eb591b73aa4..c26fef49be735 100644 --- a/src/test/run-pass/issue-2502.rs +++ b/src/test/run-pass/issue-2502.rs @@ -12,8 +12,8 @@ struct font<'self> { fontbuf: &'self ~[u8], } -pub impl<'self> font<'self> { - fn buf(&self) -> &'self ~[u8] { +impl<'self> font<'self> { + pub fn buf(&self) -> &'self ~[u8] { self.fontbuf } } diff --git a/src/test/run-pass/issue-2718.rs b/src/test/run-pass/issue-2718.rs index 4dad60225dd90..d51470cf9bd91 100644 --- a/src/test/run-pass/issue-2718.rs +++ b/src/test/run-pass/issue-2718.rs @@ -172,8 +172,8 @@ pub mod pipes { } } - pub impl send_packet { - fn unwrap(&mut self) -> *packet { + impl send_packet { + pub fn unwrap(&mut self) -> *packet { util::replace(&mut self.p, None).unwrap() } } @@ -202,8 +202,8 @@ pub mod pipes { } } - pub impl recv_packet { - fn unwrap(&mut self) -> *packet { + impl recv_packet { + pub fn unwrap(&mut self) -> *packet { util::replace(&mut self.p, None).unwrap() } } diff --git a/src/test/run-pass/issue-3220.rs b/src/test/run-pass/issue-3220.rs index 9ecc46c17ac34..9cc5e5910435f 100644 --- a/src/test/run-pass/issue-3220.rs +++ b/src/test/run-pass/issue-3220.rs @@ -19,7 +19,10 @@ fn thing() -> thing { x: 0 } } -pub impl thing { fn f(self) {} } + +impl thing { + pub fn f(self) {} +} pub fn main() { let z = thing(); diff --git a/src/test/run-pass/issue-3447.rs b/src/test/run-pass/issue-3447.rs index 20355238e3ebb..711dfd3778b5b 100644 --- a/src/test/run-pass/issue-3447.rs +++ b/src/test/run-pass/issue-3447.rs @@ -13,8 +13,8 @@ struct list<'self, T> { next: Option<@mut list<'self, T>> } -pub impl<'self, T> list<'self, T>{ - fn addEnd(&mut self, element: &'self T) { +impl<'self, T> list<'self, T>{ + pub fn addEnd(&mut self, element: &'self T) { let newList = list { element: element, next: None diff --git a/src/test/run-pass/issue-3753.rs b/src/test/run-pass/issue-3753.rs index 825a49e91b08e..a94abe04fded2 100644 --- a/src/test/run-pass/issue-3753.rs +++ b/src/test/run-pass/issue-3753.rs @@ -24,7 +24,7 @@ pub enum Shape { Rectangle(Point, Point) } -pub impl Shape { +impl Shape { pub fn area(&self, sh: Shape) -> float { match sh { Circle(_, size) => float::consts::pi * size * size, diff --git a/src/test/run-pass/issue-3860.rs b/src/test/run-pass/issue-3860.rs index 778b2b72b13d9..0a22e8bcfd07e 100644 --- a/src/test/run-pass/issue-3860.rs +++ b/src/test/run-pass/issue-3860.rs @@ -10,8 +10,8 @@ struct Foo { x: int } -pub impl Foo { - fn stuff<'a>(&'a mut self) -> &'a mut Foo { +impl Foo { + pub fn stuff<'a>(&'a mut self) -> &'a mut Foo { return self; } } diff --git a/src/test/run-pass/issue-3904.rs b/src/test/run-pass/issue-3904.rs index 1a09a8b860f84..6b0796a1260d5 100644 --- a/src/test/run-pass/issue-3904.rs +++ b/src/test/run-pass/issue-3904.rs @@ -23,8 +23,8 @@ struct X { err: ErrPrinter } -pub impl X { - fn boom() { +impl X { + pub fn boom() { exit(self.err, "prog", "arg"); } } diff --git a/src/test/run-pass/max-min-classes.rs b/src/test/run-pass/max-min-classes.rs index 87e80568c3223..c34067c329d27 100644 --- a/src/test/run-pass/max-min-classes.rs +++ b/src/test/run-pass/max-min-classes.rs @@ -17,8 +17,8 @@ struct Foo { y: int, } -pub impl Foo { - fn sum(&self) -> int { +impl Foo { + pub fn sum(&self) -> int { self.x + self.y } } diff --git a/src/test/run-pass/move-self.rs b/src/test/run-pass/move-self.rs index 61ece52453e3a..55a7edbb679c6 100644 --- a/src/test/run-pass/move-self.rs +++ b/src/test/run-pass/move-self.rs @@ -2,12 +2,12 @@ struct S { x: ~str } -pub impl S { - fn foo(self) { +impl S { + pub fn foo(self) { self.bar(); } - fn bar(self) { + pub fn bar(self) { println(self.x); } } diff --git a/src/test/run-pass/nested-class.rs b/src/test/run-pass/nested-class.rs index 3bf4b53c18407..6ab9856c0700a 100644 --- a/src/test/run-pass/nested-class.rs +++ b/src/test/run-pass/nested-class.rs @@ -13,8 +13,8 @@ pub fn main() { i: int, } - pub impl b { - fn do_stuff(&self) -> int { return 37; } + impl b { + pub fn do_stuff(&self) -> int { return 37; } } fn b(i:int) -> b { diff --git a/src/test/run-pass/private-class-field.rs b/src/test/run-pass/private-class-field.rs index 44a56333a780b..868cbbfa80212 100644 --- a/src/test/run-pass/private-class-field.rs +++ b/src/test/run-pass/private-class-field.rs @@ -14,8 +14,8 @@ struct cat { how_hungry : int, } -pub impl cat { - fn meow_count(&mut self) -> uint { self.meows } +impl cat { + pub fn meow_count(&mut self) -> uint { self.meows } } fn cat(in_x : uint, in_y : int) -> cat { diff --git a/src/test/run-pass/private-method.rs b/src/test/run-pass/private-method.rs index 2b811a69db0bf..de07cc7c4d018 100644 --- a/src/test/run-pass/private-method.rs +++ b/src/test/run-pass/private-method.rs @@ -16,14 +16,14 @@ struct cat { how_hungry : int, } -pub impl cat { - fn play(&mut self) { +impl cat { + pub fn play(&mut self) { self.meows += 1u; self.nap(); } } -priv impl cat { +impl cat { fn nap(&mut self) { for uint::range(1u, 10u) |_i| { }} } diff --git a/src/test/run-pass/reflect-visit-data.rs b/src/test/run-pass/reflect-visit-data.rs index e218d3326eeef..f4ccd038afee8 100644 --- a/src/test/run-pass/reflect-visit-data.rs +++ b/src/test/run-pass/reflect-visit-data.rs @@ -33,29 +33,29 @@ fn align(size: uint, align: uint) -> uint { struct ptr_visit_adaptor(Inner); -pub impl ptr_visit_adaptor { +impl ptr_visit_adaptor { #[inline(always)] - fn bump(&self, sz: uint) { + pub fn bump(&self, sz: uint) { do self.inner.move_ptr() |p| { ((p as uint) + sz) as *c_void }; } #[inline(always)] - fn align(&self, a: uint) { + pub fn align(&self, a: uint) { do self.inner.move_ptr() |p| { align(p as uint, a) as *c_void }; } #[inline(always)] - fn align_to(&self) { + pub fn align_to(&self) { self.align(sys::min_align_of::()); } #[inline(always)] - fn bump_past(&self) { + pub fn bump_past(&self) { self.bump(sys::size_of::()); } @@ -485,14 +485,14 @@ struct Stuff { vals: ~[~str] } -pub impl my_visitor { - fn get(&self, f: &fn(T)) { +impl my_visitor { + pub fn get(&self, f: &fn(T)) { unsafe { f(*(self.ptr1 as *T)); } } - fn visit_inner(&self, inner: *TyDesc) -> bool { + pub fn visit_inner(&self, inner: *TyDesc) -> bool { unsafe { let u = my_visitor(**self); let v = ptr_visit_adaptor::(Inner {inner: u}); diff --git a/src/test/run-pass/regions-expl-self.rs b/src/test/run-pass/regions-expl-self.rs index 174b9a206ccdf..58c13885e036c 100644 --- a/src/test/run-pass/regions-expl-self.rs +++ b/src/test/run-pass/regions-expl-self.rs @@ -14,8 +14,8 @@ struct Foo { f: uint } -pub impl Foo { - fn foo<'a>(&'a self) {} +impl Foo { + pub fn foo<'a>(&'a self) {} } -pub fn main() {} \ No newline at end of file +pub fn main() {} diff --git a/src/test/run-pass/resource-destruct.rs b/src/test/run-pass/resource-destruct.rs index b69248e327710..c240c6708a4ac 100644 --- a/src/test/run-pass/resource-destruct.rs +++ b/src/test/run-pass/resource-destruct.rs @@ -21,8 +21,8 @@ impl Drop for shrinky_pointer { } } -pub impl shrinky_pointer { - fn look_at(&self) -> int { return **(self.i); } +impl shrinky_pointer { + pub fn look_at(&self) -> int { return **(self.i); } } fn shrinky_pointer(i: @@mut int) -> shrinky_pointer {