Repository navigation
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.T-libsRelevant to the library team, which will review and decide on the PR/issue.
Description
Feature gate: #![feature(command_resolved_envs)]
This is a tracking issue for the API Change Proposal (ACP) rust-lang/libs-team#194.
This feature adds two methods to std::process::Command to expose environment variable resolution logic, addressing the inability to observe the effects of env_clear() and the lack of a single source of truth for environment variable resolution.
Public API
// std::process
impl Command {
pub fn get_env_clear(&self) -> bool;
pub fn get_resolved_envs(&self) -> CommandResolvedEnvs;
}
// `get_resolved_envs` returns a concrete iterator type:
pub struct CommandResolvedEnvs { /* .. */ }
impl Iterator for CommandResolvedEnvs {
type Item = (OsString, OsString);
// ..
}Explanation:
get_env_clearThis makes sure people have all the information Command stores.get_resolved_envsThis should include documentation that says it returns the environment as it would be if the command were executed at that point, and will not match if the environment is subsequently changed (including in a pre_exec hook). This avoids duplicating the Command logic.
Steps / History
(Remember to update the S-tracking-* label when checking boxes.)
- ACP: rust-lang/libs-team#194
- Implementation:
-
get_env_clear: Add Command::get_env_clear #149074 -
get_resolved_envs: Add Command::get_resolved_envs #149362
-
- Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
Both questions raised at filing time have been resolved during implementation:
Should this useResolved:impl Iteratorin the return type, or a concrete iterator type?get_resolved_envsreturns a concrete iterator type (CommandResolvedEnvs), matching the precedent set bystd::env::vars_os/std::env::VarsOsand leaving room to add impls such asDebug. See #149362 and this comment.Should we allow borrowing fromResolved: the iterator yields ownedstd::process::Command(or other sources) in the returned iterator, rather than requiring(OsString, OsString)which implies fresh allocations for each environment variable and value on every iteration?(OsString, OsString), consistent withstd::env::vars_os. Anyone able to spawn a process can afford these allocations, which are negligible relative to process spawning.
Footnotes
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.T-libsRelevant to the library team, which will review and decide on the PR/issue.
Activity
Add Command::get_env_clear
Rollup merge of rust-lang#149074 - schneems:schneems/get_env_clear, r…
Rollup merge of rust-lang#149074 - schneems:schneems/get_env_clear, r…
Rollup merge of rust-lang#149074 - schneems:schneems/get_env_clear, r…
Add Command::get_resolved_envs
Add Command::get_resolved_envs
Add Command::get_resolved_envs
Rollup merge of rust-lang#149074 - schneems:schneems/get_env_clear, r…
Unrolled build for #149074
schneems commentedon Jan 14, 2026
I'm good with either, I picked
impl Iteratorbased on comment from rust-lang/libs-team#194. I think naming is possibly an issue. I think if we want to add things to the implementation likeDebugthen we should go with concrete.The closest existing API would be https://doc.rust-lang.org/std/env/fn.vars_os.html which returns https://doc.rust-lang.org/std/env/struct.VarsOs.html (concrete iterator)
For my needs (OsString, OsString) is fine. I think any system where you can spawn a process you can allocate. If you're working with process spawning then I don't think string allocation will be a comparatively large bottleneck. Mentioned above that https://doc.rust-lang.org/std/env/struct.VarsOs.html returns
(OsString, OsString).Add Command::get_env_clear
Rollup merge of rust-lang#149074 - schneems:schneems/get_env_clear, r…
schneems commentedon Mar 2, 2026
I've updated #149362 to use a concrete type.
Rollup merge of rust-lang#149362 - schneems:schneems/get_resolved_env…
Rollup merge of rust-lang#149362 - schneems:schneems/get_resolved_env…
Rollup merge of rust-lang#149362 - schneems:schneems/get_resolved_env…
Rollup merge of rust-lang#149362 - schneems:schneems/get_resolved_env…
Auto merge of #149362 - schneems:schneems/get_resolved_envs, r=Mark-S…
Auto merge of #149362 - schneems:schneems/get_resolved_envs, r=Mark-S…
schneems commentedon Jun 28, 2026
The implementation has landed in two merged PRs:
get_env_clear: Add Command::get_env_clear #149074get_resolved_envs: Add Command::get_resolved_envs #149362Updated the tracking issue checklist accordingly. Both unresolved questions were settled during implementation (concrete
CommandResolvedEnvsiterator type yielding owned(OsString, OsString), matchingstd::env::vars_os).@rustbot label -S-tracking-unimplemented +S-tracking-needs-to-bake
schneems commentedon Jul 18, 2026
I've shipped these features with a
build.rsgating in thefun_runcrate:So far, so good. I'm happy with the resolved env iterator.