Skip to content

Clarify doc comment on unix OpenOptions #142889

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

Merged
merged 1 commit into from
Jun 29, 2025
Merged

Conversation

nabijaczleweli
Copy link
Contributor

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Jun 22, 2025

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

@rustbot rustbot added O-unix Operating system: Unix-like 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 Jun 22, 2025
@nabijaczleweli
Copy link
Contributor Author

Also am I crazy or is this example nonsensical?

use std::fs::OpenOptions;
use std::os::unix::fs::OpenOptionsExt;

let mut options = OpenOptions::new();
options.write(true);
if cfg!(unix) {
    options.custom_flags(libc::O_NOFOLLOW);
}
let file = options.open("foo.txt");

You'd want this to be #[cfg(unix)] use std::os::unix::fs::OpenOptionsExt; and #[cfg(unix)] options.custom_flags(libc::O_NOFOLLOW); right?

@bjorn3
Copy link
Member

bjorn3 commented Jun 23, 2025

The example is already on a trait that is #[cfg(unix)]. And just adding #[cfg(unix)] would potentially introduce a symlink vulnerability on non-unic systems.

@nabijaczleweli
Copy link
Contributor Author

Under that analysis, what's the if cfg!(unix) doing there, since that's guaranteed to be true?

@bjorn3
Copy link
Member

bjorn3 commented Jun 23, 2025

Right. When that example is tested, it is always true.

@ChrisDenton
Copy link
Member

This is perhaps a bigger issue than this PR seeks to deal with but would it be possible to be rid of the #![feature(rustc_private)]? I don't love having that in a doc test especially because it does leak to users via the playground button. It's a no-run test anyway so maybe it could have a fake mod libc that defines the var?

@nabijaczleweli
Copy link
Contributor Author

mod libc { const O_NOFOLLOW: i32 = 0; } would be a valid substitution if this weren't no-run anyway, applied

@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum Mark-Simulacrum changed the title "set by Rusts options" Clarify doc comment on unix OpenOptions Jun 28, 2025
@Mark-Simulacrum
Copy link
Member

r=me with commits squashed

@nabijaczleweli
Copy link
Contributor Author

squashed

@Mark-Simulacrum
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 28, 2025

📌 Commit 45204ef has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors 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 Jun 28, 2025
bors added a commit that referenced this pull request Jun 29, 2025
Rollup of 11 pull requests

Successful merges:

 - #142021 (Doc: clarify priority of lint level sources)
 - #142367 (Add regression test for #137857 to ensure that we generate intra doc links for extern crate items.)
 - #142641 (Generate symbols.o for proc-macros too)
 - #142889 (Clarify doc comment on unix OpenOptions)
 - #143063 (explain `ImportData::imported_module`)
 - #143088 (Improve documentation of `TagEncoding`)
 - #143135 (fix typos on some doc comments)
 - #143138 (Port `#[link_name]` to the new attribute parsing infrastructure)
 - #143155 (`librustdoc` house-keeping 🧹)
 - #143169 (Remove unused feature gates)
 - #143171 (Fix the span of trait bound modifier `[const]`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit eef87fd into rust-lang:master Jun 29, 2025
10 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jun 29, 2025
rust-timer added a commit that referenced this pull request Jun 29, 2025
Rollup merge of #142889 - nabijaczleweli:rusts, r=Mark-Simulacrum

Clarify doc comment on unix OpenOptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix Operating system: Unix-like 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.

7 participants