]> git.lizzy.rs Git - rust.git/commitdiff
str: use more helpful assertion failure messages
authorCorey Richardson <corey@octayn.net>
Wed, 18 Jun 2014 17:40:38 +0000 (10:40 -0700)
committerCorey Richardson <corey@octayn.net>
Wed, 9 Jul 2014 07:06:28 +0000 (00:06 -0700)
src/libcore/str.rs

index 94df7a5a6c2d9c7548a089e8e949fbc32936f226..f94d5a5e4b5e3b6fe31f02a687189afdfd3d2b92 100644 (file)
@@ -1764,7 +1764,9 @@ fn char_len(&self) -> uint { self.chars().count() }
 
     #[inline]
     fn slice(&self, begin: uint, end: uint) -> &'a str {
-        assert!(self.is_char_boundary(begin) && self.is_char_boundary(end));
+        assert!(self.is_char_boundary(begin) && self.is_char_boundary(end),
+                "index {} and/or {} in `{}` do not lie on character boundary", begin,
+                end, *self);
         unsafe { raw::slice_bytes(*self, begin, end) }
     }
 
@@ -1775,7 +1777,8 @@ fn slice_from(&self, begin: uint) -> &'a str {
 
     #[inline]
     fn slice_to(&self, end: uint) -> &'a str {
-        assert!(self.is_char_boundary(end));
+        assert!(self.is_char_boundary(end), "index {} in `{}` does not lie on \
+                a character boundary", end, *self);
         unsafe { raw::slice_bytes(*self, 0, end) }
     }