diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 60cb1b51be68..1a1aeeadeb67 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -310,3 +310,10 @@ impl extensions for dvec { do self.swap |v| { vec::reachi(v, f); v } } } + +impl extensions of ops::index for dvec { + pure fn index(&&idx: uint) -> A { + self.get_elt(idx) + } +} + diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 9b142adf165b..c56af8442f69 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1897,7 +1897,6 @@ trait unique_str { fn trim() -> self; fn trim_left() -> self; fn trim_right() -> self; - pure fn +(rhs: &str) -> self; } /// Extension methods for strings @@ -1919,6 +1918,13 @@ impl extensions of unique_str for ~str { } } +impl extensions of ops::add<&str,~str> for ~str { + #[inline(always)] + pure fn add(rhs: &str) -> ~str { + append(self, rhs) + } +} + trait str_slice { fn all(it: fn(char) -> bool) -> bool; fn any(it: fn(char) -> bool) -> bool; diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index c07dd9b8224c..a97c8f8601a0 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1299,6 +1299,13 @@ impl extensions of vec_concat for ~[T] { } } +impl extensions of ops::add<&[const T],~[T]> for ~[T] { + #[inline(always)] + pure fn add(rhs: &[const T]) -> ~[T] { + append(self, rhs) + } +} + impl extensions of vec_concat for ~[mut T] { #[inline(always)] pure fn +(rhs: &[const T]) -> ~[mut T] { @@ -1306,6 +1313,13 @@ impl extensions of vec_concat for ~[mut T] { } } +impl extensions of ops::add<&[const T],~[mut T]> for ~[mut T] { + #[inline(always)] + pure fn add(rhs: &[const T]) -> ~[mut T] { + append_mut(self, rhs) + } +} + trait const_vector { pure fn is_empty() -> bool; pure fn is_not_empty() -> bool; diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index adb7f56ef3b5..145ceba4ae53 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -239,7 +239,7 @@ trait methods { fn union(rhs: bitv) -> bool; fn intersect(rhs: bitv) -> bool; fn assign(rhs: bitv) -> bool; - fn get(i: uint) -> bool; + pure fn get(i: uint) -> bool; fn [](i: uint) -> bool; fn eq(rhs: bitv) -> bool; fn clear(); @@ -261,7 +261,7 @@ impl of methods for bitv { fn union(rhs: bitv) -> bool { union(self, rhs) } fn intersect(rhs: bitv) -> bool { intersect(self, rhs) } fn assign(rhs: bitv) -> bool { assign(self, rhs) } - fn get(i: uint) -> bool { get(self, i) } + pure fn get(i: uint) -> bool { get(self, i) } fn [](i: uint) -> bool { self.get(i) } fn eq(rhs: bitv) -> bool { equal(self, rhs) } fn clear() { clear(self) } @@ -285,6 +285,12 @@ impl of methods for bitv { } } +impl extensions of ops::index for bitv { + pure fn index(&&i: uint) -> bool { + self.get(i) + } +} + impl of to_str::to_str for bitv { fn to_str() -> ~str { to_str(self) } } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index afb5f28ae087..2522c9d58763 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -314,6 +314,14 @@ mod chained { } } + impl hashmap of ops::index for t { + pure fn index(k: K) -> V { + unchecked { + self.get(k) + } + } + } + fn chains(nchains: uint) -> ~[mut chain] { ret vec::to_mut(vec::from_elem(nchains, absent)); diff --git a/src/libstd/smallintmap.rs b/src/libstd/smallintmap.rs index 02948f58fc4d..0325ef3ac2e2 100644 --- a/src/libstd/smallintmap.rs +++ b/src/libstd/smallintmap.rs @@ -35,7 +35,7 @@ fn insert(self: smallintmap, key: uint, val: T) { * Get the value for the specified key. If the key does not exist * in the map then returns none */ -fn find(self: smallintmap, key: uint) -> option { +pure fn find(self: smallintmap, key: uint) -> option { if key < self.v.len() { ret self.v.get_elt(key); } ret none::; } @@ -47,7 +47,7 @@ fn find(self: smallintmap, key: uint) -> option { * * If the key does not exist in the map */ -fn get(self: smallintmap, key: uint) -> T { +pure fn get(self: smallintmap, key: uint) -> T { alt find(self, key) { none { #error("smallintmap::get(): key not present"); fail; } some(v) { ret v; } @@ -114,6 +114,14 @@ impl of map::map for smallintmap { } } +impl extensions of ops::index for smallintmap { + pure fn index(&&key: uint) -> V { + unchecked { + get(self, key) + } + } +} + /// Cast the given smallintmap to a map::map fn as_map(s: smallintmap) -> map::map { s as map::map:: diff --git a/src/rustc/middle/trans/shape.rs b/src/rustc/middle/trans/shape.rs index 71a15b7f05ee..279709a01b95 100644 --- a/src/rustc/middle/trans/shape.rs +++ b/src/rustc/middle/trans/shape.rs @@ -16,6 +16,7 @@ import syntax::util::interner; import util::ppaux::ty_to_str; import syntax::codemap::span; import dvec::{dvec, extensions}; +import vec::extensions; import std::map::hashmap; import option::is_some;