Skip to content

Implement str::copy_from_str#159846

Open
valentynkit wants to merge 1 commit into
rust-lang:mainfrom
valentynkit:str-copy-from-str
Open

Implement str::copy_from_str#159846
valentynkit wants to merge 1 commit into
rust-lang:mainfrom
valentynkit:str-copy-from-str

Conversation

@valentynkit

@valentynkit valentynkit commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Implements the accepted ACP rust-lang/libs-team#709: add str::copy_from_str, which copies a same-length &str into a mutable str in place, mirroring <[T]>::copy_from_slice.

The write is safe because UTF-8 is self-recovering: overwriting a str with a same-length &str cannot produce invalid UTF-8, and copy_from_slice enforces the length equality (panics otherwise).

The ACP accepted copy_from_str and rejected copy_within; swap_with_str was left out pending a use case, so this adds only the one method.

Tracking issue: #159841

r? libs

@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 Jul 24, 2026

@jhpratt jhpratt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread library/core/src/str/mod.rs Outdated
///
/// # Panics
///
/// This function will panic if the two string slices have different lengths.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/// This function will panic if the two string slices have different lengths.
/// This function will panic if the two strings have different lengths.

Same throughout. While "string slices" may be more correct technically, I've never seen it referred to that way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Applied the same change to the other two mentions in the doc.

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 25, 2026
@rustbot

rustbot commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@valentynkit

Copy link
Copy Markdown
Contributor Author

@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 Jul 25, 2026
@jhpratt

jhpratt commented Jul 26, 2026

Copy link
Copy Markdown
Member

@bors squash

@rust-bors

This comment has been minimized.

* Implement `str::copy_from_str`
* Reword `str::copy_from_str` docs to say "strings"
@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

🔨 2 commits were squashed into 4cf766b.

@rust-bors
rust-bors Bot force-pushed the str-copy-from-str branch from 5a600f8 to 4cf766b Compare July 26, 2026 04:23
@jhpratt

jhpratt commented Jul 26, 2026

Copy link
Copy Markdown
Member

Thanks!

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 4cf766b has been approved by jhpratt

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@rust-bors rust-bors Bot 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 Jul 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
…hpratt

Implement `str::copy_from_str`

Implements the accepted ACP rust-lang/libs-team#709: add `str::copy_from_str`, which copies a same-length `&str` into a mutable `str` in place, mirroring `<[T]>::copy_from_slice`.

The write is safe because UTF-8 is self-recovering: overwriting a `str` with a same-length `&str` cannot produce invalid UTF-8, and `copy_from_slice` enforces the length equality (panics otherwise).

The ACP accepted `copy_from_str` and rejected `copy_within`; `swap_with_str` was left out pending a use case, so this adds only the one method.

Tracking issue: rust-lang#159841

r? libs
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
…hpratt

Implement `str::copy_from_str`

Implements the accepted ACP rust-lang/libs-team#709: add `str::copy_from_str`, which copies a same-length `&str` into a mutable `str` in place, mirroring `<[T]>::copy_from_slice`.

The write is safe because UTF-8 is self-recovering: overwriting a `str` with a same-length `&str` cannot produce invalid UTF-8, and `copy_from_slice` enforces the length equality (panics otherwise).

The ACP accepted `copy_from_str` and rejected `copy_within`; `swap_with_str` was left out pending a use case, so this adds only the one method.

Tracking issue: rust-lang#159841

r? libs
rust-bors Bot pushed a commit that referenced this pull request Jul 26, 2026
…uwer

Rollup of 24 pull requests

Successful merges:

 - #159638 (bootstrap: Split the `Step` trait into multiple traits)
 - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations)
 - #159837 (line-tables-only test: check that the line number matches the function name)
 - #159946 (Update Enzyme submodule to imporve llvm-cov)
 - #159617 (Fix up `#[linkage]` target checking)
 - #159733 (std: Switch implementations of `thread_local!` for WASI)
 - #159783 (Check unsafe impls on safe EIIs)
 - #159810 (Add tuple never coercion collection regression test)
 - #159821 (Update expect message using the recommended style in binary_heap module)
 - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
 - #159846 (Implement `str::copy_from_str`)
 - #159849 (rustc_parse: Stop returning `Option` from statement parsing)
 - #159853 (Updated expect messages for `CString` struct and method documentation)
 - #159875 (More cleanup in `rustc_attr_parsing`)
 - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide)
 - #159891 (Split multiline derives into std/rustc macros)
 - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups)
 - #159895 (rustc-dev-guide subtree update)
 - #159902 (Clarify that the expected runtime symbols signature is for the current target only)
 - #159914 (Fix error in diagnostic on_unmatched_args)
 - #159917 (spare capacity mut constification)
 - #159918 (rename abort_unwind → abort_on_unwind)
 - #159936 (Minor `rustc_ast::ast` doc cleanups)
 - #159945 (Update expect messages in library/core/src/ptr/non_null.rs)
rust-bors Bot pushed a commit that referenced this pull request Jul 26, 2026
…uwer

Rollup of 24 pull requests

Successful merges:

 - #159638 (bootstrap: Split the `Step` trait into multiple traits)
 - #159774 (rustc_trait_selection: fix trait solver hang caused by degenerate obligations)
 - #159837 (line-tables-only test: check that the line number matches the function name)
 - #159946 (Update Enzyme submodule to imporve llvm-cov)
 - #159617 (Fix up `#[linkage]` target checking)
 - #159733 (std: Switch implementations of `thread_local!` for WASI)
 - #159783 (Check unsafe impls on safe EIIs)
 - #159810 (Add tuple never coercion collection regression test)
 - #159821 (Update expect message using the recommended style in binary_heap module)
 - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
 - #159846 (Implement `str::copy_from_str`)
 - #159849 (rustc_parse: Stop returning `Option` from statement parsing)
 - #159853 (Updated expect messages for `CString` struct and method documentation)
 - #159875 (More cleanup in `rustc_attr_parsing`)
 - #159882 (Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide)
 - #159891 (Split multiline derives into std/rustc macros)
 - #159893 (Fix `find_attr` hygiene and `rustc_hir` cleanups)
 - #159895 (rustc-dev-guide subtree update)
 - #159902 (Clarify that the expected runtime symbols signature is for the current target only)
 - #159914 (Fix error in diagnostic on_unmatched_args)
 - #159917 (spare capacity mut constification)
 - #159918 (rename abort_unwind → abort_on_unwind)
 - #159936 (Minor `rustc_ast::ast` doc cleanups)
 - #159945 (Update expect messages in library/core/src/ptr/non_null.rs)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 26, 2026
…hpratt

Implement `str::copy_from_str`

Implements the accepted ACP rust-lang/libs-team#709: add `str::copy_from_str`, which copies a same-length `&str` into a mutable `str` in place, mirroring `<[T]>::copy_from_slice`.

The write is safe because UTF-8 is self-recovering: overwriting a `str` with a same-length `&str` cannot produce invalid UTF-8, and `copy_from_slice` enforces the length equality (panics otherwise).

The ACP accepted `copy_from_str` and rejected `copy_within`; `swap_with_str` was left out pending a use case, so this adds only the one method.

Tracking issue: rust-lang#159841

r? libs
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.

3 participants