Skip to content

Fix NamedTempFile constructors - #23292

Open
BenjaminBrienen wants to merge 2 commits into
rust-lang:masterfrom
BenjaminBrienen:fix-tempfile-new
Open

Fix NamedTempFile constructors#23292
BenjaminBrienen wants to merge 2 commits into
rust-lang:masterfrom
BenjaminBrienen:fix-tempfile-new

Conversation

@BenjaminBrienen

@BenjaminBrienen BenjaminBrienen commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

OpenOptions::create_new documentation:

/// The file must be opened with write or append access in order to create
/// a new file.
///
/// ```no_run
/// use std::fs::OpenOptions;
///
/// let file = OpenOptions::new().write(true)
///                              .create_new(true)
///                              .open("foo.txt");
/// ```

First commit demonstrates failing test. Error is like: creating or truncating a file requires write or append access.

https://github.com/rust-lang/rust-analyzer/actions/runs/33827828269/job/100884169555?pr=23292

Second commit is the fix. Can squash if approved.

I think this wasn't caught because it is only used in crates/proc-macro-srv/src/dylib.rs and only in #[cfg(windows)] and I'm not sure whether this issue appears on Windows in this circumstance.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 4, 2026
use super::*;
use std::sync::atomic::{AtomicUsize, Ordering};

static TEST_COUNTER: AtomicUsize = AtomicUsize::new(0);

@BenjaminBrienen BenjaminBrienen Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more complicated than it needs to be because I copy pasted these from what I was doing in another branch. I can simplify it if is a bother.

View changes since the review

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

I thought I already did that 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants