std: Change String::truncate to panic less#32977
Conversation
|
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
|
r? @brson |
|
@bors r+ |
|
📌 Commit 41861ed has been approved by |
|
@alexcrichton: You need to update |
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. rust-lang#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 rust-lang#32717
41861ed to
ae79ce3
Compare
|
⌛ Testing commit ae79ce3 with merge 20dafb0... |
|
💔 Test failed - auto-win-gnu-32-opt-rustbuild |
|
@bors: retry On Sat, Apr 16, 2016 at 2:06 AM, bors [email protected] wrote:
|
|
⌛ Testing commit ae79ce3 with merge b5de94f... |
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
std: make `OsString::truncate` a no-op when `len > current_len` Align `OsString::truncate` (and the underlying WTF-8 implementation) with `String::truncate` by making it a no-op when `len > self.len()`. Previously, `OsString::truncate` would panic if `len > self.len()`, while `String::truncate` treats such cases as a no-op. Tracking (`os_string_truncate`): #133262 See also: #32977 cc: @alexcrichton, @lolbinarycat
std: make `OsString::truncate` a no-op when `len > current_len` Align `OsString::truncate` (and the underlying WTF-8 implementation) with `String::truncate` by making it a no-op when `len > self.len()`. Previously, `OsString::truncate` would panic if `len > self.len()`, while `String::truncate` treats such cases as a no-op. Tracking (`os_string_truncate`): rust-lang#133262 See also: rust-lang#32977 cc: @alexcrichton, @lolbinarycat
The
Vec::truncatemethod does not panic if the length argument is greater thanthe vector's current length, but
String::truncatewill indeed panic. Thissemantic 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::truncateto be a noop ifnew_lenis greater than the length of the current string.Closes #32717