diff options
Diffstat (limited to 'src/liballoc/str.rs')
-rw-r--r-- | src/liballoc/str.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 870bf971cd3..f1bc9a83988 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -515,6 +515,10 @@ impl str { /// Create a [`String`] by repeating a string `n` times. /// + /// # Panics + /// + /// This function will panic if the capacity would overflow. + /// /// [`String`]: string/struct.String.html /// /// # Examples @@ -524,6 +528,15 @@ impl str { /// ``` /// assert_eq!("abc".repeat(4), String::from("abcabcabcabc")); /// ``` + /// + /// A panic upon overflow: + /// + /// ```should_panic + /// fn main() { + /// // this will panic at runtime + /// "0123456789abcdef".repeat(usize::max_value()); + /// } + /// ``` #[stable(feature = "repeat_str", since = "1.16.0")] pub fn repeat(&self, n: usize) -> String { unsafe { String::from_utf8_unchecked(self.as_bytes().repeat(n)) } |