Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Change String::truncate to panic less #32977

Merged
merged 1 commit into from
Apr 17, 2016

Conversation

alexcrichton
Copy link
Member

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

@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @brson

@rust-highfive rust-highfive assigned brson and unassigned aturon Apr 14, 2016
@brson brson added the relnotes Marks issues that should be documented in the release notes of the next release. label Apr 15, 2016
@brson
Copy link
Contributor

brson commented Apr 15, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Apr 15, 2016

📌 Commit 41861ed has been approved by brson

@GuillaumeGomez
Copy link
Member

@alexcrichton: You need to update string::test_str_truncate_invalid_len.

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
@alexcrichton
Copy link
Member Author

@bors: r=brson ae79ce3

@bors
Copy link
Contributor

bors commented Apr 16, 2016

⌛ Testing commit ae79ce3 with merge 20dafb0...

@bors
Copy link
Contributor

bors commented Apr 16, 2016

💔 Test failed - auto-win-gnu-32-opt-rustbuild

@alexcrichton
Copy link
Member Author

@bors: retry

On Sat, Apr 16, 2016 at 2:06 AM, bors notifications@github.com wrote:

[image: 💔] Test failed - auto-win-gnu-32-opt-rustbuild
http://buildbot.rust-lang.org/builders/auto-win-gnu-32-opt-rustbuild/builds/732


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#32977 (comment)

@bors
Copy link
Contributor

bors commented Apr 17, 2016

⌛ Testing commit ae79ce3 with merge b5de94f...

bors added a commit that referenced this pull request Apr 17, 2016
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
@bors bors merged commit ae79ce3 into rust-lang:master Apr 17, 2016
@alexcrichton alexcrichton deleted the ignore-panics branch May 2, 2016 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants