Skip to content

Conversation

@sourcefrog
Copy link
Contributor

@sourcefrog sourcefrog commented Jan 8, 2026

This documents one other OS-specific behavior that might be surprising to some users. The underlying behavior is documented in for example https://man7.org/linux/man-pages/man5/proc_pid_exe.5.html.

Rust std docs can't and shouldn't try to cover every single OS quirk but this seems reasonably in line with telling people how to use this function, and with the text above about what happens when the exe has been renamed.

This came up in the context of zed-industries/zed#46367

Fixes #69343 (by documenting the behavior)

@rustbot rustbot added 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 Jan 8, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2026

r? @joboet

rustbot has assigned @joboet.
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

@joboet
Copy link
Member

joboet commented Jan 9, 2026

r? libs-api

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 9, 2026
@rustbot rustbot assigned the8472 and unassigned joboet Jan 9, 2026
Copy link
Member

@the8472 the8472 left a comment

Choose a reason for hiding this comment

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

The convention is to put such things under a platform-specific behavior section + link to elaboration what that means.

Then we do not consider it a new API guarantee.

View changes since this review

@sourcefrog
Copy link
Contributor Author

sourcefrog commented Jan 9, 2026

The convention is to put such things under a platform-specific behavior section + link to elaboration what that means.

Then we do not consider it a new API guarantee.

This is already under a "platform-specific behavior" heading though?

https://github.com/sourcefrog/rust/blob/802cda98d90f8a9e181b90e0dd6be7c4c7a65946/library/std/src/env.rs#L698-L708

@sourcefrog
Copy link
Contributor Author

The convention is to put such things under a platform-specific behavior section + link to elaboration what that means.

Then we do not consider it a new API guarantee.

Beyond the scope of this PR, I do think some users will want to know what the behavior is on some particular platform: does it search $PATH, does it read /proc/self/exe, etc etc. At the moment they can read the source.

The API docs make minimal commitments with text like "some platforms may" but perhaps we should upgrade this to something like "Linux will xyz but this is subject to change?"

Anyhow I still think this is a step forward.

@the8472
Copy link
Member

the8472 commented Jan 10, 2026

This is already under a "platform-specific behavior" heading though?

Ah yes, then just add a link to the "subject to change" section.
The important point is that whatever is documented now may change it in the future, e.g. by returning an error when the path doesn't point to a real location, assuming linux provides some way to do so.

Beyond the scope of this PR, I do think some users will want to know what the behavior is on some particular platform: does it search $PATH, does it read /proc/self/exe, etc etc.

Yes, that's the stuff that can typically be put in that section.

@sourcefrog sourcefrog changed the title Document in current_exe that Linux can add " (deleted)" Document platform-specific behavior of current_exe, including that Linux can add " (deleted)" Jan 11, 2026
@sourcefrog
Copy link
Contributor Author

This is already under a "platform-specific behavior" heading though?

Ah yes, then just add a link to the "subject to change" section. The important point is that whatever is documented now may change it in the future, e.g. by returning an error when the path doesn't point to a real location, assuming linux provides some way to do so.

Beyond the scope of this PR, I do think some users will want to know what the behavior is on some particular platform: does it search $PATH, does it read /proc/self/exe, etc etc.

Yes, that's the stuff that can typically be put in that section.

Ah, thanks.

I've added that link, and since it says

Many I/O functions throughout the standard library are documented to indicate what various library or syscalls they are delegated to.

I've actually extended this to document all the currently implemented per-OS behavior by reading the current code.

@theemathas
Copy link
Contributor

See also #69343

@sourcefrog
Copy link
Contributor Author

@cuviper would you mind looking at this too while you're thinking about current_exe?

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. T-libs Relevant to the library team, which will review and decide on the 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 this pull request may close these issues.

current_exe() returns invalid path on linux when exe has been deleted

5 participants