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

Add String::extend_from_within #85801

Merged
merged 1 commit into from
May 30, 2021
Merged

Add String::extend_from_within #85801

merged 1 commit into from
May 30, 2021

Conversation

WaffleLapkin
Copy link
Member

This PR adds String::extend_from_within function under the string_extend_from_within feature gate similar to the Vec::extend_from_within function.

// String
pub fn extend_from_within<R>(&mut self, src: R)
where
    R: RangeBounds<usize>;

This patch adds `String::extend_from_within` function under the
`string_extend_from_within` feature gate similar to the
`Vec::extend_from_within` function.
@rust-highfive
Copy link
Collaborator

r? @joshtriplett

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 29, 2021
Comment on lines +876 to +877
assert!(self.is_char_boundary(start));
assert!(self.is_char_boundary(end));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If panic happens, how does one know if it panics because of start or end?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be possible by checking the line number in the panic message. It isn't convenient, but it is possible.

Also, note that the same pattern appears multiple times in this file:

assert!(self.is_char_boundary(start));
assert!(self.is_char_boundary(end));
let start = range.start_bound();
match start {
Included(&n) => assert!(self.is_char_boundary(n)),
Excluded(&n) => assert!(self.is_char_boundary(n + 1)),
Unbounded => {}
};
// WARNING: Inlining this variable would be unsound (#81138)
let end = range.end_bound();
match end {
Included(&n) => assert!(self.is_char_boundary(n + 1)),
Excluded(&n) => assert!(self.is_char_boundary(n)),
Unbounded => {}
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should have a separate issue for this.

Copy link
Contributor

@pickfire pickfire May 31, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, it's not necessary. The current panic error message is good enough. (but still without the function name, like drain)

thread 'main' panicked at 'assertion failed: self.is_char_boundary(start)', /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/alloc/src/string.rs:1571:9

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4e29eec2c640b0a42b054f58b1f6753d

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so when called without a message, assert! prints the passed expression. That's nice.

@joshtriplett
Copy link
Member

Seems reasonable, and I appreciate that it calls Vec::extend_from_within rather than doing anything unsafe itself.

@bors r+

@bors
Copy link
Contributor

bors commented May 30, 2021

📌 Commit 23f9b92 has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request May 30, 2021
…laumeGomez

Rollup of 8 pull requests

Successful merges:

 - rust-lang#85285 (Add eslint checks to CI)
 - rust-lang#85709 (Use correct edition when parsing `:pat` matchers)
 - rust-lang#85762 (Do not try to build LLVM with Zlib on Windows)
 - rust-lang#85770 (Remove `--print unversioned-files` from rustdoc )
 - rust-lang#85781 (Add documentation for aarch64-apple-ios-sim target)
 - rust-lang#85801 (Add `String::extend_from_within`)
 - rust-lang#85817 (Fix a typo)
 - rust-lang#85818 (Don't drop `PResult` without handling the error)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b0f2a4c into rust-lang:master May 30, 2021
@rustbot rustbot added this to the 1.54.0 milestone May 30, 2021
@ghost ghost mentioned this pull request Oct 31, 2022
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants