]> git.lizzy.rs Git - rust.git/commit
std: Change String::truncate to panic less
authorAlex Crichton <alex@alexcrichton.com>
Thu, 14 Apr 2016 23:56:59 +0000 (16:56 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 15 Apr 2016 17:13:43 +0000 (10:13 -0700)
commitae79ce3f030db27aa7d35d1b22307fb4eba14f36
treee35bca3694409c208d2b1e7709583851fbabceef
parent073a09fd63c9b4ec3bb4709986a2517ca4c3cdf1
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
src/libcollections/string.rs
src/libcollectionstest/string.rs