From 3c7f619b76b87c400e270eebfa7625844afcd673 Mon Sep 17 00:00:00 2001 From: Corey Richardson Date: Wed, 18 Jun 2014 10:40:38 -0700 Subject: [PATCH] str: use more helpful assertion failure messages --- src/libcore/str.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 94df7a5a6c2..f94d5a5e4b5 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -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) } }