about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-06-29 12:02:05 -0700
committerbors <bors@rust-lang.org>2013-06-29 12:02:05 -0700
commitc86df3a65cc239fd69b9a8d628808498cdb07e0d (patch)
treeb2557de482d3c0946cd683bd92dff65a1adf15f4 /src/libstd
parent88830996d811be3ff833ba590c98f28daaf31f43 (diff)
parent3bad7129ebb13d7a4c0a7965aeb5bd536cc0f5f0 (diff)
downloadrust-c86df3a65cc239fd69b9a8d628808498cdb07e0d.tar.gz
rust-c86df3a65cc239fd69b9a8d628808498cdb07e0d.zip
auto merge of #7342 : alexcrichton/rust/assort-cleanup, r=cmr
This removes usage of `&const` throughout the standard libraries/compiler, and it removes some extraneous fields in the AST now that unique boxes always inherit their mutability.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/at_vec.rs6
-rw-r--r--src/libstd/hashmap.rs8
-rw-r--r--src/libstd/io.rs6
-rw-r--r--src/libstd/option.rs4
-rw-r--r--src/libstd/ptr.rs18
-rw-r--r--src/libstd/str.rs8
-rw-r--r--src/libstd/task/spawn.rs2
-rw-r--r--src/libstd/trie.rs8
-rw-r--r--src/libstd/vec.rs72
9 files changed, 50 insertions, 82 deletions
diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs
index 5a2f948600a..325ce097cd5 100644
--- a/src/libstd/at_vec.rs
+++ b/src/libstd/at_vec.rs
@@ -108,7 +108,7 @@ pub fn build_sized_opt<A>(size: Option<uint>,
 /// Iterates over the `rhs` vector, copying each element and appending it to the
 /// `lhs`. Afterwards, the `lhs` is then returned for use again.
 #[inline]
-pub fn append<T:Copy>(lhs: @[T], rhs: &const [T]) -> @[T] {
+pub fn append<T:Copy>(lhs: @[T], rhs: &[T]) -> @[T] {
     do build_sized(lhs.len() + rhs.len()) |push| {
         for lhs.iter().advance |x| { push(copy *x); }
         for uint::range(0, rhs.len()) |i| { push(copy rhs[i]); }
@@ -180,9 +180,9 @@ pub mod traits {
     use kinds::Copy;
     use ops::Add;
 
-    impl<'self,T:Copy> Add<&'self const [T],@[T]> for @[T] {
+    impl<'self,T:Copy> Add<&'self [T],@[T]> for @[T] {
         #[inline]
-        fn add(&self, rhs: & &'self const [T]) -> @[T] {
+        fn add(&self, rhs: & &'self [T]) -> @[T] {
             append(*self, (*rhs))
         }
     }
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs
index 7f9fb6ad938..35db229b65d 100644
--- a/src/libstd/hashmap.rs
+++ b/src/libstd/hashmap.rs
@@ -282,10 +282,10 @@ impl<K:Hash + Eq,V> HashMap<K, V> {
 
 impl<K:Hash + Eq,V> Container for HashMap<K, V> {
     /// Return the number of elements in the map
-    fn len(&const self) -> uint { self.size }
+    fn len(&self) -> uint { self.size }
 
     /// Return true if the map contains no elements
-    fn is_empty(&const self) -> bool { self.len() == 0 }
+    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl<K:Hash + Eq,V> Mutable for HashMap<K, V> {
@@ -623,10 +623,10 @@ impl<T:Hash + Eq> Eq for HashSet<T> {
 
 impl<T:Hash + Eq> Container for HashSet<T> {
     /// Return the number of elements in the set
-    fn len(&const self) -> uint { self.map.len() }
+    fn len(&self) -> uint { self.map.len() }
 
     /// Return true if the set contains no elements
-    fn is_empty(&const self) -> bool { self.map.is_empty() }
+    fn is_empty(&self) -> bool { self.map.is_empty() }
 }
 
 impl<T:Hash + Eq> Mutable for HashSet<T> {
diff --git a/src/libstd/io.rs b/src/libstd/io.rs
index 59ac58a514f..40793ff1af7 100644
--- a/src/libstd/io.rs
+++ b/src/libstd/io.rs
@@ -1152,7 +1152,7 @@ impl<W:Writer,C> Writer for Wrapper<W, C> {
 impl Writer for *libc::FILE {
     fn write(&self, v: &[u8]) {
         unsafe {
-            do vec::as_const_buf(v) |vbuf, len| {
+            do vec::as_imm_buf(v) |vbuf, len| {
                 let nout = libc::fwrite(vbuf as *c_void,
                                         1,
                                         len as size_t,
@@ -1203,9 +1203,9 @@ impl Writer for fd_t {
     fn write(&self, v: &[u8]) {
         unsafe {
             let mut count = 0u;
-            do vec::as_const_buf(v) |vbuf, len| {
+            do vec::as_imm_buf(v) |vbuf, len| {
                 while count < len {
-                    let vb = ptr::const_offset(vbuf, count) as *c_void;
+                    let vb = ptr::offset(vbuf, count) as *c_void;
                     let nout = libc::write(*self, vb, len as size_t);
                     if nout < 0 as ssize_t {
                         error!("error writing buffer");
diff --git a/src/libstd/option.rs b/src/libstd/option.rs
index 12ae2abd4a1..64381231258 100644
--- a/src/libstd/option.rs
+++ b/src/libstd/option.rs
@@ -121,13 +121,13 @@ impl<T> Option<T> {
 
     /// Returns true if the option equals `none`
     #[inline]
-    pub fn is_none(&const self) -> bool {
+    pub fn is_none(&self) -> bool {
         match *self { None => true, Some(_) => false }
     }
 
     /// Returns true if the option contains some value
     #[inline]
-    pub fn is_some(&const self) -> bool { !self.is_none() }
+    pub fn is_some(&self) -> bool { !self.is_none() }
 
     /// Update an optional value by optionally running its content through a
     /// function that returns an option.
diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs
index 7f89d454be1..473f56ddd79 100644
--- a/src/libstd/ptr.rs
+++ b/src/libstd/ptr.rs
@@ -232,9 +232,9 @@ pub unsafe fn array_each<T>(arr: **T, cb: &fn(*T)) {
 
 #[allow(missing_doc)]
 pub trait RawPtr<T> {
-    fn is_null(&const self) -> bool;
-    fn is_not_null(&const self) -> bool;
-    unsafe fn to_option(&const self) -> Option<&T>;
+    fn is_null(&self) -> bool;
+    fn is_not_null(&self) -> bool;
+    unsafe fn to_option(&self) -> Option<&T>;
     fn offset(&self, count: uint) -> Self;
 }
 
@@ -242,11 +242,11 @@ pub trait RawPtr<T> {
 impl<T> RawPtr<T> for *T {
     /// Returns true if the pointer is equal to the null pointer.
     #[inline]
-    fn is_null(&const self) -> bool { is_null(*self) }
+    fn is_null(&self) -> bool { is_null(*self) }
 
     /// Returns true if the pointer is not equal to the null pointer.
     #[inline]
-    fn is_not_null(&const self) -> bool { is_not_null(*self) }
+    fn is_not_null(&self) -> bool { is_not_null(*self) }
 
     ///
     /// Returns `None` if the pointer is null, or else returns the value wrapped
@@ -259,7 +259,7 @@ impl<T> RawPtr<T> for *T {
     /// be pointing to invalid memory.
     ///
     #[inline]
-    unsafe fn to_option(&const self) -> Option<&T> {
+    unsafe fn to_option(&self) -> Option<&T> {
         if self.is_null() { None } else {
             Some(cast::transmute(*self))
         }
@@ -274,11 +274,11 @@ impl<T> RawPtr<T> for *T {
 impl<T> RawPtr<T> for *mut T {
     /// Returns true if the pointer is equal to the null pointer.
     #[inline]
-    fn is_null(&const self) -> bool { is_null(*self) }
+    fn is_null(&self) -> bool { is_null(*self) }
 
     /// Returns true if the pointer is not equal to the null pointer.
     #[inline]
-    fn is_not_null(&const self) -> bool { is_not_null(*self) }
+    fn is_not_null(&self) -> bool { is_not_null(*self) }
 
     ///
     /// Returns `None` if the pointer is null, or else returns the value wrapped
@@ -291,7 +291,7 @@ impl<T> RawPtr<T> for *mut T {
     /// be pointing to invalid memory.
     ///
     #[inline]
-    unsafe fn to_option(&const self) -> Option<&T> {
+    unsafe fn to_option(&self) -> Option<&T> {
         if self.is_null() { None } else {
             Some(cast::transmute(*self))
         }
diff --git a/src/libstd/str.rs b/src/libstd/str.rs
index e47800d70c6..a06d858e424 100644
--- a/src/libstd/str.rs
+++ b/src/libstd/str.rs
@@ -569,7 +569,7 @@ Section: Misc
 */
 
 /// Determines if a vector of bytes contains valid UTF-8
-pub fn is_utf8(v: &const [u8]) -> bool {
+pub fn is_utf8(v: &[u8]) -> bool {
     let mut i = 0u;
     let total = v.len();
     while i < total {
@@ -815,7 +815,7 @@ pub mod raw {
     }
 
     /// Create a Rust string from a *u8 buffer of the given length
-    pub unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str {
+    pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str {
         let mut v: ~[u8] = vec::with_capacity(len + 1);
         vec::as_mut_buf(v, |vbuf, _len| {
             ptr::copy_memory(vbuf, buf as *u8, len)
@@ -838,8 +838,8 @@ pub mod raw {
     }
 
     /// Converts a vector of bytes to a new owned string.
-    pub unsafe fn from_bytes(v: &const [u8]) -> ~str {
-        do vec::as_const_buf(v) |buf, len| {
+    pub unsafe fn from_bytes(v: &[u8]) -> ~str {
+        do vec::as_imm_buf(v) |buf, len| {
             from_buf_len(buf, len)
         }
     }
diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs
index c932a9660c2..190485a720a 100644
--- a/src/libstd/task/spawn.rs
+++ b/src/libstd/task/spawn.rs
@@ -129,7 +129,7 @@ type TaskGroupInner<'self> = &'self mut Option<TaskGroupData>;
 
 // A taskgroup is 'dead' when nothing can cause it to fail; only members can.
 fn taskgroup_is_dead(tg: &TaskGroupData) -> bool {
-    (&const tg.members).is_empty()
+    tg.members.is_empty()
 }
 
 // A list-like structure by which taskgroups keep track of all ancestor groups
diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs
index b9b03ea5661..8ce02d59ab1 100644
--- a/src/libstd/trie.rs
+++ b/src/libstd/trie.rs
@@ -35,11 +35,11 @@ pub struct TrieMap<T> {
 impl<T> Container for TrieMap<T> {
     /// Return the number of elements in the map
     #[inline]
-    fn len(&const self) -> uint { self.length }
+    fn len(&self) -> uint { self.length }
 
     /// Return true if the map contains no elements
     #[inline]
-    fn is_empty(&const self) -> bool { self.len() == 0 }
+    fn is_empty(&self) -> bool { self.len() == 0 }
 }
 
 impl<T> Mutable for TrieMap<T> {
@@ -179,11 +179,11 @@ pub struct TrieSet {
 impl Container for TrieSet {
     /// Return the number of elements in the set
     #[inline]
-    fn len(&const self) -> uint { self.map.len() }
+    fn len(&self) -> uint { self.map.len() }
 
     /// Return true if the set contains no elements
     #[inline]
-    fn is_empty(&const self) -> bool { self.map.is_empty() }
+    fn is_empty(&self) -> bool { self.map.is_empty() }
 }
 
 impl Mutable for TrieSet {
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 4e7943f7cfd..4196fbac0be 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -64,7 +64,7 @@ pub mod rustrt {
 }
 
 /// Returns true if two vectors have the same length
-pub fn same_length<T, U>(xs: &const [T], ys: &const [U]) -> bool {
+pub fn same_length<T, U>(xs: &[T], ys: &[U]) -> bool {
     xs.len() == ys.len()
 }
 
@@ -350,10 +350,7 @@ pub fn dedup<T:Eq>(v: &mut ~[T]) {
         if v.len() < 1 { return; }
         let mut last_written = 0;
         let mut next_to_read = 1;
-        do as_const_buf(*v) |p, ln| {
-            // We have a mutable reference to v, so we can make arbitrary
-            // changes. (cf. push and pop)
-            let p = p as *mut T;
+        do as_mut_buf(*v) |p, ln| {
             // last_written < next_to_read <= ln
             while next_to_read < ln {
                 // last_written < next_to_read < ln
@@ -384,7 +381,7 @@ pub fn dedup<T:Eq>(v: &mut ~[T]) {
 /// Iterates over the `rhs` vector, copying each element and appending it to the
 /// `lhs`. Afterwards, the `lhs` is then returned for use again.
 #[inline]
-pub fn append<T:Copy>(lhs: ~[T], rhs: &const [T]) -> ~[T] {
+pub fn append<T:Copy>(lhs: ~[T], rhs: &[T]) -> ~[T] {
     let mut v = lhs;
     v.push_all(rhs);
     v
@@ -831,7 +828,7 @@ pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
 /**
  * Convert two vectors to a vector of pairs, by reference. As zip().
  */
-pub fn zip_slice<T:Copy,U:Copy>(v: &const [T], u: &const [U])
+pub fn zip_slice<T:Copy,U:Copy>(v: &[T], u: &[U])
         -> ~[(T, U)] {
     let mut zipped = ~[];
     let sz = v.len();
@@ -893,7 +890,7 @@ pub fn reverse<T>(v: &mut [T]) {
 }
 
 /// Returns a vector with the order of elements reversed
-pub fn reversed<T:Copy>(v: &const [T]) -> ~[T] {
+pub fn reversed<T:Copy>(v: &[T]) -> ~[T] {
     let mut rs: ~[T] = ~[];
     let mut i = v.len();
     if i == 0 { return (rs); } else { i -= 1; }
@@ -1003,16 +1000,6 @@ pub fn as_imm_buf<T,U>(s: &[T],
     }
 }
 
-/// Similar to `as_imm_buf` but passing a `*const T`
-#[inline]
-pub fn as_const_buf<T,U>(s: &const [T], f: &fn(*const T, uint) -> U) -> U {
-    unsafe {
-        let v : *(*const T,uint) = transmute(&s);
-        let (buf,len) = *v;
-        f(buf, len / sys::nonzero_size_of::<T>())
-    }
-}
-
 /// Similar to `as_imm_buf` but passing a `*mut T`
 #[inline]
 pub fn as_mut_buf<T,U>(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U {
@@ -1198,25 +1185,25 @@ pub mod traits {
     use ops::Add;
     use vec::append;
 
-    impl<'self,T:Copy> Add<&'self const [T],~[T]> for ~[T] {
+    impl<'self,T:Copy> Add<&'self [T],~[T]> for ~[T] {
         #[inline]
-        fn add(&self, rhs: & &'self const [T]) -> ~[T] {
+        fn add(&self, rhs: & &'self [T]) -> ~[T] {
             append(copy *self, (*rhs))
         }
     }
 }
 
-impl<'self, T> Container for &'self const [T] {
+impl<'self, T> Container for &'self [T] {
     /// Returns true if a vector contains no elements
     #[inline]
     fn is_empty(&self) -> bool {
-        as_const_buf(*self, |_p, len| len == 0u)
+        as_imm_buf(*self, |_p, len| len == 0u)
     }
 
     /// Returns the length of a vector
     #[inline]
     fn len(&self) -> uint {
-        as_const_buf(*self, |_p, len| len)
+        as_imm_buf(*self, |_p, len| len)
     }
 }
 
@@ -1224,13 +1211,13 @@ impl<T> Container for ~[T] {
     /// Returns true if a vector contains no elements
     #[inline]
     fn is_empty(&self) -> bool {
-        as_const_buf(*self, |_p, len| len == 0u)
+        as_imm_buf(*self, |_p, len| len == 0u)
     }
 
     /// Returns the length of a vector
     #[inline]
     fn len(&self) -> uint {
-        as_const_buf(*self, |_p, len| len)
+        as_imm_buf(*self, |_p, len| len)
     }
 }
 
@@ -1843,7 +1830,7 @@ impl<T> Mutable for ~[T] {
 
 #[allow(missing_doc)]
 pub trait OwnedCopyableVector<T:Copy> {
-    fn push_all(&mut self, rhs: &const [T]);
+    fn push_all(&mut self, rhs: &[T]);
     fn grow(&mut self, n: uint, initval: &T);
     fn grow_set(&mut self, index: uint, initval: &T, val: T);
 }
@@ -1860,7 +1847,7 @@ impl<T:Copy> OwnedCopyableVector<T> for ~[T] {
     /// assert!(a == ~[1, 2, 3, 4]);
     /// ~~~
     #[inline]
-    fn push_all(&mut self, rhs: &const [T]) {
+    fn push_all(&mut self, rhs: &[T]) {
         let new_len = self.len() + rhs.len();
         self.reserve(new_len);
 
@@ -2017,7 +2004,7 @@ pub mod raw {
     use ptr;
     use sys;
     use unstable::intrinsics;
-    use vec::{UnboxedVecRepr, as_const_buf, as_mut_buf, with_capacity};
+    use vec::{UnboxedVecRepr, as_imm_buf, as_mut_buf, with_capacity};
     use util;
 
     /// The internal representation of a (boxed) vector
@@ -2067,15 +2054,6 @@ pub mod raw {
 
     /** see `to_ptr()` */
     #[inline]
-    pub fn to_const_ptr<T>(v: &const [T]) -> *const T {
-        unsafe {
-            let repr: **SliceRepr = transmute(&v);
-            transmute(&((**repr).data))
-        }
-    }
-
-    /** see `to_ptr()` */
-    #[inline]
     pub fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
         unsafe {
             let repr: **SliceRepr = transmute(&v);
@@ -2113,8 +2091,8 @@ pub mod raw {
      * Unchecked vector indexing.
      */
     #[inline]
-    pub unsafe fn get<T:Copy>(v: &const [T], i: uint) -> T {
-        as_const_buf(v, |p, _len| copy *ptr::const_offset(p, i))
+    pub unsafe fn get<T:Copy>(v: &[T], i: uint) -> T {
+        as_imm_buf(v, |p, _len| copy *ptr::offset(p, i))
     }
 
     /**
@@ -2156,13 +2134,13 @@ pub mod raw {
       * may overlap.
       */
     #[inline]
-    pub unsafe fn copy_memory<T>(dst: &mut [T], src: &const [T],
+    pub unsafe fn copy_memory<T>(dst: &mut [T], src: &[T],
                                  count: uint) {
         assert!(dst.len() >= count);
         assert!(src.len() >= count);
 
         do as_mut_buf(dst) |p_dst, _len_dst| {
-            do as_const_buf(src) |p_src, _len_src| {
+            do as_imm_buf(src) |p_src, _len_src| {
                 ptr::copy_memory(p_dst, p_src, count)
             }
         }
@@ -2238,7 +2216,7 @@ pub mod bytes {
       * may overlap.
       */
     #[inline]
-    pub fn copy_memory(dst: &mut [u8], src: &const [u8], count: uint) {
+    pub fn copy_memory(dst: &mut [u8], src: &[u8], count: uint) {
         // Bound checks are done at vec::raw::copy_memory.
         unsafe { vec::raw::copy_memory(dst, src, count) }
     }
@@ -3691,16 +3669,6 @@ mod tests {
     }
 
     #[test]
-    #[ignore(windows)]
-    #[should_fail]
-    fn test_as_const_buf_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        do as_const_buf(v) |_buf, _i| {
-            fail!()
-        }
-    }
-
-    #[test]
     #[ignore(cfg(windows))]
     #[should_fail]
     fn test_as_mut_buf_fail() {