Skip to content

Updated expect messages for CString struct and method documentation#159853

Open
asder8215 wants to merge 1 commit into
rust-lang:mainfrom
asder8215:cstr_expect
Open

Updated expect messages for CString struct and method documentation#159853
asder8215 wants to merge 1 commit into
rust-lang:mainfrom
asder8215:cstr_expect

Conversation

@asder8215

@asder8215 asder8215 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Completes a task with #159751. Updates the expect messages in library/alloc/src/ffi/c_str.rs.

@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
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from 6 candidates

Comment thread library/alloc/src/ffi/c_str.rs Outdated
/// // We are certain that our string doesn't have 0 bytes in the middle,
/// // so we can .expect()
/// let c_to_print = CString::new("Hello, world!").expect("CString::new failed");
/// let c_to_print = CString::new("Hello, world!").expect("the provided string should not have a nul byte");

@fee1-dead fee1-dead Jul 24, 2026

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.

Thinking a bit on these messages that are more documentation facing (so more effort to consider what's the best), "the provided string" language seems to vaguely suggesting a variable, when we're actually using a constant. Perhaps it would be more clear to say like:

"we provided a string without NUL bytes, so CString::new should not fail"
"we provided bytes that are invalid UTF-8, so `into_string` should fail" // (we can also use `expect_err` instead of `.ok().expect`)
"we provided bytes that has one NUL byte exactly at the end, so CString::from_vec_with_nul should not fail"

View changes since the review

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

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

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

@asder8215

Copy link
Copy Markdown
Contributor Author

Since this was reviewed earlier by @fee1-dead, I'll assign them as the reviewer. I hope that isn't an issue.

r? @fee1-dead

@rustbot rustbot assigned fee1-dead and unassigned Mark-Simulacrum Jul 24, 2026
@asder8215
asder8215 requested a review from fee1-dead July 24, 2026 22:50
@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 24, 2026
@fee1-dead

Copy link
Copy Markdown
Member

nice! I don't de jure have the perms to approve something in libcore, but given that this is only a user facing change for docs, should be pretty uncontroversial:

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a32fa44 has been approved by fee1-dead

It is now in the queue for this repository.

@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 25, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 25, 2026
Updated expect messages for `CString` struct and method documentation

Completes a task with rust-lang#159751. Updates the expect messages in `library/alloc/src/ffi/c_str.rs`.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 25, 2026
Updated expect messages for `CString` struct and method documentation

Completes a task with rust-lang#159751. Updates the expect messages in `library/alloc/src/ffi/c_str.rs`.
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
Rollup of 20 pull requests

Successful merges:

 - #138618 (Support using const pointers in asm `const` operand)
 - #157962 (Lower paths to functions in const args as ConstKind::Error)
 - #158404 (trait_solver: normalize next-gen region constraints)
 - #158709 (rustdoc: warn on improperly interleaved HTML/MD)
 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
 - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
 - #159853 (Updated expect messages for `CString` struct and method documentation)
 - #159877 (Revert "Export `derive` at `core::derive` and `std::derive`")
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
Rollup of 20 pull requests

Successful merges:

 - #138618 (Support using const pointers in asm `const` operand)
 - #157962 (Lower paths to functions in const args as ConstKind::Error)
 - #158404 (trait_solver: normalize next-gen region constraints)
 - #158709 (rustdoc: warn on improperly interleaved HTML/MD)
 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
 - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
 - #159853 (Updated expect messages for `CString` struct and method documentation)
 - #159877 (Revert "Export `derive` at `core::derive` and `std::derive`")
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 25, 2026
Updated expect messages for `CString` struct and method documentation

Completes a task with rust-lang#159751. Updates the expect messages in `library/alloc/src/ffi/c_str.rs`.
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
Rollup of 23 pull requests

Successful merges:

 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159204 (Add support to caller_location to rustc_public)
 - #159411 ([rustdoc] Correctly handle output options with --show-coverage)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
 - #159810 (Add tuple never coercion collection regression test)
 - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
 - #159853 (Updated expect messages for `CString` struct and method documentation)
 - #159877 (Revert "Export `derive` at `core::derive` and `std::derive`")
 - #159878 (bootstrap: Remove obsolete option `build.compiletest-use-stage0-libtest`)
 - #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)
 - #159895 (rustc-dev-guide subtree update)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 25, 2026
Updated expect messages for `CString` struct and method documentation

Completes a task with rust-lang#159751. Updates the expect messages in `library/alloc/src/ffi/c_str.rs`.
rust-bors Bot pushed a commit that referenced this pull request Jul 25, 2026
Rollup of 23 pull requests

Successful merges:

 - #159673 (bootstrap: forward -fdebug-prefix-map when using cc)
 - #159720 (document #[global_allocator] constraints)
 - #159732 (optimization: don't look for diagnostic/canonical items without rustc_attrs enabled)
 - #159738 (implement `CovariantUnsafeCell`)
 - #159740 (reuse regular exported_non_generic_symbols logic in Miri)
 - #159780 (check `extern "custom"` function pointers)
 - #159786 (rustdoc-js: ignore editor temp files in test folder discovery)
 - #159819 (std::sync::poison: disable auto_cfg on PoisonError::new)
 - #155388 (stepping into where-clauses during normalization may be productive)
 - #155914 (when bailing on ambiguity, don't force other results to ambig)
 - #159204 (Add support to caller_location to rustc_public)
 - #159411 ([rustdoc] Correctly handle output options with --show-coverage)
 - #159439 (Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`)
 - #159676 (Update wasm-component-ld to 0.5.27)
 - #159730 (allow accessing the contents of UnsafeCell without going through get)
 - #159809 (Avoid `#[target_features]`)
 - #159810 (Add tuple never coercion collection regression test)
 - #159826 (Remove redundant `#[rustc_paren_sugar]` feature gate)
 - #159853 (Updated expect messages for `CString` struct and method documentation)
 - #159878 (bootstrap: Remove obsolete option `build.compiletest-use-stage0-libtest`)
 - #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)
 - #159895 (rustc-dev-guide subtree update)
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.

4 participants