Skip to content

Mistake in CStr type's to_string_lossy() doc #139835

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

Closed
jnqnfe opened this issue Apr 15, 2025 · 1 comment · Fixed by #139922
Closed

Mistake in CStr type's to_string_lossy() doc #139835

jnqnfe opened this issue Apr 15, 2025 · 1 comment · Fixed by #139922
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@jnqnfe
Copy link
Contributor

jnqnfe commented Apr 15, 2025

Location

https://doc.rust-lang.org/stable/std/ffi/struct.CStr.html#method.to_str

Summary

The documentation for the to_string_lossy() method of CStr, which returns a Cow<'_, str>, currently contains the following text:

If the contents of the CStr are valid UTF-8 data, this function will return a Cow::Borrowed(&str) with the corresponding &str slice. Otherwise, it will replace any invalid UTF-8 sequences with U+FFFD REPLACEMENT CHARACTER and return a Cow::Owned(&str) with the result.

The owned case seems wrong. I believe that it would return a Cow::Owned(String) not a Cow::Owned(&str).

The documentation did actually claim Cow::Owned(String) was returned prior to commit 67065fe which changed it to the above without explanation.

@jnqnfe jnqnfe added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Apr 15, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 15, 2025
@jnqnfe
Copy link
Contributor Author

jnqnfe commented Apr 15, 2025

@steffahn ?

@jieyouxu jieyouxu added T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 15, 2025
jhpratt added a commit to jhpratt/rust that referenced this issue Apr 19, 2025
fix incorrect type in cstr `to_string_lossy()` docs

Restoring what it said prior to commit 67065fe in which it was changed incorrectly with no supporting explanation.

Closes rust-lang#139835.
ChrisDenton added a commit to ChrisDenton/rust that referenced this issue Apr 19, 2025
fix incorrect type in cstr `to_string_lossy()` docs

Restoring what it said prior to commit 67065fe in which it was changed incorrectly with no supporting explanation.

Closes rust-lang#139835.
@bors bors closed this as completed in 2f0ba67 Apr 19, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 19, 2025
Rollup merge of rust-lang#139922 - jnqnfe:cstr_doc_fix, r=jhpratt

fix incorrect type in cstr `to_string_lossy()` docs

Restoring what it said prior to commit 67065fe in which it was changed incorrectly with no supporting explanation.

Closes rust-lang#139835.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants