collections: Enable IndexMut for some collections
This commit enables implementations of IndexMut for a number of collections, including Vec, RingBuf, SmallIntMap, TrieMap, TreeMap, and HashMap. At the same time this deprecates the `get_mut` methods on vectors in favor of using the indexing notation. cc #18424
This commit is contained in:
parent
18a3db6aa1
commit
1d356624a1
src
compiletest
libcollections
libcore
libgetopts
libregex
librustc
libserialize
libstd
libsync
libsyntax
libtest
@ -1013,7 +1013,7 @@ fn check_expected_errors(expected_errors: Vec<errors::ExpectedError> ,
|
||||
if prefix_matches(line, prefixes[i].as_slice()) &&
|
||||
line.contains(ee.kind.as_slice()) &&
|
||||
line.contains(ee.msg.as_slice()) {
|
||||
*found_flags.get_mut(i) = true;
|
||||
found_flags[i] = true;
|
||||
was_expected = true;
|
||||
break;
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ impl Bitv {
|
||||
let used_bits = bitv.nbits % u32::BITS;
|
||||
if init && used_bits != 0 {
|
||||
let largest_used_word = (bitv.nbits + u32::BITS - 1) / u32::BITS - 1;
|
||||
*bitv.storage.get_mut(largest_used_word) &= (1 << used_bits) - 1;
|
||||
bitv.storage[largest_used_word] &= (1 << used_bits) - 1;
|
||||
}
|
||||
|
||||
bitv
|
||||
@ -297,8 +297,9 @@ impl Bitv {
|
||||
let w = i / u32::BITS;
|
||||
let b = i % u32::BITS;
|
||||
let flag = 1 << b;
|
||||
*self.storage.get_mut(w) = if x { self.storage[w] | flag }
|
||||
else { self.storage[w] & !flag };
|
||||
let val = if x { self.storage[w] | flag }
|
||||
else { self.storage[w] & !flag };
|
||||
self.storage[w] = val;
|
||||
}
|
||||
|
||||
/// Sets all bits to 1.
|
||||
@ -617,7 +618,7 @@ impl Bitv {
|
||||
self.storage.truncate(word_len);
|
||||
if len % u32::BITS > 0 {
|
||||
let mask = (1 << len % u32::BITS) - 1;
|
||||
*self.storage.get_mut(word_len - 1) &= mask;
|
||||
self.storage[word_len - 1] &= mask;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -681,15 +682,15 @@ impl Bitv {
|
||||
let overhang = self.nbits % u32::BITS; // # of already-used bits
|
||||
let mask = !((1 << overhang) - 1); // e.g. 5 unused bits => 111110....0
|
||||
if value {
|
||||
*self.storage.get_mut(old_last_word) |= mask;
|
||||
self.storage[old_last_word] |= mask;
|
||||
} else {
|
||||
*self.storage.get_mut(old_last_word) &= !mask;
|
||||
self.storage[old_last_word] &= !mask;
|
||||
}
|
||||
}
|
||||
// Fill in words after the old tail word
|
||||
let stop_idx = cmp::min(self.storage.len(), new_nwords);
|
||||
for idx in range(old_last_word + 1, stop_idx) {
|
||||
*self.storage.get_mut(idx) = full_value;
|
||||
self.storage[idx] = full_value;
|
||||
}
|
||||
// Allocate new words, if needed
|
||||
if new_nwords > self.storage.len() {
|
||||
@ -700,7 +701,7 @@ impl Bitv {
|
||||
if value {
|
||||
let tail_word = new_nwords - 1;
|
||||
let used_bits = new_nbits % u32::BITS;
|
||||
*self.storage.get_mut(tail_word) &= (1 << used_bits) - 1;
|
||||
self.storage[tail_word] &= (1 << used_bits) - 1;
|
||||
}
|
||||
}
|
||||
// Adjust internal bit count
|
||||
@ -728,7 +729,7 @@ impl Bitv {
|
||||
let ret = self.get(self.nbits - 1);
|
||||
// If we are unusing a whole word, make sure it is zeroed out
|
||||
if self.nbits % u32::BITS == 1 {
|
||||
*self.storage.get_mut(self.nbits / u32::BITS) = 0;
|
||||
self.storage[self.nbits / u32::BITS] = 0;
|
||||
}
|
||||
self.nbits -= 1;
|
||||
ret
|
||||
@ -1184,7 +1185,7 @@ impl BitvSet {
|
||||
for (i, w) in other_words {
|
||||
let old = self_bitv.storage[i];
|
||||
let new = f(old, w);
|
||||
*self_bitv.storage.get_mut(i) = new;
|
||||
self_bitv.storage[i] = new;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -690,6 +690,12 @@ impl<K: Ord, V> Index<K, V> for BTreeMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: Ord, V> IndexMut<K, V> for BTreeMap<K, V> {
|
||||
fn index_mut(&mut self, key: &K) -> &mut V {
|
||||
self.find_mut(key).expect("no entry found for key")
|
||||
}
|
||||
}
|
||||
|
||||
/// Genericises over how to get the correct type of iterator from the correct type
|
||||
/// of Node ownership.
|
||||
trait Traverse<N> {
|
||||
|
@ -71,7 +71,7 @@
|
||||
//! let mut pq = PriorityQueue::new();
|
||||
//!
|
||||
//! // We're at `start`, with a zero cost
|
||||
//! *dist.get_mut(start) = 0u;
|
||||
//! dist[start] = 0u;
|
||||
//! pq.push(State { cost: 0u, position: start });
|
||||
//!
|
||||
//! // Examine the frontier with lower cost nodes first (min-heap)
|
||||
@ -96,7 +96,7 @@
|
||||
//! if next.cost < dist[next.position] {
|
||||
//! pq.push(next);
|
||||
//! // Relaxation, we have now found a better way
|
||||
//! *dist.get_mut(next.position) = next.cost;
|
||||
//! dist[next.position] = next.cost;
|
||||
//! }
|
||||
//! }
|
||||
//! }
|
||||
@ -330,7 +330,7 @@ impl<T: Ord> PriorityQueue<T> {
|
||||
None => { None }
|
||||
Some(mut item) => {
|
||||
if !self.is_empty() {
|
||||
swap(&mut item, self.data.get_mut(0));
|
||||
swap(&mut item, &mut self.data[0]);
|
||||
self.siftdown(0);
|
||||
}
|
||||
Some(item)
|
||||
@ -378,7 +378,7 @@ impl<T: Ord> PriorityQueue<T> {
|
||||
/// ```
|
||||
pub fn push_pop(&mut self, mut item: T) -> T {
|
||||
if !self.is_empty() && *self.top().unwrap() > item {
|
||||
swap(&mut item, self.data.get_mut(0));
|
||||
swap(&mut item, &mut self.data[0]);
|
||||
self.siftdown(0);
|
||||
}
|
||||
item
|
||||
@ -402,7 +402,7 @@ impl<T: Ord> PriorityQueue<T> {
|
||||
/// ```
|
||||
pub fn replace(&mut self, mut item: T) -> Option<T> {
|
||||
if !self.is_empty() {
|
||||
swap(&mut item, self.data.get_mut(0));
|
||||
swap(&mut item, &mut self.data[0]);
|
||||
self.siftdown(0);
|
||||
Some(item)
|
||||
} else {
|
||||
@ -462,26 +462,26 @@ impl<T: Ord> PriorityQueue<T> {
|
||||
// compared to using swaps, which involves twice as many moves.
|
||||
fn siftup(&mut self, start: uint, mut pos: uint) {
|
||||
unsafe {
|
||||
let new = replace(self.data.get_mut(pos), zeroed());
|
||||
let new = replace(&mut self.data[pos], zeroed());
|
||||
|
||||
while pos > start {
|
||||
let parent = (pos - 1) >> 1;
|
||||
if new > self.data[parent] {
|
||||
let x = replace(self.data.get_mut(parent), zeroed());
|
||||
ptr::write(self.data.get_mut(pos), x);
|
||||
let x = replace(&mut self.data[parent], zeroed());
|
||||
ptr::write(&mut self.data[pos], x);
|
||||
pos = parent;
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
ptr::write(self.data.get_mut(pos), new);
|
||||
ptr::write(&mut self.data[pos], new);
|
||||
}
|
||||
}
|
||||
|
||||
fn siftdown_range(&mut self, mut pos: uint, end: uint) {
|
||||
unsafe {
|
||||
let start = pos;
|
||||
let new = replace(self.data.get_mut(pos), zeroed());
|
||||
let new = replace(&mut self.data[pos], zeroed());
|
||||
|
||||
let mut child = 2 * pos + 1;
|
||||
while child < end {
|
||||
@ -489,13 +489,13 @@ impl<T: Ord> PriorityQueue<T> {
|
||||
if right < end && !(self.data[child] > self.data[right]) {
|
||||
child = right;
|
||||
}
|
||||
let x = replace(self.data.get_mut(child), zeroed());
|
||||
ptr::write(self.data.get_mut(pos), x);
|
||||
let x = replace(&mut self.data[child], zeroed());
|
||||
ptr::write(&mut self.data[pos], x);
|
||||
pos = child;
|
||||
child = 2 * pos + 1;
|
||||
}
|
||||
|
||||
ptr::write(self.data.get_mut(pos), new);
|
||||
ptr::write(&mut self.data[pos], new);
|
||||
self.siftup(start, pos);
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ impl<T> Deque<T> for RingBuf<T> {
|
||||
|
||||
/// Returns a mutable reference to the first element in the `RingBuf`.
|
||||
fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> {
|
||||
if self.nelts > 0 { Some(self.get_mut(0)) } else { None }
|
||||
if self.nelts > 0 { Some(&mut self[0]) } else { None }
|
||||
}
|
||||
|
||||
/// Returns a reference to the last element in the `RingBuf`.
|
||||
@ -69,13 +69,13 @@ impl<T> Deque<T> for RingBuf<T> {
|
||||
/// Returns a mutable reference to the last element in the `RingBuf`.
|
||||
fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
|
||||
let nelts = self.nelts;
|
||||
if nelts > 0 { Some(self.get_mut(nelts - 1)) } else { None }
|
||||
if nelts > 0 { Some(&mut self[nelts - 1]) } else { None }
|
||||
}
|
||||
|
||||
/// Removes and returns the first element in the `RingBuf`, or `None` if it
|
||||
/// is empty.
|
||||
fn pop_front(&mut self) -> Option<T> {
|
||||
let result = self.elts.get_mut(self.lo).take();
|
||||
let result = self.elts[self.lo].take();
|
||||
if result.is_some() {
|
||||
self.lo = (self.lo + 1u) % self.elts.len();
|
||||
self.nelts -= 1u;
|
||||
@ -91,7 +91,7 @@ impl<T> Deque<T> for RingBuf<T> {
|
||||
if self.lo == 0u {
|
||||
self.lo = self.elts.len() - 1u;
|
||||
} else { self.lo -= 1u; }
|
||||
*self.elts.get_mut(self.lo) = Some(t);
|
||||
self.elts[self.lo] = Some(t);
|
||||
self.nelts += 1u;
|
||||
}
|
||||
}
|
||||
@ -102,14 +102,14 @@ impl<T> MutableSeq<T> for RingBuf<T> {
|
||||
grow(self.nelts, &mut self.lo, &mut self.elts);
|
||||
}
|
||||
let hi = self.raw_index(self.nelts);
|
||||
*self.elts.get_mut(hi) = Some(t);
|
||||
self.elts[hi] = Some(t);
|
||||
self.nelts += 1u;
|
||||
}
|
||||
fn pop(&mut self) -> Option<T> {
|
||||
if self.nelts > 0 {
|
||||
self.nelts -= 1;
|
||||
let hi = self.raw_index(self.nelts);
|
||||
self.elts.get_mut(hi).take()
|
||||
self.elts[hi].take()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -140,6 +140,7 @@ impl<T> RingBuf<T> {
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # #![allow(deprecated)]
|
||||
/// use std::collections::RingBuf;
|
||||
///
|
||||
/// let mut buf = RingBuf::new();
|
||||
@ -149,12 +150,9 @@ impl<T> RingBuf<T> {
|
||||
/// *buf.get_mut(1) = 7;
|
||||
/// assert_eq!(buf[1], 7);
|
||||
/// ```
|
||||
#[deprecated = "use indexing instead: `buf[index] = value`"]
|
||||
pub fn get_mut<'a>(&'a mut self, i: uint) -> &'a mut T {
|
||||
let idx = self.raw_index(i);
|
||||
match *self.elts.get_mut(idx) {
|
||||
None => panic!(),
|
||||
Some(ref mut v) => v
|
||||
}
|
||||
&mut self[i]
|
||||
}
|
||||
|
||||
/// Swaps elements at indices `i` and `j`.
|
||||
@ -466,13 +464,16 @@ impl<A> Index<uint, A> for RingBuf<A> {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
|
||||
/*impl<A> IndexMut<uint, A> for RingBuf<A> {
|
||||
impl<A> IndexMut<uint, A> for RingBuf<A> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut A {
|
||||
self.get_mut(*index)
|
||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut A {
|
||||
let idx = self.raw_index(*i);
|
||||
match *(&mut self.elts[idx]) {
|
||||
None => panic!(),
|
||||
Some(ref mut v) => v
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
impl<A> FromIterator<A> for RingBuf<A> {
|
||||
fn from_iter<T: Iterator<A>>(iterator: T) -> RingBuf<A> {
|
||||
|
@ -100,7 +100,7 @@ impl<V> MutableMap<uint, V> for SmallIntMap<V> {
|
||||
/// Returns a mutable reference to the value corresponding to the key.
|
||||
fn find_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut V> {
|
||||
if *key < self.v.len() {
|
||||
match *self.v.get_mut(*key) {
|
||||
match *self.v.index_mut(key) {
|
||||
Some(ref mut value) => Some(value),
|
||||
None => None
|
||||
}
|
||||
@ -118,7 +118,7 @@ impl<V> MutableMap<uint, V> for SmallIntMap<V> {
|
||||
if len <= key {
|
||||
self.v.grow_fn(key - len + 1, |_| None);
|
||||
}
|
||||
*self.v.get_mut(key) = Some(value);
|
||||
self.v[key] = Some(value);
|
||||
!exists
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@ impl<V> MutableMap<uint, V> for SmallIntMap<V> {
|
||||
if *key >= self.v.len() {
|
||||
return None;
|
||||
}
|
||||
self.v.get_mut(*key).take()
|
||||
self.v[*key].take()
|
||||
}
|
||||
}
|
||||
|
||||
@ -405,13 +405,12 @@ impl<V> Index<uint, V> for SmallIntMap<V> {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
|
||||
/*impl<V> IndexMut<uint, V> for SmallIntMap<V> {
|
||||
impl<V> IndexMut<uint, V> for SmallIntMap<V> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut V {
|
||||
self.find_mut(i).expect("key not present")
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
macro_rules! iterator {
|
||||
(impl $name:ident -> $elem:ty, $($getter:ident),+) => {
|
||||
|
@ -692,17 +692,17 @@ pub trait StrAllocating: Str {
|
||||
for (i, sc) in me.chars().enumerate() {
|
||||
|
||||
let mut current = i;
|
||||
*dcol.get_mut(0) = current + 1;
|
||||
dcol[0] = current + 1;
|
||||
|
||||
for (j, tc) in t.chars().enumerate() {
|
||||
|
||||
let next = dcol[j + 1];
|
||||
|
||||
if sc == tc {
|
||||
*dcol.get_mut(j + 1) = current;
|
||||
dcol[j + 1] = current;
|
||||
} else {
|
||||
*dcol.get_mut(j + 1) = cmp::min(current, next);
|
||||
*dcol.get_mut(j + 1) = cmp::min(dcol[j + 1], dcol[j]) + 1;
|
||||
dcol[j + 1] = cmp::min(current, next);
|
||||
dcol[j + 1] = cmp::min(dcol[j + 1], dcol[j]) + 1;
|
||||
}
|
||||
|
||||
current = next;
|
||||
|
@ -257,12 +257,12 @@ impl<K: Ord, V> Index<K, V> for TreeMap<K, V> {
|
||||
}
|
||||
}
|
||||
|
||||
/*impl<K: Ord, V> IndexMut<K, V> for TreeMap<K, V> {
|
||||
impl<K: Ord, V> IndexMut<K, V> for TreeMap<K, V> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, i: &K) -> &'a mut V {
|
||||
self.find_mut(i).expect("no entry found for key")
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
impl<K: Ord, V> TreeMap<K, V> {
|
||||
/// Creates an empty `TreeMap`.
|
||||
|
@ -515,13 +515,12 @@ impl<T> Index<uint, T> for TrieMap<T> {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
|
||||
/*impl<T> IndexMut<uint, T> for TrieMap<T> {
|
||||
impl<T> IndexMut<uint, T> for TrieMap<T> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut T {
|
||||
self.find_mut(i).expect("key not present")
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/// A set implemented as a radix trie.
|
||||
///
|
||||
|
@ -46,7 +46,7 @@ use slice::{Items, MutItems};
|
||||
/// assert_eq!(vec.pop(), Some(2));
|
||||
/// assert_eq!(vec.len(), 1);
|
||||
///
|
||||
/// *vec.get_mut(0) = 7i;
|
||||
/// vec[0] = 7i;
|
||||
/// assert_eq!(vec[0], 7);
|
||||
///
|
||||
/// vec.push_all([1, 2, 3]);
|
||||
@ -414,11 +414,10 @@ impl<T> Index<uint,T> for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T> IndexMut<uint,T> for Vec<T> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
|
||||
self.get_mut(*index)
|
||||
&mut self.as_mut_slice()[*index]
|
||||
}
|
||||
}
|
||||
|
||||
@ -712,14 +711,6 @@ impl<T> Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Deprecated, use `.extend(other.into_iter())`
|
||||
#[inline]
|
||||
#[deprecated = "use .extend(other.into_iter())"]
|
||||
#[cfg(stage0)]
|
||||
pub fn push_all_move(&mut self, other: Vec<T>) {
|
||||
self.extend(other.into_iter());
|
||||
}
|
||||
|
||||
/// Returns a mutable slice of the elements of `self`.
|
||||
///
|
||||
/// # Example
|
||||
@ -799,12 +790,13 @@ impl<T> Vec<T> {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # #![allow(deprecated)]
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// *vec.get_mut(1) = 4;
|
||||
/// assert_eq!(vec, vec![1i, 4, 3]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "this is likely to be moved to actual indexing"]
|
||||
#[deprecated = "use `foo[index] = bar` instead"]
|
||||
pub fn get_mut<'a>(&'a mut self, index: uint) -> &'a mut T {
|
||||
&mut self.as_mut_slice()[index]
|
||||
}
|
||||
|
@ -57,107 +57,10 @@ pub struct TyDesc {
|
||||
// Called when a value of type `T` is no longer needed
|
||||
pub drop_glue: GlueFn,
|
||||
|
||||
// Called by reflection visitor to visit a value of type `T`
|
||||
#[cfg(stage0)]
|
||||
pub visit_glue: GlueFn,
|
||||
|
||||
// Name corresponding to the type
|
||||
pub name: &'static str,
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[lang="opaque"]
|
||||
pub enum Opaque { }
|
||||
|
||||
#[cfg(stage0)]
|
||||
pub type Disr = u64;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[lang="ty_visitor"]
|
||||
pub trait TyVisitor {
|
||||
fn visit_bot(&mut self) -> bool;
|
||||
fn visit_nil(&mut self) -> bool;
|
||||
fn visit_bool(&mut self) -> bool;
|
||||
|
||||
fn visit_int(&mut self) -> bool;
|
||||
fn visit_i8(&mut self) -> bool;
|
||||
fn visit_i16(&mut self) -> bool;
|
||||
fn visit_i32(&mut self) -> bool;
|
||||
fn visit_i64(&mut self) -> bool;
|
||||
|
||||
fn visit_uint(&mut self) -> bool;
|
||||
fn visit_u8(&mut self) -> bool;
|
||||
fn visit_u16(&mut self) -> bool;
|
||||
fn visit_u32(&mut self) -> bool;
|
||||
fn visit_u64(&mut self) -> bool;
|
||||
|
||||
fn visit_f32(&mut self) -> bool;
|
||||
fn visit_f64(&mut self) -> bool;
|
||||
|
||||
fn visit_char(&mut self) -> bool;
|
||||
|
||||
fn visit_estr_slice(&mut self) -> bool;
|
||||
|
||||
fn visit_box(&mut self, mtbl: uint, inner: *const TyDesc) -> bool;
|
||||
fn visit_uniq(&mut self, mtbl: uint, inner: *const TyDesc) -> bool;
|
||||
fn visit_ptr(&mut self, mtbl: uint, inner: *const TyDesc) -> bool;
|
||||
fn visit_rptr(&mut self, mtbl: uint, inner: *const TyDesc) -> bool;
|
||||
|
||||
fn visit_evec_slice(&mut self, mtbl: uint, inner: *const TyDesc) -> bool;
|
||||
fn visit_evec_fixed(&mut self, n: uint, sz: uint, align: uint,
|
||||
inner: *const TyDesc) -> bool;
|
||||
|
||||
fn visit_enter_rec(&mut self, n_fields: uint,
|
||||
sz: uint, align: uint) -> bool;
|
||||
fn visit_rec_field(&mut self, i: uint, name: &str,
|
||||
mtbl: uint, inner: *const TyDesc) -> bool;
|
||||
fn visit_leave_rec(&mut self, n_fields: uint,
|
||||
sz: uint, align: uint) -> bool;
|
||||
|
||||
fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint,
|
||||
sz: uint, align: uint) -> bool;
|
||||
fn visit_class_field(&mut self, i: uint, name: &str, named: bool,
|
||||
mtbl: uint, inner: *const TyDesc) -> bool;
|
||||
fn visit_leave_class(&mut self, name: &str, named_fields: bool, n_fields: uint,
|
||||
sz: uint, align: uint) -> bool;
|
||||
|
||||
fn visit_enter_tup(&mut self, n_fields: uint,
|
||||
sz: uint, align: uint) -> bool;
|
||||
fn visit_tup_field(&mut self, i: uint, inner: *const TyDesc) -> bool;
|
||||
fn visit_leave_tup(&mut self, n_fields: uint,
|
||||
sz: uint, align: uint) -> bool;
|
||||
|
||||
fn visit_enter_enum(&mut self, n_variants: uint,
|
||||
get_disr: unsafe extern fn(ptr: *const Opaque) -> Disr,
|
||||
sz: uint, align: uint) -> bool;
|
||||
fn visit_enter_enum_variant(&mut self, variant: uint,
|
||||
disr_val: Disr,
|
||||
n_fields: uint,
|
||||
name: &str) -> bool;
|
||||
fn visit_enum_variant_field(&mut self, i: uint, offset: uint,
|
||||
inner: *const TyDesc) -> bool;
|
||||
fn visit_leave_enum_variant(&mut self, variant: uint,
|
||||
disr_val: Disr,
|
||||
n_fields: uint,
|
||||
name: &str) -> bool;
|
||||
fn visit_leave_enum(&mut self, n_variants: uint,
|
||||
get_disr: unsafe extern fn(ptr: *const Opaque) -> Disr,
|
||||
sz: uint, align: uint) -> bool;
|
||||
|
||||
fn visit_enter_fn(&mut self, purity: uint, proto: uint,
|
||||
n_inputs: uint, retstyle: uint) -> bool;
|
||||
fn visit_fn_input(&mut self, i: uint, mode: uint,
|
||||
inner: *const TyDesc) -> bool;
|
||||
fn visit_fn_output(&mut self, retstyle: uint, variadic: bool,
|
||||
converging: bool, inner: *const TyDesc) -> bool;
|
||||
fn visit_leave_fn(&mut self, purity: uint, proto: uint,
|
||||
n_inputs: uint, retstyle: uint) -> bool;
|
||||
|
||||
fn visit_trait(&mut self, name: &str) -> bool;
|
||||
fn visit_param(&mut self, i: uint) -> bool;
|
||||
fn visit_self(&mut self) -> bool;
|
||||
}
|
||||
|
||||
extern "rust-intrinsic" {
|
||||
|
||||
// NB: These intrinsics take unsafe pointers because they mutate aliased
|
||||
|
@ -614,29 +614,29 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
|
||||
if name_pos == names.len() && !i_arg.is_none() {
|
||||
return Err(UnexpectedArgument(nm.to_string()));
|
||||
}
|
||||
vals.get_mut(optid).push(Given);
|
||||
vals[optid].push(Given);
|
||||
}
|
||||
Maybe => {
|
||||
if !i_arg.is_none() {
|
||||
vals.get_mut(optid)
|
||||
vals[optid]
|
||||
.push(Val((i_arg.clone())
|
||||
.unwrap()));
|
||||
} else if name_pos < names.len() || i + 1 == l ||
|
||||
is_arg(args[i + 1].as_slice()) {
|
||||
vals.get_mut(optid).push(Given);
|
||||
vals[optid].push(Given);
|
||||
} else {
|
||||
i += 1;
|
||||
vals.get_mut(optid).push(Val(args[i].clone()));
|
||||
vals[optid].push(Val(args[i].clone()));
|
||||
}
|
||||
}
|
||||
Yes => {
|
||||
if !i_arg.is_none() {
|
||||
vals.get_mut(optid).push(Val(i_arg.clone().unwrap()));
|
||||
vals[optid].push(Val(i_arg.clone().unwrap()));
|
||||
} else if i + 1 == l {
|
||||
return Err(ArgumentMissing(nm.to_string()));
|
||||
} else {
|
||||
i += 1;
|
||||
vals.get_mut(optid).push(Val(args[i].clone()));
|
||||
vals[optid].push(Val(args[i].clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ impl<'r> Compiler<'r> {
|
||||
if cap >= len {
|
||||
self.names.grow(10 + cap - len, None)
|
||||
}
|
||||
*self.names.get_mut(cap) = name;
|
||||
self.names[cap] = name;
|
||||
|
||||
self.push(Save(2 * cap));
|
||||
self.compile(*x);
|
||||
@ -243,7 +243,7 @@ impl<'r> Compiler<'r> {
|
||||
/// `panic!` is called.
|
||||
#[inline]
|
||||
fn set_split(&mut self, i: InstIdx, pc1: InstIdx, pc2: InstIdx) {
|
||||
let split = self.insts.get_mut(i);
|
||||
let split = &mut self.insts[i];
|
||||
match *split {
|
||||
Split(_, _) => *split = Split(pc1, pc2),
|
||||
_ => panic!("BUG: Invalid split index."),
|
||||
@ -263,7 +263,7 @@ impl<'r> Compiler<'r> {
|
||||
/// `panic!` is called.
|
||||
#[inline]
|
||||
fn set_jump(&mut self, i: InstIdx, pc: InstIdx) {
|
||||
let jmp = self.insts.get_mut(i);
|
||||
let jmp = &mut self.insts[i];
|
||||
match *jmp {
|
||||
Jump(_) => *jmp = Jump(pc),
|
||||
_ => panic!("BUG: Invalid jump index."),
|
||||
|
@ -978,7 +978,7 @@ fn combine_ranges(unordered: Vec<(char, char)>) -> Vec<(char, char)> {
|
||||
}
|
||||
match which {
|
||||
None => ordered.push((us, ue)),
|
||||
Some(i) => *ordered.get_mut(i) = (us, ue),
|
||||
Some(i) => ordered[i] = (us, ue),
|
||||
}
|
||||
}
|
||||
ordered.sort();
|
||||
|
@ -461,13 +461,13 @@ impl Threads {
|
||||
}
|
||||
|
||||
fn add(&mut self, pc: uint, groups: &[Option<uint>], empty: bool) {
|
||||
let t = self.queue.get_mut(self.size);
|
||||
let t = &mut self.queue[self.size];
|
||||
t.pc = pc;
|
||||
match (empty, self.which) {
|
||||
(_, Exists) | (true, _) => {},
|
||||
(false, Location) => {
|
||||
*t.groups.get_mut(0) = groups[0];
|
||||
*t.groups.get_mut(1) = groups[1];
|
||||
t.groups[0] = groups[0];
|
||||
t.groups[1] = groups[1];
|
||||
}
|
||||
(false, Submatches) => {
|
||||
for (slot, val) in t.groups.iter_mut().zip(groups.iter()) {
|
||||
@ -475,7 +475,7 @@ impl Threads {
|
||||
}
|
||||
}
|
||||
}
|
||||
*self.sparse.get_mut(pc) = self.size;
|
||||
self.sparse[pc] = self.size;
|
||||
self.size += 1;
|
||||
}
|
||||
|
||||
@ -497,7 +497,7 @@ impl Threads {
|
||||
|
||||
#[inline]
|
||||
fn groups<'r>(&'r mut self, i: uint) -> &'r mut [Option<uint>] {
|
||||
self.queue.get_mut(i).groups.as_mut_slice()
|
||||
self.queue[i].groups.as_mut_slice()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1619,7 +1619,7 @@ fn encode_index<T: Hash>(rbml_w: &mut Encoder, index: Vec<entry<T>>,
|
||||
let mut buckets: Vec<Vec<entry<T>>> = Vec::from_fn(256, |_| Vec::new());
|
||||
for elt in index.into_iter() {
|
||||
let h = hash::hash(&elt.val) as uint;
|
||||
buckets.get_mut(h % 256).push(elt);
|
||||
buckets[h % 256].push(elt);
|
||||
}
|
||||
|
||||
rbml_w.start_tag(tag_index);
|
||||
|
@ -214,13 +214,13 @@ impl MoveData {
|
||||
fn set_path_first_move(&self,
|
||||
index: MovePathIndex,
|
||||
first_move: MoveIndex) {
|
||||
self.paths.borrow_mut().get_mut(index.get()).first_move = first_move
|
||||
(*self.paths.borrow_mut())[index.get()].first_move = first_move
|
||||
}
|
||||
|
||||
fn set_path_first_child(&self,
|
||||
index: MovePathIndex,
|
||||
first_child: MovePathIndex) {
|
||||
self.paths.borrow_mut().get_mut(index.get()).first_child = first_child
|
||||
(*self.paths.borrow_mut())[index.get()].first_child = first_child
|
||||
}
|
||||
|
||||
fn move_next_move(&self, index: MoveIndex) -> MoveIndex {
|
||||
|
@ -161,7 +161,7 @@ fn calculate_type(sess: &session::Session,
|
||||
if src.dylib.is_none() && !formats.contains_key(&cnum) {
|
||||
assert!(src.rlib.is_some());
|
||||
add_library(sess, cnum, cstore::RequireStatic, &mut formats);
|
||||
*ret.get_mut(cnum as uint - 1) = Some(cstore::RequireStatic);
|
||||
ret[cnum as uint - 1] = Some(cstore::RequireStatic);
|
||||
debug!("adding staticlib: {}", data.name);
|
||||
}
|
||||
});
|
||||
|
@ -142,7 +142,7 @@ impl<N,E> Graph<N,E> {
|
||||
}
|
||||
|
||||
pub fn mut_node_data<'a>(&'a mut self, idx: NodeIndex) -> &'a mut N {
|
||||
&mut self.nodes.get_mut(idx.get()).data
|
||||
&mut self.nodes[idx.get()].data
|
||||
}
|
||||
|
||||
pub fn node_data<'a>(&'a self, idx: NodeIndex) -> &'a N {
|
||||
@ -182,14 +182,14 @@ impl<N,E> Graph<N,E> {
|
||||
});
|
||||
|
||||
// adjust the firsts for each node target be the next object.
|
||||
self.nodes.get_mut(source.get()).first_edge[Outgoing.repr] = idx;
|
||||
self.nodes.get_mut(target.get()).first_edge[Incoming.repr] = idx;
|
||||
self.nodes[source.get()].first_edge[Outgoing.repr] = idx;
|
||||
self.nodes[target.get()].first_edge[Incoming.repr] = idx;
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
pub fn mut_edge_data<'a>(&'a mut self, idx: EdgeIndex) -> &'a mut E {
|
||||
&mut self.edges.get_mut(idx.get()).data
|
||||
&mut self.edges[idx.get()].data
|
||||
}
|
||||
|
||||
pub fn edge_data<'a>(&'a self, idx: EdgeIndex) -> &'a E {
|
||||
|
@ -756,7 +756,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn init_empty(&mut self, ln: LiveNode, succ_ln: LiveNode) {
|
||||
*self.successors.get_mut(ln.get()) = succ_ln;
|
||||
self.successors[ln.get()] = succ_ln;
|
||||
|
||||
// It is not necessary to initialize the
|
||||
// values to empty because this is the value
|
||||
@ -770,10 +770,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
|
||||
fn init_from_succ(&mut self, ln: LiveNode, succ_ln: LiveNode) {
|
||||
// more efficient version of init_empty() / merge_from_succ()
|
||||
*self.successors.get_mut(ln.get()) = succ_ln;
|
||||
self.successors[ln.get()] = succ_ln;
|
||||
|
||||
self.indices2(ln, succ_ln, |this, idx, succ_idx| {
|
||||
*this.users.get_mut(idx) = this.users[succ_idx]
|
||||
this.users[idx] = this.users[succ_idx]
|
||||
});
|
||||
debug!("init_from_succ(ln={}, succ={})",
|
||||
self.ln_str(ln), self.ln_str(succ_ln));
|
||||
@ -789,11 +789,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
let mut changed = false;
|
||||
self.indices2(ln, succ_ln, |this, idx, succ_idx| {
|
||||
changed |= copy_if_invalid(this.users[succ_idx].reader,
|
||||
&mut this.users.get_mut(idx).reader);
|
||||
&mut this.users[idx].reader);
|
||||
changed |= copy_if_invalid(this.users[succ_idx].writer,
|
||||
&mut this.users.get_mut(idx).writer);
|
||||
&mut this.users[idx].writer);
|
||||
if this.users[succ_idx].used && !this.users[idx].used {
|
||||
this.users.get_mut(idx).used = true;
|
||||
this.users[idx].used = true;
|
||||
changed = true;
|
||||
}
|
||||
});
|
||||
@ -817,8 +817,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
// this) so we just clear out all the data.
|
||||
fn define(&mut self, writer: LiveNode, var: Variable) {
|
||||
let idx = self.idx(writer, var);
|
||||
self.users.get_mut(idx).reader = invalid_node();
|
||||
self.users.get_mut(idx).writer = invalid_node();
|
||||
self.users[idx].reader = invalid_node();
|
||||
self.users[idx].writer = invalid_node();
|
||||
|
||||
debug!("{} defines {} (idx={}): {}", writer.to_string(), var.to_string(),
|
||||
idx, self.ln_str(writer));
|
||||
@ -830,7 +830,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
|
||||
ln.to_string(), acc, var.to_string(), self.ln_str(ln));
|
||||
|
||||
let idx = self.idx(ln, var);
|
||||
let user = self.users.get_mut(idx);
|
||||
let user = &mut self.users[idx];
|
||||
|
||||
if (acc & ACC_WRITE) != 0 {
|
||||
user.reader = invalid_node();
|
||||
|
@ -2596,7 +2596,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
// We've successfully resolved the import. Write the results in.
|
||||
let mut import_resolutions = module_.import_resolutions.borrow_mut();
|
||||
let import_resolution = import_resolutions.get_mut(&target);
|
||||
let import_resolution = &mut (*import_resolutions)[target];
|
||||
|
||||
match value_result {
|
||||
BoundResult(ref target_module, ref name_bindings) => {
|
||||
@ -5697,7 +5697,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
let mut smallest = 0;
|
||||
for (i, other) in maybes.iter().enumerate() {
|
||||
*values.get_mut(i) = name.lev_distance(other.get());
|
||||
values[i] = name.lev_distance(other.get());
|
||||
|
||||
if values[i] <= values[smallest] {
|
||||
smallest = i;
|
||||
|
@ -403,7 +403,7 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
}
|
||||
|
||||
let mut pats = br.pats.clone();
|
||||
*pats.get_mut(col) = pat;
|
||||
pats[col] = pat;
|
||||
Match {
|
||||
pats: pats,
|
||||
data: &*br.data,
|
||||
|
@ -469,7 +469,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
|
||||
assert!(self.is_valid_custom_scope(custom_scope));
|
||||
|
||||
let mut scopes = self.scopes.borrow_mut();
|
||||
let scope = scopes.get_mut(custom_scope.index);
|
||||
let scope = &mut (*scopes)[custom_scope.index];
|
||||
scope.cleanups.push(cleanup);
|
||||
scope.clear_cached_exits();
|
||||
}
|
||||
|
@ -1331,7 +1331,7 @@ fn trans_struct<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
|
||||
field_ty.name == field.ident.node.name);
|
||||
match opt_pos {
|
||||
Some(i) => {
|
||||
*need_base.get_mut(i) = false;
|
||||
need_base[i] = false;
|
||||
(i, &*field.expr)
|
||||
}
|
||||
None => {
|
||||
|
@ -284,7 +284,7 @@ impl Type {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut elts = Vec::from_elem(n_elts, 0 as TypeRef);
|
||||
llvm::LLVMGetStructElementTypes(self.to_ref(), elts.get_mut(0));
|
||||
llvm::LLVMGetStructElementTypes(self.to_ref(), &mut elts[0]);
|
||||
mem::transmute(elts)
|
||||
}
|
||||
}
|
||||
|
@ -650,7 +650,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
|
||||
ByValueExplicitSelfCategory => {
|
||||
let mut n = (*m).clone();
|
||||
let self_ty = n.fty.sig.inputs[0];
|
||||
*n.fty.sig.inputs.get_mut(0) = ty::mk_uniq(tcx, self_ty);
|
||||
n.fty.sig.inputs[0] = ty::mk_uniq(tcx, self_ty);
|
||||
m = Rc::new(n);
|
||||
}
|
||||
_ => { }
|
||||
|
@ -5455,7 +5455,7 @@ pub fn check_bounds_are_used(ccx: &CrateCtxt,
|
||||
match ty::get(t).sty {
|
||||
ty::ty_param(ParamTy {idx, ..}) => {
|
||||
debug!("Found use of ty param num {}", idx);
|
||||
*tps_used.get_mut(idx) = true;
|
||||
tps_used[idx] = true;
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
|
@ -1757,7 +1757,7 @@ fn adjust_upvar_borrow_kind_for_mut(rcx: &Rcx,
|
||||
// is inferred to mutable if necessary
|
||||
let mut upvar_borrow_map =
|
||||
rcx.fcx.inh.upvar_borrow_map.borrow_mut();
|
||||
let ub = upvar_borrow_map.get_mut(upvar_id);
|
||||
let ub = &mut (*upvar_borrow_map)[*upvar_id];
|
||||
return adjust_upvar_borrow_kind(rcx, *upvar_id, ub, ty::MutBorrow);
|
||||
}
|
||||
|
||||
@ -1807,7 +1807,7 @@ fn adjust_upvar_borrow_kind_for_unique(rcx: &Rcx, cmt: mc::cmt) {
|
||||
// borrow_kind of the upvar to make sure it
|
||||
// is inferred to unique if necessary
|
||||
let mut ub = rcx.fcx.inh.upvar_borrow_map.borrow_mut();
|
||||
let ub = ub.get_mut(upvar_id);
|
||||
let ub = &mut (*ub)[*upvar_id];
|
||||
return adjust_upvar_borrow_kind(rcx, *upvar_id, ub, ty::UniqueImmBorrow);
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
|
||||
if snapshot.length == 0 {
|
||||
undo_log.truncate(0);
|
||||
} else {
|
||||
*undo_log.get_mut(snapshot.length) = CommitedSnapshot;
|
||||
(*undo_log)[snapshot.length] = CommitedSnapshot;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -159,12 +159,12 @@ impl sv::SnapshotVecDelegate<TypeVariableData,UndoEntry> for Delegate {
|
||||
action: UndoEntry) {
|
||||
match action {
|
||||
SpecifyVar(vid, relations) => {
|
||||
values.get_mut(vid.index).value = Bounded(relations);
|
||||
values[vid.index].value = Bounded(relations);
|
||||
}
|
||||
|
||||
Relate(a, b) => {
|
||||
relations(values.get_mut(a.index)).pop();
|
||||
relations(values.get_mut(b.index)).pop();
|
||||
relations(&mut (*values)[a.index]).pop();
|
||||
relations(&mut (*values)[b.index]).pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -994,7 +994,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> {
|
||||
new_value,
|
||||
term.to_string());
|
||||
|
||||
*self.solutions.get_mut(inferred) = new_value;
|
||||
self.solutions[inferred] = new_value;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ impl<T,U,D:SnapshotVecDelegate<T,U>> SnapshotVec<T,U,D> {
|
||||
* action.
|
||||
*/
|
||||
|
||||
self.values.get_mut(index)
|
||||
&mut self.values[index]
|
||||
}
|
||||
|
||||
pub fn set(&mut self, index: uint, new_elem: T) {
|
||||
@ -114,7 +114,7 @@ impl<T,U,D:SnapshotVecDelegate<T,U>> SnapshotVec<T,U,D> {
|
||||
* saved (and perhaps restored) if a snapshot is active.
|
||||
*/
|
||||
|
||||
let old_elem = mem::replace(self.values.get_mut(index), new_elem);
|
||||
let old_elem = mem::replace(&mut self.values[index], new_elem);
|
||||
if self.in_snapshot() {
|
||||
self.undo_log.push(SetElem(index, old_elem));
|
||||
}
|
||||
@ -162,7 +162,7 @@ impl<T,U,D:SnapshotVecDelegate<T,U>> SnapshotVec<T,U,D> {
|
||||
}
|
||||
|
||||
SetElem(i, v) => {
|
||||
*self.values.get_mut(i) = v;
|
||||
self.values[i] = v;
|
||||
}
|
||||
|
||||
Other(u) => {
|
||||
@ -189,7 +189,7 @@ impl<T,U,D:SnapshotVecDelegate<T,U>> SnapshotVec<T,U,D> {
|
||||
// The root snapshot.
|
||||
self.undo_log.truncate(0);
|
||||
} else {
|
||||
*self.undo_log.get_mut(snapshot.length) = CommittedSnapshot;
|
||||
self.undo_log[snapshot.length] = CommittedSnapshot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1231,7 +1231,7 @@ impl Stack {
|
||||
InternalIndex(i) => { i + 1 }
|
||||
_ => { panic!(); }
|
||||
};
|
||||
*self.stack.get_mut(len - 1) = InternalIndex(idx);
|
||||
self.stack[len - 1] = InternalIndex(idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,19 +14,14 @@ use clone::Clone;
|
||||
use cmp::{max, Eq, Equiv, PartialEq};
|
||||
use collections::{Collection, Mutable, MutableSet, Map, MutableMap};
|
||||
use default::Default;
|
||||
use fmt::Show;
|
||||
use fmt;
|
||||
use fmt::{mod, Show};
|
||||
use hash::{Hash, Hasher, RandomSipHasher};
|
||||
use iter::{Iterator, FromIterator, Extendable};
|
||||
use iter;
|
||||
use mem::replace;
|
||||
use mem;
|
||||
use iter::{mod, Iterator, FromIterator, Extendable};
|
||||
use mem::{mod, replace};
|
||||
use num;
|
||||
use ops::Deref;
|
||||
use ops::{Deref, Index, IndexMut};
|
||||
use option::{Some, None, Option};
|
||||
use result::{Ok, Err};
|
||||
use ops::Index;
|
||||
use core::result::Result;
|
||||
use result::{Result, Ok, Err};
|
||||
|
||||
use super::table;
|
||||
use super::table::{
|
||||
@ -837,6 +832,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # #![allow(deprecated)]
|
||||
/// use std::collections::HashMap;
|
||||
///
|
||||
/// let mut map = HashMap::new();
|
||||
@ -852,11 +848,9 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> {
|
||||
/// *map.get_mut(&"a") = -2;
|
||||
/// assert_eq!(map["a"], -2);
|
||||
/// ```
|
||||
#[deprecated = "use indexing instead: `&mut map[key]`"]
|
||||
pub fn get_mut<'a>(&'a mut self, k: &K) -> &'a mut V {
|
||||
match self.find_mut(k) {
|
||||
Some(v) => v,
|
||||
None => panic!("no entry found for key")
|
||||
}
|
||||
&mut self[*k]
|
||||
}
|
||||
|
||||
/// Return true if the map contains a value for the specified key,
|
||||
@ -1194,13 +1188,15 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> Index<K, V> for HashMap<K, V, H> {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
|
||||
/*impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> ops::IndexMut<K, V> for HashMap<K, V, H> {
|
||||
impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> IndexMut<K, V> for HashMap<K, V, H> {
|
||||
#[inline]
|
||||
fn index_mut<'a>(&'a mut self, index: &K) -> &'a mut V {
|
||||
self.get_mut(index)
|
||||
match self.find_mut(index) {
|
||||
Some(v) => v,
|
||||
None => panic!("no entry found for key")
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
/// HashMap iterator
|
||||
pub struct Entries<'a, K: 'a, V: 'a> {
|
||||
|
@ -963,7 +963,7 @@ mod test {
|
||||
|
||||
macro_rules! error( ($e:expr, $s:expr) => (
|
||||
match $e {
|
||||
Ok(val) => panic!("Unexpected success. Should've been: {}", $s),
|
||||
Ok(_) => panic!("Unexpected success. Should've been: {}", $s),
|
||||
Err(ref err) => assert!(err.to_string().as_slice().contains($s.as_slice()),
|
||||
format!("`{}` did not contain `{}`", err, $s))
|
||||
}
|
||||
|
@ -424,10 +424,10 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+
|
||||
// or set to 0 if max and carry the 1.
|
||||
let current_digit = ascii2value(buf[i as uint]);
|
||||
if current_digit < (radix - 1) {
|
||||
*buf.get_mut(i as uint) = value2ascii(current_digit+1);
|
||||
buf[i as uint] = value2ascii(current_digit+1);
|
||||
break;
|
||||
} else {
|
||||
*buf.get_mut(i as uint) = value2ascii(0);
|
||||
buf[i as uint] = value2ascii(0);
|
||||
i -= 1;
|
||||
}
|
||||
}
|
||||
|
@ -776,7 +776,7 @@ impl Path {
|
||||
let mut s = String::from_str(s.slice_to(len));
|
||||
unsafe {
|
||||
let v = s.as_mut_vec();
|
||||
*v.get_mut(0) = (*v)[0]
|
||||
v[0] = (*v)[0]
|
||||
.to_ascii()
|
||||
.to_uppercase()
|
||||
.to_byte();
|
||||
@ -784,7 +784,7 @@ impl Path {
|
||||
if is_abs {
|
||||
// normalize C:/ to C:\
|
||||
unsafe {
|
||||
*s.as_mut_vec().get_mut(2) = SEP_BYTE;
|
||||
s.as_mut_vec()[2] = SEP_BYTE;
|
||||
}
|
||||
}
|
||||
Some(s)
|
||||
@ -794,7 +794,7 @@ impl Path {
|
||||
let mut s = String::from_str(s.slice_to(len));
|
||||
unsafe {
|
||||
let v = s.as_mut_vec();
|
||||
*v.get_mut(4) = (*v)[4].to_ascii().to_uppercase().to_byte();
|
||||
v[4] = (*v)[4].to_ascii().to_uppercase().to_byte();
|
||||
}
|
||||
Some(s)
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ pub fn sample<T, I: Iterator<T>, R: Rng>(rng: &mut R,
|
||||
for (i, elem) in iter.enumerate() {
|
||||
let k = rng.gen_range(0, i + 1 + amount);
|
||||
if k < amount {
|
||||
*reservoir.get_mut(k) = elem;
|
||||
reservoir[k] = elem;
|
||||
}
|
||||
}
|
||||
return reservoir;
|
||||
|
@ -426,7 +426,7 @@ impl<T> Buffer<T> {
|
||||
fn enqueue(&mut self, t: T) {
|
||||
let pos = (self.start + self.size) % self.buf.len();
|
||||
self.size += 1;
|
||||
let prev = mem::replace(self.buf.get_mut(pos), Some(t));
|
||||
let prev = mem::replace(&mut self.buf[pos], Some(t));
|
||||
assert!(prev.is_none());
|
||||
}
|
||||
|
||||
@ -434,7 +434,7 @@ impl<T> Buffer<T> {
|
||||
let start = self.start;
|
||||
self.size -= 1;
|
||||
self.start = (self.start + 1) % self.buf.len();
|
||||
self.buf.get_mut(start).take().unwrap()
|
||||
self.buf[start].take().unwrap()
|
||||
}
|
||||
|
||||
fn size(&self) -> uint { self.size }
|
||||
|
@ -308,7 +308,7 @@ impl<'a> Condvar<'a> {
|
||||
// To avoid :broadcast_heavy, we make a new waitqueue,
|
||||
// swap it out with the old one, and broadcast on the
|
||||
// old one outside of the little-lock.
|
||||
queue = Some(mem::replace(state.blocked.get_mut(condvar_id),
|
||||
queue = Some(mem::replace(&mut state.blocked[condvar_id],
|
||||
WaitQueue::new()));
|
||||
} else {
|
||||
out_of_bounds = Some(state.blocked.len());
|
||||
|
@ -712,7 +712,7 @@ impl<'ast> NodeCollector<'ast> {
|
||||
if id as uint >= len {
|
||||
self.map.grow(id as uint - len + 1, NotPresent);
|
||||
}
|
||||
*self.map.get_mut(id as uint) = entry;
|
||||
self.map[id as uint] = entry;
|
||||
}
|
||||
|
||||
fn insert(&mut self, id: NodeId, node: Node<'ast>) {
|
||||
|
@ -785,6 +785,6 @@ impl SyntaxEnv {
|
||||
|
||||
pub fn info<'a>(&'a mut self) -> &'a mut BlockInfo {
|
||||
let last_chain_index = self.chain.len() - 1;
|
||||
&mut self.chain.get_mut(last_chain_index).info
|
||||
&mut self.chain[last_chain_index].info
|
||||
}
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||
self.verify_same(self.args[arg].span, &ty, arg_type);
|
||||
}
|
||||
if self.arg_types[arg].is_none() {
|
||||
*self.arg_types.get_mut(arg) = Some(ty);
|
||||
self.arg_types[arg] = Some(ty);
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,7 +567,7 @@ impl<'a, 'b> Context<'a, 'b> {
|
||||
let lname = self.ecx.ident_of(format!("__arg{}",
|
||||
*name).as_slice());
|
||||
pats.push(self.ecx.pat_ident(e.span, lname));
|
||||
*names.get_mut(self.name_positions[*name]) =
|
||||
names[self.name_positions[*name]] =
|
||||
Some(Context::format_arg(self.ecx, e.span, arg_ty,
|
||||
self.ecx.expr_ident(e.span, lname)));
|
||||
heads.push(self.ecx.expr_addr_of(e.span, e));
|
||||
|
@ -288,8 +288,7 @@ pub fn parse(sess: &ParseSess,
|
||||
// Only touch the binders we have actually bound
|
||||
for idx in range(ei.match_lo, ei.match_hi) {
|
||||
let sub = (ei.matches[idx]).clone();
|
||||
new_pos.matches
|
||||
.get_mut(idx)
|
||||
new_pos.matches[idx]
|
||||
.push(Rc::new(MatchedSeq(sub, mk_sp(ei.sp_lo,
|
||||
sp.hi))));
|
||||
}
|
||||
@ -331,8 +330,7 @@ pub fn parse(sess: &ParseSess,
|
||||
new_ei.idx += 1u;
|
||||
//we specifically matched zero repeats.
|
||||
for idx in range(match_idx_lo, match_idx_hi) {
|
||||
new_ei.matches
|
||||
.get_mut(idx)
|
||||
new_ei.matches[idx]
|
||||
.push(Rc::new(MatchedSeq(Vec::new(), sp)));
|
||||
}
|
||||
|
||||
@ -376,7 +374,7 @@ pub fn parse(sess: &ParseSess,
|
||||
if token_name_eq(&tok, &token::Eof) {
|
||||
if eof_eis.len() == 1u {
|
||||
let mut v = Vec::new();
|
||||
for dv in eof_eis.get_mut(0).matches.iter_mut() {
|
||||
for dv in eof_eis[0].matches.iter_mut() {
|
||||
v.push(dv.pop().unwrap());
|
||||
}
|
||||
return Success(nameize(sess, ms, v.as_slice()));
|
||||
@ -417,7 +415,7 @@ pub fn parse(sess: &ParseSess,
|
||||
match ei.elts[ei.idx].node {
|
||||
MatchNonterminal(_, name, idx) => {
|
||||
let name_string = token::get_ident(name);
|
||||
ei.matches.get_mut(idx).push(Rc::new(MatchedNonterminal(
|
||||
ei.matches[idx].push(Rc::new(MatchedNonterminal(
|
||||
parse_nt(&mut rust_parser, name_string.get()))));
|
||||
ei.idx += 1u;
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ impl Printer {
|
||||
}
|
||||
// be very careful with this!
|
||||
pub fn replace_last_token(&mut self, t: Token) {
|
||||
*self.token.get_mut(self.right) = t;
|
||||
self.token[self.right] = t;
|
||||
}
|
||||
pub fn pretty_print(&mut self, t: Token) -> io::IoResult<()> {
|
||||
debug!("pp ~[{},{}]", self.left, self.right);
|
||||
@ -327,8 +327,8 @@ impl Printer {
|
||||
} else { self.advance_right(); }
|
||||
debug!("pp Begin({})/buffer ~[{},{}]",
|
||||
b.offset, self.left, self.right);
|
||||
*self.token.get_mut(self.right) = t;
|
||||
*self.size.get_mut(self.right) = -self.right_total;
|
||||
self.token[self.right] = t;
|
||||
self.size[self.right] = -self.right_total;
|
||||
let right = self.right;
|
||||
self.scan_push(right);
|
||||
Ok(())
|
||||
@ -340,8 +340,8 @@ impl Printer {
|
||||
} else {
|
||||
debug!("pp End/buffer ~[{},{}]", self.left, self.right);
|
||||
self.advance_right();
|
||||
*self.token.get_mut(self.right) = t;
|
||||
*self.size.get_mut(self.right) = -1;
|
||||
self.token[self.right] = t;
|
||||
self.size[self.right] = -1;
|
||||
let right = self.right;
|
||||
self.scan_push(right);
|
||||
Ok(())
|
||||
@ -359,8 +359,8 @@ impl Printer {
|
||||
self.check_stack(0);
|
||||
let right = self.right;
|
||||
self.scan_push(right);
|
||||
*self.token.get_mut(self.right) = t;
|
||||
*self.size.get_mut(self.right) = -self.right_total;
|
||||
self.token[self.right] = t;
|
||||
self.size[self.right] = -self.right_total;
|
||||
self.right_total += b.blank_space;
|
||||
Ok(())
|
||||
}
|
||||
@ -373,8 +373,8 @@ impl Printer {
|
||||
debug!("pp String('{}')/buffer ~[{},{}]",
|
||||
*s, self.left, self.right);
|
||||
self.advance_right();
|
||||
*self.token.get_mut(self.right) = t.clone();
|
||||
*self.size.get_mut(self.right) = len;
|
||||
self.token[self.right] = t.clone();
|
||||
self.size[self.right] = len;
|
||||
self.right_total += len;
|
||||
self.check_stream()
|
||||
}
|
||||
@ -391,7 +391,7 @@ impl Printer {
|
||||
if self.left == self.scan_stack[self.bottom] {
|
||||
debug!("setting {} to infinity and popping", self.left);
|
||||
let scanned = self.scan_pop_bottom();
|
||||
*self.size.get_mut(scanned) = SIZE_INFINITY;
|
||||
self.size[scanned] = SIZE_INFINITY;
|
||||
}
|
||||
}
|
||||
let left = self.token[self.left].clone();
|
||||
@ -412,7 +412,7 @@ impl Printer {
|
||||
self.top %= self.buf_len;
|
||||
assert!((self.top != self.bottom));
|
||||
}
|
||||
*self.scan_stack.get_mut(self.top) = x;
|
||||
self.scan_stack[self.top] = x;
|
||||
}
|
||||
pub fn scan_pop(&mut self) -> uint {
|
||||
assert!((!self.scan_stack_empty));
|
||||
@ -474,20 +474,19 @@ impl Printer {
|
||||
Begin(_) => {
|
||||
if k > 0 {
|
||||
let popped = self.scan_pop();
|
||||
*self.size.get_mut(popped) = self.size[x] +
|
||||
self.right_total;
|
||||
self.size[popped] = self.size[x] + self.right_total;
|
||||
self.check_stack(k - 1);
|
||||
}
|
||||
}
|
||||
End => {
|
||||
// paper says + not =, but that makes no sense.
|
||||
let popped = self.scan_pop();
|
||||
*self.size.get_mut(popped) = 1;
|
||||
self.size[popped] = 1;
|
||||
self.check_stack(k + 1);
|
||||
}
|
||||
_ => {
|
||||
let popped = self.scan_pop();
|
||||
*self.size.get_mut(popped) = self.size[x] + self.right_total;
|
||||
self.size[popped] = self.size[x] + self.right_total;
|
||||
if k > 0 {
|
||||
self.check_stack(k);
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ impl<'a, T: FloatMath + FromPrimitive> Stats<T> for &'a [T] {
|
||||
let hi = x + y;
|
||||
let lo = y - (hi - x);
|
||||
if !lo.is_zero() {
|
||||
*partials.get_mut(j) = lo;
|
||||
partials[j] = lo;
|
||||
j += 1;
|
||||
}
|
||||
x = hi;
|
||||
@ -193,7 +193,7 @@ impl<'a, T: FloatMath + FromPrimitive> Stats<T> for &'a [T] {
|
||||
if j >= partials.len() {
|
||||
partials.push(x);
|
||||
} else {
|
||||
*partials.get_mut(j) = x;
|
||||
partials[j] = x;
|
||||
partials.truncate(j+1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user