about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/to_str.rs24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs
index 227712e31e6..50cbd36ced9 100644
--- a/src/libstd/to_str.rs
+++ b/src/libstd/to_str.rs
@@ -50,7 +50,7 @@ impl<A:ToStr> ToStr for (A,) {
     }
 }
 
-impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
+impl<A:ToStr+Hash+Eq, B:ToStr> ToStr for HashMap<A, B> {
     #[inline]
     fn to_str(&self) -> ~str {
         let mut acc = ~"{";
@@ -182,6 +182,8 @@ mod tests {
     use hashmap::HashMap;
     use hashmap::HashSet;
     use container::{MutableSet, MutableMap};
+    use super::*;
+
     #[test]
     fn test_simple_types() {
         assert_eq!(1i.to_str(), ~"1");
@@ -212,17 +214,27 @@ mod tests {
                ~"[[], [1], [1, 1]]");
     }
 
+    struct StructWithToStrWithoutEqOrHash {
+        value: int
+    }
+
+    impl ToStr for StructWithToStrWithoutEqOrHash {
+        fn to_str(&self) -> ~str {
+            fmt!("s%d", self.value)
+        }
+    }
+
     #[test]
     fn test_hashmap() {
-        let mut table: HashMap<int, int> = HashMap::new();
-        let empty: HashMap<int, int> = HashMap::new();
+        let mut table: HashMap<int, StructWithToStrWithoutEqOrHash> = HashMap::new();
+        let empty: HashMap<int, StructWithToStrWithoutEqOrHash> = HashMap::new();
 
-        table.insert(3, 4);
-        table.insert(1, 2);
+        table.insert(3, StructWithToStrWithoutEqOrHash { value: 4 });
+        table.insert(1, StructWithToStrWithoutEqOrHash { value: 2 });
 
         let table_str = table.to_str();
 
-        assert!(table_str == ~"{1: 2, 3: 4}" || table_str == ~"{3: 4, 1: 2}");
+        assert!(table_str == ~"{1: s2, 3: s4}" || table_str == ~"{3: s4, 1: s2}");
         assert_eq!(empty.to_str(), ~"{}");
     }