str: use more helpful assertion failure messages

This commit is contained in:
Corey Richardson 2014-06-18 10:40:38 -07:00
parent c2dd553bed
commit 3c7f619b76

View File

@ -1764,7 +1764,9 @@ impl<'a> StrSlice<'a> for &'a str {
#[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 @@ impl<'a> StrSlice<'a> for &'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) }
}