Skip to content

Commit 4695212

Browse files
committed
Deduplicate unsupported env items
1 parent 1b00ebe commit 4695212

File tree

2 files changed

+8
-42
lines changed

2 files changed

+8
-42
lines changed

library/std/src/sys/env/unsupported.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ pub struct Env(!);
66
impl Env {
77
// FIXME(https://github.com/rust-lang/rust/issues/114583): Remove this when <OsStr as Debug>::fmt matches <str as Debug>::fmt.
88
pub fn str_debug(&self) -> impl fmt::Debug + '_ {
9-
let Self(inner) = self;
10-
match *inner {}
9+
self.0
1110
}
1211
}
1312

1413
impl fmt::Debug for Env {
1514
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
16-
let Self(inner) = self;
17-
match *inner {}
15+
self.0
1816
}
1917
}
2018

2119
impl Iterator for Env {
2220
type Item = (OsString, OsString);
2321
fn next(&mut self) -> Option<(OsString, OsString)> {
24-
let Self(inner) = self;
25-
match *inner {}
22+
self.0
2623
}
2724
}
2825

library/std/src/sys/env/zkvm.rs

+5-36
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,12 @@
1+
#[expect(dead_code)]
2+
#[path = "unsupported.rs"]
3+
mod unsupported_env;
4+
pub use unsupported_env::{Env, env, setenv, unsetenv};
5+
16
use crate::ffi::{OsStr, OsString};
27
use crate::sys::os_str;
38
use crate::sys::pal::{WORD_SIZE, abi};
49
use crate::sys_common::FromInner;
5-
use crate::{fmt, io};
6-
7-
pub struct Env(!);
8-
9-
impl Iterator for Env {
10-
type Item = (OsString, OsString);
11-
fn next(&mut self) -> Option<(OsString, OsString)> {
12-
self.0
13-
}
14-
}
15-
16-
pub fn env() -> Env {
17-
panic!("not supported on this platform")
18-
}
19-
20-
impl Env {
21-
pub fn str_debug(&self) -> impl fmt::Debug + '_ {
22-
let Self(inner) = self;
23-
match *inner {}
24-
}
25-
}
26-
27-
impl fmt::Debug for Env {
28-
fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result {
29-
let Self(inner) = self;
30-
match *inner {}
31-
}
32-
}
3310

3411
pub fn getenv(varname: &OsStr) -> Option<OsString> {
3512
let varname = varname.as_encoded_bytes();
@@ -53,11 +30,3 @@ pub fn getenv(varname: &OsStr) -> Option<OsString> {
5330
let u8s: &[u8] = unsafe { crate::slice::from_raw_parts(words.cast() as *const u8, nbytes) };
5431
Some(OsString::from_inner(os_str::Buf { inner: u8s.to_vec() }))
5532
}
56-
57-
pub unsafe fn setenv(_: &OsStr, _: &OsStr) -> io::Result<()> {
58-
Err(io::const_error!(io::ErrorKind::Unsupported, "cannot set env vars on this platform"))
59-
}
60-
61-
pub unsafe fn unsetenv(_: &OsStr) -> io::Result<()> {
62-
Err(io::const_error!(io::ErrorKind::Unsupported, "cannot unset env vars on this platform"))
63-
}

0 commit comments

Comments
 (0)