diff --git a/src/cargo/cargo.rs b/src/cargo/cargo.rs
index 0ac7cf008744..443d4dda020c 100644
--- a/src/cargo/cargo.rs
+++ b/src/cargo/cargo.rs
@@ -11,7 +11,7 @@ import result::{ok, err};
import io::writer_util;
import std::{map, json, tempfile, term, sort, getopts};
import map::hashmap;
-import json::to_str;
+import to_str::to_str;
import getopts::{optflag, optopt, opt_present};
type package = {
@@ -535,7 +535,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
versions: ~[]
};
- alt src.packages.position(|pkg| pkg.uuid == uuid ) {
+ alt vec::position(src.packages, |pkg| pkg.uuid == uuid) {
some(idx) {
src.packages[idx] = newpkg;
log(debug, ~" updated package: " + src.name + ~"/" + name);
diff --git a/src/libcore/core.rs b/src/libcore/core.rs
index c70be013fb74..07dac5270b0c 100644
--- a/src/libcore/core.rs
+++ b/src/libcore/core.rs
@@ -5,12 +5,15 @@
import option::{some, none};
import option = option::option;
import path = path::path;
-import str::extensions;
import tuple::extensions;
+import str::{extensions, str_slice, unique_str};
import vec::extensions;
+import vec::{const_vector, copyable_vector, immutable_vector};
+import vec::{immutable_copyable_vector, iter_trait_extensions, vec_concat};
+import iter::{base_iter, extended_iter, copyable_iter, times};
import option::extensions;
import option_iter::extensions;
-import ptr::extensions;
+import ptr::{extensions, ptr};
import rand::extensions;
import result::extensions;
import int::{num, times};
@@ -26,11 +29,18 @@ import u64::{num, times};
import float::num;
import f32::num;
import f64::num;
+import num::num;
export path, option, some, none, unreachable;
export extensions;
// The following exports are the extension impls for numeric types
export num, times;
+// The following exports are the common traits
+export str_slice, unique_str;
+export const_vector, copyable_vector, immutable_vector;
+export immutable_copyable_vector, iter_trait_extensions, vec_concat;
+export base_iter, copyable_iter, extended_iter;
+export ptr;
// Export the log levels as global constants. Higher levels mean
// more-verbosity. Error is the bottom level, default logging level is
diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs
index 983d1b9968f3..d9fb3dae846a 100644
--- a/src/libcore/int-template.rs
+++ b/src/libcore/int-template.rs
@@ -233,6 +233,7 @@ fn test_ifaces() {
#[test]
fn test_times() {
+ import iter::times;
let ten = 10 as T;
let mut accum = 0;
for ten.times { accum += 1; }
@@ -243,5 +244,6 @@ fn test_times() {
#[should_fail]
#[ignore(cfg(windows))]
fn test_times_negative() {
+ import iter::times;
for (-10).times { log(error, ~"nope!"); }
}
diff --git a/src/libcore/iter-trait.rs b/src/libcore/iter-trait.rs
index 80b81753af81..e31824d066dc 100644
--- a/src/libcore/iter-trait.rs
+++ b/src/libcore/iter-trait.rs
@@ -8,6 +8,9 @@ export extensions;
impl extensions of iter::base_iter for IMPL_T {
fn each(blk: fn(A) -> bool) { EACH(self, blk) }
fn size_hint() -> option { SIZE_HINT(self) }
+}
+
+impl extensions of iter::extended_iter for IMPL_T {
fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) }
fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index e2a321cde23d..2e0c778cd5a4 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -3,6 +3,16 @@ iface base_iter {
fn size_hint() -> option;
}
+trait extended_iter {
+ fn eachi(blk: fn(uint, A) -> bool);
+ fn all(blk: fn(A) -> bool) -> bool;
+ fn any(blk: fn(A) -> bool) -> bool;
+ fn foldl(+b0: B, blk: fn(B, A) -> B) -> B;
+ fn contains(x: A) -> bool;
+ fn count(x: A) -> uint;
+ fn position(f: fn(A) -> bool) -> option;
+}
+
iface times {
fn times(it: fn() -> bool);
}
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index dabfa04ef245..2b9794987ee0 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -92,6 +92,7 @@ pure fn iter(opt: option, f: fn(T)) {
alt opt { none { } some(t) { f(t); } }
}
+#[inline(always)]
pure fn unwrap(-opt: option) -> T {
/*!
* Moves a value out of an option type and returns it.
diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs
index 13a90ac7ae56..33f5fe958a50 100644
--- a/src/libcore/pipes.rs
+++ b/src/libcore/pipes.rs
@@ -578,7 +578,11 @@ impl of selectable for pipes::port {
type shared_chan = arc::exclusive>;
-impl chan for shared_chan {
+trait send_on_shared_chan {
+ fn send(+x: T);
+}
+
+impl chan of send_on_shared_chan for shared_chan {
fn send(+x: T) {
let mut xx = some(x);
do self.with |_c, chan| {
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index 178a68a1c654..ba98fb3c119f 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -14,6 +14,7 @@ export memset;
export buf_len;
export position;
export extensions;
+export ptr;
import libc::{c_void, size_t};
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index cc5ae30268df..7e83e7aa0ee7 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -106,7 +106,9 @@ export
escape_unicode,
unsafe,
- extensions;
+ extensions,
+ str_slice,
+ unique_str;
#[abi = "cdecl"]
extern mod rustrt {
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index 7c4244efd9bd..4f35f1a8756e 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -278,6 +278,7 @@ fn to_str_radix17() {
#[test]
fn test_times() {
+ import iter::times;
let ten = 10 as T;
let mut accum = 0;
for ten.times { accum += 1; }
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index 60e3373fdbe0..1dd4ef5ae43e 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -85,6 +85,12 @@ export unpack_const_slice;
export unsafe;
export u8;
export extensions;
+export const_vector;
+export copyable_vector;
+export immutable_vector;
+export immutable_copyable_vector;
+export iter_trait_extensions;
+export vec_concat;
#[abi = "cdecl"]
extern mod rustrt {
@@ -179,11 +185,12 @@ pure fn len(&&v: &[const T]) -> uint {
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
-pure fn from_fn(n_elts: uint, op: init_op) -> ~[T] {
+pure fn from_fn(n_elts: uint, op: init_op) -> ~[T] {
let mut v = ~[];
unchecked{reserve(v, n_elts);}
let mut i: uint = 0u;
- while i < n_elts unsafe { push(v, op(i)); i += 1u; }
+ while i < n_elts unsafe { ref_set(v, i, op(i)); i += 1u; }
+ unsafe { unsafe::set_len(v, n_elts); }
ret v;
}
@@ -197,8 +204,9 @@ pure fn from_elem(n_elts: uint, t: T) -> ~[T] {
let mut v = ~[];
unchecked{reserve(v, n_elts)}
let mut i: uint = 0u;
- unsafe { // because push is impure
- while i < n_elts { push(v, t); i += 1u; }
+ unsafe { // because ref_set is unsafe
+ while i < n_elts { ref_set(v, i, t); i += 1u; }
+ unsafe { unsafe::set_len(v, n_elts); }
}
ret v;
}
@@ -468,6 +476,16 @@ unsafe fn ref(v: &[const T], i: uint) -> T {
unpack_slice(v, |p, _len| *ptr::offset(p, i))
}
+#[inline(always)]
+unsafe fn ref_set(v: &[mut T], i: uint, +val: T) {
+ let mut box = some(val);
+ do unpack_mut_slice(v) |p, _len| {
+ let mut box2 = none;
+ box2 <-> box;
+ rusti::move_val_init(*ptr::mut_offset(p, i), option::unwrap(box2));
+ }
+}
+
#[inline(always)]
fn push_all(&v: ~[const T], rhs: &[const T]) {
reserve(v, v.len() + rhs.len());
@@ -1591,6 +1609,9 @@ mod u8 {
impl extensions/& of iter::base_iter for &[const A] {
fn each(blk: fn(A) -> bool) { each(self, blk) }
fn size_hint() -> option { some(len(self)) }
+}
+
+impl extensions/& of iter::extended_iter for &[const A] {
fn eachi(blk: fn(uint, A) -> bool) { iter::eachi(self, blk) }
fn all(blk: fn(A) -> bool) -> bool { iter::all(self, blk) }
fn any(blk: fn(A) -> bool) -> bool { iter::any(self, blk) }
@@ -1599,6 +1620,7 @@ impl extensions/& of iter::base_iter for &[const A] {
}
fn contains(x: A) -> bool { iter::contains(self, x) }
fn count(x: A) -> uint { iter::count(self, x) }
+ fn position(f: fn(A) -> bool) -> option { iter::position(self, f) }
}
trait iter_trait_extensions {
diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs
index 65fcd0a59ca0..2df720e6fe1b 100644
--- a/src/libstd/arena.rs
+++ b/src/libstd/arena.rs
@@ -6,7 +6,12 @@ import list;
import list::{list, cons, nil};
type chunk = {data: ~[u8], mut fill: uint};
-type arena = {mut chunks: @list<@chunk>};
+
+type arena_ = {mut chunks: @list<@chunk>};
+
+enum arena {
+ arena_(arena_)
+}
fn chunk(size: uint) -> @chunk {
let mut v = ~[];
@@ -15,7 +20,7 @@ fn chunk(size: uint) -> @chunk {
}
fn arena_with_size(initial_size: uint) -> arena {
- ret {mut chunks: @cons(chunk(initial_size), @nil)};
+ ret arena_({mut chunks: @cons(chunk(initial_size), @nil)});
}
fn arena() -> arena {
diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs
index 5f833a20e326..07f578901fdb 100644
--- a/src/libstd/ebml.rs
+++ b/src/libstd/ebml.rs
@@ -155,7 +155,11 @@ fn doc_as_i32(d: doc) -> i32 { doc_as_u32(d) as i32 }
fn doc_as_i64(d: doc) -> i64 { doc_as_u64(d) as i64 }
// ebml writing
-type writer = {writer: io::writer, mut size_positions: ~[uint]};
+type writer_ = {writer: io::writer, mut size_positions: ~[uint]};
+
+enum writer {
+ writer_(writer_)
+}
fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
alt size {
@@ -187,7 +191,7 @@ fn write_vuint(w: io::writer, n: uint) {
fn writer(w: io::writer) -> writer {
let size_positions: ~[uint] = ~[];
- ret {writer: w, mut size_positions: size_positions};
+ ret writer_({writer: w, mut size_positions: size_positions});
}
// FIXME (#2741): Provide a function to write the standard ebml header.
@@ -311,9 +315,12 @@ enum ebml_serializer_tag {
es_label // Used only when debugging
}
-impl serializer of serialization::serializer for ebml::writer {
- fn emit_nil() {}
+trait serializer_priv {
+ fn _emit_tagged_uint(t: ebml_serializer_tag, v: uint);
+ fn _emit_label(label: ~str);
+}
+impl serializer of serializer_priv for ebml::writer {
// used internally to emit things like the vector length and so on
fn _emit_tagged_uint(t: ebml_serializer_tag, v: uint) {
assert v <= 0xFFFF_FFFF_u;
@@ -329,6 +336,10 @@ impl serializer of serialization::serializer for ebml::writer {
// try and check failures more quickly.
if debug { self.wr_tagged_str(es_label as uint, label) }
}
+}
+
+impl serializer of serialization::serializer for ebml::writer {
+ fn emit_nil() {}
fn emit_uint(v: uint) { self.wr_tagged_u64(es_uint as uint, v as u64); }
fn emit_u64(v: u64) { self.wr_tagged_u64(es_u64 as uint, v); }
@@ -383,14 +394,18 @@ impl serializer of serialization::serializer for ebml::writer {
fn emit_tup_elt(_idx: uint, f: fn()) { f() }
}
-type ebml_deserializer = {mut parent: ebml::doc,
- mut pos: uint};
+type ebml_deserializer_ = {mut parent: ebml::doc,
+ mut pos: uint};
-fn ebml_deserializer(d: ebml::doc) -> ebml_deserializer {
- {mut parent: d, mut pos: d.start}
+enum ebml_deserializer {
+ ebml_deserializer_(ebml_deserializer_)
}
-impl deserializer of serialization::deserializer for ebml_deserializer {
+fn ebml_deserializer(d: ebml::doc) -> ebml_deserializer {
+ ebml_deserializer_({mut parent: d, mut pos: d.start})
+}
+
+impl deserializer_priv for ebml_deserializer {
fn _check_label(lbl: ~str) {
if self.pos < self.parent.end {
let {tag: r_tag, doc: r_doc} =
@@ -443,7 +458,9 @@ impl deserializer of serialization::deserializer for ebml_deserializer {
#debug["_next_uint exp_tag=%? result=%?", exp_tag, r];
ret r as uint;
}
+}
+impl deserializer of serialization::deserializer for ebml_deserializer {
fn read_nil() -> () { () }
fn read_u64() -> u64 { ebml::doc_as_u64(self.next_doc(es_u64)) }
diff --git a/src/libstd/json.rs b/src/libstd/json.rs
index f81942046265..74707e36a51a 100644
--- a/src/libstd/json.rs
+++ b/src/libstd/json.rs
@@ -8,6 +8,7 @@ import io;
import io::{reader_util, writer_util};
import map;
import map::hashmap;
+import map::map;
import core::vec::extensions;
export json;
@@ -114,13 +115,17 @@ fn to_str(j: json) -> ~str {
io::with_str_writer(|wr| to_writer(wr, j))
}
-type parser = {
+type parser_ = {
rdr: io::reader,
mut ch: char,
mut line: uint,
mut col: uint,
};
+enum parser {
+ parser_(parser_)
+}
+
impl parser for parser {
fn eof() -> bool { self.ch == -1 as char }
@@ -463,12 +468,12 @@ impl parser for parser {
/// Deserializes a json value from an io::reader
fn from_reader(rdr: io::reader) -> result {
- let parser = {
+ let parser = parser_({
rdr: rdr,
mut ch: rdr.read_char(),
mut line: 1u,
mut col: 1u,
- };
+ });
parser.parse()
}
diff --git a/src/libstd/map.rs b/src/libstd/map.rs
index 90ca5e233720..c285bc066290 100644
--- a/src/libstd/map.rs
+++ b/src/libstd/map.rs
@@ -92,13 +92,19 @@ mod chained {
absent
}
- type t = @{
+ type hashmap__ = {
mut count: uint,
mut chains: ~[mut chain],
hasher: hashfn,
eqer: eqfn
};
+ enum hashmap_ {
+ hashmap_(@hashmap__)
+ }
+
+ type t = hashmap_;
+
enum search_result {
not_found,
found_first(uint, @entry),
@@ -284,10 +290,10 @@ mod chained {
}
fn mk(hasher: hashfn, eqer: eqfn) -> t {
- let slf: t = @{mut count: 0u,
- mut chains: chains(initial_capacity),
- hasher: hasher,
- eqer: eqer};
+ let slf: t = hashmap_(@{mut count: 0u,
+ mut chains: chains(initial_capacity),
+ hasher: hasher,
+ eqer: eqer});
slf
}
}
diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs
index a78b6a5f1723..f79a95d8ab50 100644
--- a/src/libstd/net_ip.rs
+++ b/src/libstd/net_ip.rs
@@ -148,7 +148,12 @@ mod v4 {
// the simple, old style numberic representation of
// ipv4
type ipv4_rep = { a: u8, b: u8, c: u8, d:u8 };
- impl x for ipv4_rep {
+
+ trait as_unsafe_u32 {
+ unsafe fn as_u32() -> u32;
+ }
+
+ impl x of as_unsafe_u32 for ipv4_rep {
// this is pretty dastardly, i know
unsafe fn as_u32() -> u32 {
*((ptr::addr_of(self)) as *u32)
diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs
index 31b8841933bc..c7dc2d0cdab4 100644
--- a/src/libstd/net_tcp.rs
+++ b/src/libstd/net_tcp.rs
@@ -11,6 +11,7 @@ import future::extensions;
import result::*;
import libc::size_t;
import str::extensions;
+import io::{reader, writer};
// tcp interfaces
export tcp_socket;
diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs
index ba20ff88e3db..ed9cf5570ce9 100644
--- a/src/libstd/serialization.rs
+++ b/src/libstd/serialization.rs
@@ -101,13 +101,21 @@ fn read_to_vec(d: D, f: fn() -> T) -> ~[T] {
}
}
-impl serializer_helpers for S {
+trait serializer_helpers {
+ fn emit_from_vec(v: ~[T], f: fn(T));
+}
+
+impl serializer_helpers of serializer_helpers for S {
fn emit_from_vec(v: ~[T], f: fn(T)) {
emit_from_vec(self, v, f)
}
}
-impl deserializer_helpers for D {
+trait deserializer_helpers {
+ fn read_to_vec(f: fn() -> T) -> ~[T];
+}
+
+impl deserializer_helpers of deserializer_helpers for D {
fn read_to_vec(f: fn() -> T) -> ~[T] {
read_to_vec(self, f)
}
diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs
index 1d17ba0dbb47..112a55ab67d8 100644
--- a/src/libstd/smallintmap.rs
+++ b/src/libstd/smallintmap.rs
@@ -5,14 +5,19 @@
import core::option;
import core::option::{some, none};
import dvec::{dvec, extensions};
+import map::map;
// FIXME (#2347): Should not be @; there's a bug somewhere in rustc that
// requires this to be.
-type smallintmap = @{v: dvec