about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThalia Archibald <thalia@archibald.dev>2025-04-21 21:58:58 -0700
committerThalia Archibald <thalia@archibald.dev>2025-04-21 21:58:58 -0700
commit46952125661fa7bb6a016a6be4e03620da16a077 (patch)
tree03efad2645b720856fb3a9c21b91eeb9f973faaa
parent1b00ebefdfffc88dbcbf6057d156c5e62434ad43 (diff)
downloadrust-46952125661fa7bb6a016a6be4e03620da16a077.tar.gz
rust-46952125661fa7bb6a016a6be4e03620da16a077.zip
Deduplicate unsupported env items
-rw-r--r--library/std/src/sys/env/unsupported.rs9
-rw-r--r--library/std/src/sys/env/zkvm.rs41
2 files changed, 8 insertions, 42 deletions
diff --git a/library/std/src/sys/env/unsupported.rs b/library/std/src/sys/env/unsupported.rs
index 7ad76d8e31c..98905e64827 100644
--- a/library/std/src/sys/env/unsupported.rs
+++ b/library/std/src/sys/env/unsupported.rs
@@ -6,23 +6,20 @@ pub struct Env(!);
 impl Env {
     // FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
     pub fn str_debug(&self) -> impl fmt::Debug + '_ {
-        let Self(inner) = self;
-        match *inner {}
+        self.0
     }
 }
 
 impl fmt::Debug for Env {
     fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
-        let Self(inner) = self;
-        match *inner {}
+        self.0
     }
 }
 
 impl Iterator for Env {
     type Item = (OsString, OsString);
     fn next(&mut self) -> Option<(OsString, OsString)> {
-        let Self(inner) = self;
-        match *inner {}
+        self.0
     }
 }
 
diff --git a/library/std/src/sys/env/zkvm.rs b/library/std/src/sys/env/zkvm.rs
index 8d0bf7a198e..2eb7005ba12 100644
--- a/library/std/src/sys/env/zkvm.rs
+++ b/library/std/src/sys/env/zkvm.rs
@@ -1,35 +1,12 @@
+#[expect(dead_code)]
+#[path = "unsupported.rs"]
+mod unsupported_env;
+pub use unsupported_env::{Env, env, setenv, unsetenv};
+
 use crate::ffi::{OsStr, OsString};
 use crate::sys::os_str;
 use crate::sys::pal::{WORD_SIZE, abi};
 use crate::sys_common::FromInner;
-use crate::{fmt, io};
-
-pub struct Env(!);
-
-impl Iterator for Env {
-    type Item = (OsString, OsString);
-    fn next(&mut self) -> Option<(OsString, OsString)> {
-        self.0
-    }
-}
-
-pub fn env() -> Env {
-    panic!("not supported on this platform")
-}
-
-impl Env {
-    pub fn str_debug(&self) -> impl fmt::Debug + '_ {
-        let Self(inner) = self;
-        match *inner {}
-    }
-}
-
-impl fmt::Debug for Env {
-    fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
-        let Self(inner) = self;
-        match *inner {}
-    }
-}
 
 pub fn getenv(varname: &OsStr) -> Option<OsString> {
     let varname = varname.as_encoded_bytes();
@@ -53,11 +30,3 @@ pub fn getenv(varname: &OsStr) -> Option<OsString> {
     let u8s: &[u8] = unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, nbytes) };
     Some(OsString::from_inner(os_str::Buf { inner: u8s.to_vec() }))
 }
-
-pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {
-    Err(io::const_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))
-}
-
-pub unsafe fn unsetenv(_: &OsStr) -> io::Result<()> {
-    Err(io::const_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))
-}