about summary refs log tree commit diff
path: root/src/libcollectionstest
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2016-04-14 16:56:59 -0700
committerAlex Crichton <alex@alexcrichton.com>2016-04-15 10:13:43 -0700
commitae79ce3f030db27aa7d35d1b22307fb4eba14f36 (patch)
treee35bca3694409c208d2b1e7709583851fbabceef /src/libcollectionstest
parent073a09fd63c9b4ec3bb4709986a2517ca4c3cdf1 (diff)
downloadrust-ae79ce3f030db27aa7d35d1b22307fb4eba14f36.tar.gz
rust-ae79ce3f030db27aa7d35d1b22307fb4eba14f36.zip
std: Change String::truncate to panic less
The `Vec::truncate` method does not panic if the length argument is greater than
the vector's current length, but `String::truncate` will indeed panic. This
semantic difference can be a bit jarring (e.g. #32717), and after some
discussion the libs team concluded that although this can technically be a
breaking change it is almost undoubtedly not so in practice.

This commit changes the semantics of `String::truncate` to be a noop if
`new_len` is greater than the length of the current string.

Closes #32717
Diffstat (limited to 'src/libcollectionstest')
-rw-r--r--src/libcollectionstest/string.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/libcollectionstest/string.rs b/src/libcollectionstest/string.rs
index d8e01f3800c..d71529023f4 100644
--- a/src/libcollectionstest/string.rs
+++ b/src/libcollectionstest/string.rs
@@ -248,10 +248,10 @@ fn test_str_truncate() {
 }
 
 #[test]
-#[should_panic]
 fn test_str_truncate_invalid_len() {
     let mut s = String::from("12345");
     s.truncate(6);
+    assert_eq!(s, "12345");
 }
 
 #[test]