Skip to content

Commit 926f364

Browse files
committed
move cvt
1 parent a47e3c0 commit 926f364

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

src/libstd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ compiler_builtins = { version = "0.1.16" }
2424
profiler_builtins = { path = "../libprofiler_builtins", optional = true }
2525
unwind = { path = "../libunwind" }
2626
hashbrown = { version = "0.5.0", features = ['rustc-dep-of-std'] }
27+
wasi = { git = "https://github.com/newpavlov/rust-wasi", branch = "safe_rework", features = ['rustc-dep-of-std', 'alloc'] }
2728

2829
[dependencies.backtrace]
2930
version = "0.3.35"

src/libstd/sys/wasi/mod.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,6 @@ pub fn hashmap_random_keys() -> (u64, u64) {
102102
return ret
103103
}
104104

105-
#[doc(hidden)]
106-
pub trait IsMinusOne {
107-
fn is_minus_one(&self) -> bool;
108-
}
109-
110-
macro_rules! impl_is_minus_one {
111-
($($t:ident)*) => ($(impl IsMinusOne for $t {
112-
fn is_minus_one(&self) -> bool {
113-
*self == -1
114-
}
115-
})*)
116-
}
117-
118-
impl_is_minus_one! { i8 i16 i32 i64 isize }
119-
120-
pub fn cvt<T: IsMinusOne>(t: T) -> std_io::Result<T> {
121-
if t.is_minus_one() {
122-
Err(std_io::Error::last_os_error())
123-
} else {
124-
Ok(t)
125-
}
126-
}
127-
128105
fn err2io(err: wasi::Error) -> std_io::Error {
129106
std_io::Error::from_raw_os_error(err.get() as i32)
130107
}

src/libstd/sys/wasi/os.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::path::{self, PathBuf};
99
use crate::ptr;
1010
use crate::str;
1111
use crate::sys::memchr;
12-
use crate::sys::{cvt, unsupported, Void};
12+
use crate::sys::{unsupported, Void};
1313
use crate::vec;
1414

1515
#[cfg(not(target_feature = "atomics"))]
@@ -176,3 +176,26 @@ pub fn exit(code: i32) -> ! {
176176
pub fn getpid() -> u32 {
177177
panic!("unsupported");
178178
}
179+
180+
#[doc(hidden)]
181+
pub trait IsMinusOne {
182+
fn is_minus_one(&self) -> bool;
183+
}
184+
185+
macro_rules! impl_is_minus_one {
186+
($($t:ident)*) => ($(impl IsMinusOne for $t {
187+
fn is_minus_one(&self) -> bool {
188+
*self == -1
189+
}
190+
})*)
191+
}
192+
193+
impl_is_minus_one! { i8 i16 i32 i64 isize }
194+
195+
fn cvt<T: IsMinusOne>(t: T) -> io::Result<T> {
196+
if t.is_minus_one() {
197+
Err(io::Error::last_os_error())
198+
} else {
199+
Ok(t)
200+
}
201+
}

0 commit comments

Comments
 (0)