about summary refs log tree commit diff
path: root/library/std/src/sys/unix/process/process_common.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-22 10:34:45 +0000
committerbors <bors@rust-lang.org>2023-09-22 10:34:45 +0000
commit03c199af8e0f10c4fe4ead8e97e65286bef86e7d (patch)
tree9e771d0cbd662db18ef1cc7aaea1316a2e47307b /library/std/src/sys/unix/process/process_common.rs
parent5a4e47ebedb4132168c1b22262f21f0d3a2a96df (diff)
parent1a18ec0dcf88f35b4682e7f630cbd3b167b56e92 (diff)
downloadrust-03c199af8e0f10c4fe4ead8e97e65286bef86e7d.tar.gz
rust-03c199af8e0f10c4fe4ead8e97e65286bef86e7d.zip
Auto merge of #116054 - matthiaskrgr:rollup-3pusno6, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #114379 (Command: also print removed env vars)
 - #116034 (add UI test for delimiter errors)
 - #116036 (tests/ui: Split large_moves.rs and move to lint/large_assignments)
 - #116038 (Fall back to _SC_NPROCESSORS_ONLN if sched_getaffinity returns an empty mask)
 - #116039 (Account for nested `impl Trait` in TAIT)
 - #116041 (Add note to `is_known_rigid`)
 - #116049 (give FutureIncompatibilityReason variants more explicit names)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys/unix/process/process_common.rs')
-rw-r--r--library/std/src/sys/unix/process/process_common.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs
index f729da44774..1ca11a7f9d7 100644
--- a/library/std/src/sys/unix/process/process_common.rs
+++ b/library/std/src/sys/unix/process/process_common.rs
@@ -586,6 +586,23 @@ impl fmt::Debug for Command {
             if let Some(ref cwd) = self.cwd {
                 write!(f, "cd {cwd:?} && ")?;
             }
+            if self.env.does_clear() {
+                write!(f, "env -i ")?;
+                // Altered env vars will be printed next, that should exactly work as expected.
+            } else {
+                // Removed env vars need the command to be wrapped in `env`.
+                let mut any_removed = false;
+                for (key, value_opt) in self.get_envs() {
+                    if value_opt.is_none() {
+                        if !any_removed {
+                            write!(f, "env ")?;
+                            any_removed = true;
+                        }
+                        write!(f, "-u {} ", key.to_string_lossy())?;
+                    }
+                }
+            }
+            // Altered env vars can just be added in front of the program.
             for (key, value_opt) in self.get_envs() {
                 if let Some(value) = value_opt {
                     write!(f, "{}={value:?} ", key.to_string_lossy())?;