Skip to content

Conversation

@zachs18
Copy link
Contributor

@zachs18 zachs18 commented Dec 14, 2024

Rebase of #97977 (cc @WilliamVenner)

Convenience methods that use match_indices and replace_range to efficiently replace a substring in a string without reallocating, if capacity (and the implementation of Vec::splice) allows.

The intra-doc link to str::replacen is a direct url-based link to str::replacen in std's docs to work around #98941. This means that when building only alloc's docs (and not std's), it will be a broken link. There is precedent for this e.g. in core::hint::spin_loop which links to std::thread::yield_now using a url-based link and thus is a dead link when only building core's docs.

ACP: rust-lang/libs-team#506

@rustbot
Copy link
Collaborator

rustbot commented Dec 14, 2024

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 14, 2024
@tgross35
Copy link
Contributor

I don't think I see any libs-api feedback on the other thread, and that is from a while back anyway. Could you file an ACP for this at https://github.com/rust-lang/libs-team/issues?

@tgross35
Copy link
Contributor

These methods would be convenient but I feel like they should probably come with an in-place replace alternative.

@rust-log-analyzer

This comment has been minimized.

@zachs18
Copy link
Contributor Author

zachs18 commented Dec 15, 2024

ACP opened: rust-lang/libs-team#506

@rustbot label S-waiting-on-ACP

I added String::replace_in_place (doing str::replace in-place) as a possible alternative/addition in the ACP, but I'll hold off on adding it if/until the ACP is approved with it.

@rustbot rustbot added the S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. label Dec 15, 2024
@tgross35 tgross35 removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 27, 2024
@bors
Copy link
Collaborator

bors commented Jan 9, 2025

☔ The latest upstream changes (presumably #135286) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 9, 2025
@alex-semenyuk
Copy link
Member

alex-semenyuk commented Feb 21, 2025

@zachs18
Thanks for your contribution
Could you please rebase

@tgross35
Copy link
Contributor

@zachs18 Thanks for your contribution Could you please rebase

This is still waiting on the ACP

@tgross35 tgross35 removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Feb 21, 2025
@joshtriplett
Copy link
Member

@bors r+ rollup

ACP approved, PR approved.

Might be interested in the proposed replace_in_place in the future, but these seem clearly valuable and worth adding.

@bors
Copy link
Collaborator

bors commented Oct 21, 2025

📌 Commit 0243f5c has been approved by joshtriplett

It is now in the queue for this repository.

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Oct 21, 2025
@joshtriplett
Copy link
Member

@bors r-

r=me when the conflicts are fixed.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 21, 2025
@tgross35 tgross35 removed the S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. label Oct 21, 2025
@tgross35
Copy link
Contributor

Please also squash when you rebase, this PR has fixup commits

Rebased and modified by zachs18.

Co-authored-by: zachs18 <[email protected]>
@zachs18 zachs18 force-pushed the string_replace_in_place_rebase branch from 0243f5c to 8ed7fca Compare October 21, 2025 21:14
@rustbot
Copy link
Collaborator

rustbot commented Oct 21, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@zachs18
Copy link
Contributor Author

zachs18 commented Oct 21, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 21, 2025
//
// Library features:
// tidy-alphabetical-start
#![cfg_attr(not(no_global_oom_handling), feature(string_replace_in_place))]
Copy link
Contributor

@tgross35 tgross35 Oct 21, 2025

Choose a reason for hiding this comment

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

Fwiw I think you may as well drop the cfg_attr and enable the feature unconditionally, usually we don't gate these too strictly. And we'll wind up using it elsewhere anyway.

I'll merge after PR CI finishes, with or without this (just ping me once it does if I miss it)

Copy link
Contributor

Choose a reason for hiding this comment

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

This might actually be needed (?), since its absence seems to be what the failed CI job is complaining about.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah; I'm sorry, this was bad advice.

Copy link
Contributor Author

@zachs18 zachs18 Oct 23, 2025

Choose a reason for hiding this comment

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

I undid this (that is, undid removing cfg_attr, so re-added it) and re-pushed

@rustbot ready

@zachs18 zachs18 force-pushed the string_replace_in_place_rebase branch from 8ed7fca to 271b10c Compare October 22, 2025 17:00
@rust-log-analyzer

This comment has been minimized.

@tgross35
Copy link
Contributor

Thanks! I assume the GCC failure is spurious

@bors r=joshtriplett ,tgross35

@bors
Copy link
Collaborator

bors commented Oct 22, 2025

📌 Commit 271b10c has been approved by joshtriplett

It is now in the queue for this repository.

@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 Oct 22, 2025
@tgross35
Copy link
Contributor

@bors rollup

Zalathar added a commit to Zalathar/rust that referenced this pull request Oct 22, 2025
…base, r=joshtriplett

Add `String::replace_first` and `String::replace_last`

Rebase of rust-lang#97977 (cc `@WilliamVenner)`

> Convenience methods that use `match_indices` and `replace_range` to efficiently replace a substring in a string without reallocating, if capacity (and the implementation of `Vec::splice`) allows.

The intra-doc link to `str::replacen` is a direct url-based link to `str::replacen` in `std`'s docs to work around rust-lang#98941. This means that when building only `alloc`'s docs (and not `std`'s), it will be a broken link. There is precedent for this e.g. in [`core::hint::spin_loop`](https://doc.rust-lang.org/nightly/src/core/hint.rs.html#214) which links to `std::thread::yield_now` using a [url-based link](https://github.com/rust-lang/rust/blob/master/library/core/src/hint.rs#L265) and thus is a dead link when only building `core`'s docs.

ACP: rust-lang/libs-team#506
@Zalathar
Copy link
Contributor

The GCC job failed again in rollup: #148010 (comment)

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 23, 2025
@zachs18 zachs18 force-pushed the string_replace_in_place_rebase branch from 271b10c to 8ed7fca Compare October 23, 2025 03:37
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 23, 2025
@tgross35
Copy link
Contributor

@bors r=joshtriplett ,tgross35

@bors
Copy link
Collaborator

bors commented Oct 23, 2025

📌 Commit 8ed7fca has been approved by joshtriplett

It is now in the queue for this repository.

@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 Oct 23, 2025
bors added a commit that referenced this pull request Oct 23, 2025
Rollup of 3 pull requests

Successful merges:

 - #134316 (Add `String::replace_first` and `String::replace_last`)
 - #147713 (Retire ast::TyAliasWhereClauses.)
 - #148011 (Revert constification of `AsRef for Cow` due to inference failure )

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4491efb into rust-lang:master Oct 23, 2025
22 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Oct 23, 2025
rust-timer added a commit that referenced this pull request Oct 23, 2025
Rollup merge of #134316 - zachs18:string_replace_in_place_rebase, r=joshtriplett

Add `String::replace_first` and `String::replace_last`

Rebase of #97977 (cc `@WilliamVenner)`

> Convenience methods that use `match_indices` and `replace_range` to efficiently replace a substring in a string without reallocating, if capacity (and the implementation of `Vec::splice`) allows.

The intra-doc link to `str::replacen` is a direct url-based link to `str::replacen` in `std`'s docs to work around #98941. This means that when building only `alloc`'s docs (and not `std`'s), it will be a broken link. There is precedent for this e.g. in [`core::hint::spin_loop`](https://doc.rust-lang.org/nightly/src/core/hint.rs.html#214) which links to `std::thread::yield_now` using a [url-based link](https://github.com/rust-lang/rust/blob/master/library/core/src/hint.rs#L265) and thus is a dead link when only building `core`'s docs.

ACP: rust-lang/libs-team#506
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 24, 2025
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#134316 (Add `String::replace_first` and `String::replace_last`)
 - rust-lang/rust#147713 (Retire ast::TyAliasWhereClauses.)
 - rust-lang/rust#148011 (Revert constification of `AsRef for Cow` due to inference failure )

r? `@ghost`
`@rustbot` modify labels: rollup
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants