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

Open
jnqnfe opened this issue Apr 15, 2025 · 1 comment · May be fixed by #139922
Open

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

jnqnfe opened this issue Apr 15, 2025 · 1 comment · May be 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
jnqnfe added a commit to jnqnfe/rust that referenced this issue Apr 16, 2025
Restoring what it said prior to commit 67065fe in which it was changed
incorrectly with no supporting explanation.

Closes rust-lang#139835.
@jnqnfe jnqnfe linked a pull request Apr 16, 2025 that will close this issue
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