Skip to content

fix: Switch from temp-dir to a homemade NamedTempFile implementation - #23206

Merged
ShoyuVanilla merged 1 commit into
rust-lang:masterfrom
ChayimFriedman2:tempfile
Aug 26, 2026
Merged

fix: Switch from temp-dir to a homemade NamedTempFile implementation#23206
ShoyuVanilla merged 1 commit into
rust-lang:masterfrom
ChayimFriedman2:tempfile

Conversation

@ChayimFriedman2

Copy link
Copy Markdown
Contributor

That also deletes the file when the process exits without being dropped; this is important especially for the proc macro server since it is killed and does not exit normally.

Linux and the BSDs unlink the file then access it via /proc/self/fd or /dev/fd; Windows has a dedicated API for that; and macOS unfortunately does not support that (the file is not removed after being unlinked, but you cannot access it anymore via /dev/fd, or at least that's what the AI said - I don't have a macOS machine to check).

Fixes #23203.

That also deletes the file when the process exits without being dropped; this is important especially for the proc macro server since it is killed and does not exit normally.

Linux and the BSDs unlink the file then access it via `/proc/self/fd` or `/dev/fd`; Windows has a dedicated API for that; and macOS unfortunately does not support that (the file is not removed after being unlinked, but you cannot access it anymore via `/dev/fd`, or at least that's what the AI said - I don't have a macOS machine to check).
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 21, 2026

@ShoyuVanilla ShoyuVanilla left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was the one who has introduced temp-dir to our dependency tree because it has pretty simple implementation. But your implementation looks very clever (especially for the unlink part) while being not too verbose 😄

View changes since this review

@ShoyuVanilla
ShoyuVanilla added this pull request to the merge queue Aug 26, 2026
Merged via the queue into rust-lang:master with commit 0f5ab5c Aug 26, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 26, 2026
@ChayimFriedman2

Copy link
Copy Markdown
Contributor Author

But your implementation looks very clever (especially for the unlink part)

Credit where credit is due; this was the AI's idea (not original probably). Of course I verified in the POSIX specification that unlink() does not remove the file if it's open.

@ChayimFriedman2
ChayimFriedman2 deleted the tempfile branch August 26, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ra leaves empty proc-macro-srv dir behind

3 participants