]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/util/interner.rs
rollup merge of #21457: alexcrichton/issue-21436
[rust.git] / src / libsyntax / util / interner.rs
index 93de342d487dccdc32e8c55fcdc576e552c19cf0..1b35b1b04a313e872c72ecf0f868a6ea4d5f51ca 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-//! An "interner" is a data structure that associates values with uint tags and
+//! An "interner" is a data structure that associates values with usize tags and
 //! allows bidirectional lookup; i.e. given a value, one can easily find the
 //! type, and vice versa.
 
@@ -20,6 +20,7 @@
 use std::collections::HashMap;
 use std::fmt;
 use std::hash::Hash;
+use std::collections::hash_map::Hasher;
 use std::ops::Deref;
 use std::rc::Rc;
 
@@ -28,8 +29,8 @@ pub struct Interner<T> {
     vect: RefCell<Vec<T> >,
 }
 
-// when traits can extend traits, we should extend index<Name,T> to get .index(&FullRange)
-impl<T: Eq + Hash + Clone + 'static> Interner<T> {
+// when traits can extend traits, we should extend index<Name,T> to get []
+impl<T: Eq + Hash<Hasher> + Clone + 'static> Interner<T> {
     pub fn new() -> Interner<T> {
         Interner {
             map: RefCell::new(HashMap::new()),
@@ -69,16 +70,16 @@ pub fn gensym(&self, val: T) -> Name {
 
     pub fn get(&self, idx: Name) -> T {
         let vect = self.vect.borrow();
-        (*vect)[idx.uint()].clone()
+        (*vect)[idx.usize()].clone()
     }
 
-    pub fn len(&self) -> uint {
+    pub fn len(&self) -> usize {
         let vect = self.vect.borrow();
         (*vect).len()
     }
 
     pub fn find<Q: ?Sized>(&self, val: &Q) -> Option<Name>
-    where Q: BorrowFrom<T> + Eq + Hash {
+    where Q: BorrowFrom<T> + Eq + Hash<Hasher> {
         let map = self.map.borrow();
         match (*map).get(val) {
             Some(v) => Some(*v),
@@ -109,27 +110,34 @@ impl Eq for RcStr {}
 
 impl Ord for RcStr {
     fn cmp(&self, other: &RcStr) -> Ordering {
-        self.index(&FullRange).cmp(other.index(&FullRange))
+        self[].cmp(&other[])
     }
 }
 
-impl fmt::Show for RcStr {
+impl fmt::Debug for RcStr {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        use std::fmt::Show;
-        self.index(&FullRange).fmt(f)
+        use std::fmt::Debug;
+        self[].fmt(f)
+    }
+}
+
+impl fmt::Display for RcStr {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        use std::fmt::Display;
+        self[].fmt(f)
     }
 }
 
 impl BorrowFrom<RcStr> for str {
     fn borrow_from(owned: &RcStr) -> &str {
-        owned.string.index(&FullRange)
+        &owned.string[]
     }
 }
 
 impl Deref for RcStr {
     type Target = str;
 
-    fn deref(&self) -> &str { self.string.index(&FullRange) }
+    fn deref(&self) -> &str { &self.string[] }
 }
 
 /// A StrInterner differs from Interner<String> in that it accepts
@@ -139,7 +147,7 @@ pub struct StrInterner {
     vect: RefCell<Vec<RcStr> >,
 }
 
-/// When traits can extend traits, we should extend index<Name,T> to get .index(&FullRange)
+/// When traits can extend traits, we should extend index<Name,T> to get []
 impl StrInterner {
     pub fn new() -> StrInterner {
         StrInterner {
@@ -189,21 +197,21 @@ pub fn gensym_copy(&self, idx : Name) -> Name {
         let new_idx = Name(self.len() as u32);
         // leave out of map to avoid colliding
         let mut vect = self.vect.borrow_mut();
-        let existing = (*vect)[idx.uint()].clone();
+        let existing = (*vect)[idx.usize()].clone();
         vect.push(existing);
         new_idx
     }
 
     pub fn get(&self, idx: Name) -> RcStr {
-        (*self.vect.borrow())[idx.uint()].clone()
+        (*self.vect.borrow())[idx.usize()].clone()
     }
 
-    pub fn len(&self) -> uint {
+    pub fn len(&self) -> usize {
         self.vect.borrow().len()
     }
 
     pub fn find<Q: ?Sized>(&self, val: &Q) -> Option<Name>
-    where Q: BorrowFrom<RcStr> + Eq + Hash {
+    where Q: BorrowFrom<RcStr> + Eq + Hash<Hasher> {
         match (*self.map.borrow()).get(val) {
             Some(v) => Some(*v),
             None => None,