-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Don't panic in ceil_char_boundary #112387
Don't panic in ceil_char_boundary #112387
Conversation
r? @cuviper (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
I think this needs to be an API question, even though it's not stable yet. It seems surprising to me that it would return something less than @bors label -T-libs +T-libs-api |
For a more direct link to what I was searching: https://github.com/search?utf8=%E2%9C%93&q=ceil_char_boundary+language%3ARust&type=code&l=Rust Essentially, I saw a few uses of My (flimsy) logic is to think of it like climbing a ladder, and if you climb past the last rung on the ladder you just stay at the last rung. |
We discussed this in the libs-api meeting last week. While we felt it was a bit odd for this method to return a value lower than its input, we agree that one of its main use cases is basically to sanitize input to e.g. Since this is still unstable, this PR doesn't require an FCP. (The behavior of this method will be part of the FCP that will happen when stabilizing it.) @bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (4f4dae0): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 633.856s -> 632.472s (-0.22%) |
Implementing the alternative mentioned in this comment: #93743 (comment)
Since
floor_char_boundary
will always work (rounding down to the length of the string is possible), it feels best forceil_char_boundary
to not panic either. However, the semantics of "rounding up" past the length of the string aren't very great, which is why the method originally panicked in these cases.Taking into account how people are using this method, it feels best to simply return the end of the string in these cases, so that the result is still a valid char boundary.