Skip to content
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

Documentation of the From<String> impl for OsString misleading #72349

Closed
smarnach opened this issue May 19, 2020 · 1 comment
Closed

Documentation of the From<String> impl for OsString misleading #72349

smarnach opened this issue May 19, 2020 · 1 comment
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@smarnach
Copy link
Contributor

The documentation of From<String> for OsString reads

Converts a String into a OsString.

The conversion copies the data, and includes an allocation on the heap.

The implementation is platform-specific, but from a quick glance none of the implementations I looked at does seem to actually copy the data.

The documentation of From<String> for PatBbuf reads

Converts a String into a PathBuf

This conversion does not allocate or copy memory.

It is implemented using OsString::from::<String>:

fn from(s: String) -> PathBuf {
    PathBuf::from(OsString::from(s))
}

So clearly something is off here. Even when all current implementations of the String to OsString conversion avoid copying, the documentation does not necessarily need to commit to this property, but neither should it state that the implementation allocates and copies if it actually doesn't.

@smarnach smarnach added the C-bug Category: This is a bug. label May 19, 2020
@jonas-schievink jonas-schievink added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label May 19, 2020
@ChrisDenton
Copy link
Member

This was fixed by #83700.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants