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

Tracking issue for PathBuf::as_mut_os_string and Path::as_mut_os_str #105021

Closed
3 of 5 tasks
zertosh opened this issue Nov 28, 2022 · 10 comments · Fixed by #105962
Closed
3 of 5 tasks

Tracking issue for PathBuf::as_mut_os_string and Path::as_mut_os_str #105021

zertosh opened this issue Nov 28, 2022 · 10 comments · Fixed by #105962
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@zertosh
Copy link
Contributor

zertosh commented Nov 28, 2022

Feature gate: #![feature(path_as_mut_os_str)]

This is a tracking issue for adding PathBuf::as_mut_os_string and Path::as_mut_os_str (rust-lang/libs-team#140).

Public API

impl PathBuf {
    // ...
    pub fn as_mut_os_string(&mut self) -> &mut OsString {
        &mut self.inner
    }
    // ...
}

impl Path {
    // ...
    pub fn as_mut_os_str(&mut self) -> &mut OsStr {
        &mut self.inner
    }
    // ...
}

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@zertosh zertosh added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Nov 28, 2022
@the8472
Copy link
Member

the8472 commented Nov 28, 2022

That seems questionable to me. Right now we don't have any restrictions what goes into a Path, but on some future platform it might be necessary to have a validation on Path::new (e.g. only a restricted set of prefixes is allowed) and that can't be done if it can be freely mutated as a osstring.

@dtolnay
Copy link
Member

dtolnay commented Nov 28, 2022

On platforms that would need such a restriction, would Path::new have a different return type, or a different name, or would panic? In addition to Path::new, there's already impl AsRef<Path> for str, impl AsRef<Path> for OsStr, and probably a bunch of others that bake in the expectation that paths are arbitrary OS strings. If we're gonna be making those panic or be conditionally compiled, doing the same for Path::as_mut_os_str is no more complex than any of those. But it seems more likely to me that the way we would address platform-specific path restrictions would be by leaving it to the system calls to report failure on an unsupported contents of a path, or doing validation in Rust before the system call, not during PathBuf mutations.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 29, 2022
Add `PathBuf::as_mut_os_string` and `Path::as_mut_os_str`

Implements rust-lang/libs-team#140 (tracking issue rust-lang#105021).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 29, 2022
Add `PathBuf::as_mut_os_string` and `Path::as_mut_os_str`

Implements rust-lang/libs-team#140 (tracking issue rust-lang#105021).
@dtolnay dtolnay changed the title Tracking Issue for adding PathBuf::as_mut_os_string and Path::as_mut_os_str Tracking issue for PathBuf::as_mut_os_string and Path::as_mut_os_str Dec 5, 2022
@zertosh
Copy link
Contributor Author

zertosh commented Dec 20, 2022

Stabilization Report

Implementation History

API Summary

A summary of the API is included at the top of this tracking issue.

Experience Report

n/a

@zertosh
Copy link
Contributor Author

zertosh commented Dec 20, 2022

@dtolnay, can you please start an FCP? (as per Stabilization PR Checklist)

@dtolnay
Copy link
Member

dtolnay commented Dec 21, 2022

@rust-lang/libs-api
@rfcbot fcp merge

This stabilizes PathBuf::as_mut_os_string and Path::as_mut_os_str.

The point of these methods is illustrated in the documentation examples. They let you mutate the path contents in place without going through PathBuf's limited mutation API (e.g. every push adding a separator).

path.as_mut_os_string().push("-suffix");

// equivalent to:
let mut os_string = std::mem::take(path).into_os_string();
os_string.push("-suffix");
*path = PathBuf::from(os_string);

Note that a Path::as_os_str has existed since 1.0.0 to help people avoid using AsRef<OsStr> for Path in places that an as_ref() call might be ambiguous. Meanwhile PathBuf::as_os_string has not come up so far as a thing anyone wants.

@rfcbot
Copy link

rfcbot commented Dec 21, 2022

Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Dec 21, 2022
@dtolnay
Copy link
Member

dtolnay commented Jan 11, 2023

I'm marking yaahc's box because she has stepped down from T-libs-api after the point that this feature got proposed for FCP.

@dtolnay
Copy link
Member

dtolnay commented Feb 28, 2023

@Amanieu or @joshtriplett or @m-ou-se?

@dtolnay dtolnay added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Feb 28, 2023
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Feb 28, 2023
@rfcbot
Copy link

rfcbot commented Feb 28, 2023

🔔 This is now entering its final comment period, as per the review above. 🔔

@m-ou-se m-ou-se removed the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Feb 28, 2023
@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Mar 10, 2023
@rfcbot
Copy link

rfcbot commented Mar 10, 2023

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2023
…tr, r=dtolnay

Stabilize path_as_mut_os_str

Closes rust-lang#105021

r? `@dtolnay`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2023
…tr, r=dtolnay

Stabilize path_as_mut_os_str

Closes rust-lang#105021

r? ``@dtolnay``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2023
…tr, r=dtolnay

Stabilize path_as_mut_os_str

Closes rust-lang#105021

r? ```@dtolnay```
@bors bors closed this as completed in 5b7ab80 Mar 11, 2023
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants