diff options
| author | David Tolnay <dtolnay@gmail.com> | 2019-11-27 10:28:39 -0800 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2019-11-29 18:37:58 -0800 |
| commit | c34fbfaad38cf5829ef5cfe780dc9d58480adeaa (patch) | |
| tree | e57b66ed06aec18dc13ff7f14a243ca3dc3c27d1 /src/libstd/sys/hermit | |
| parent | 9081929d45f12d3f56d43b1d6db7519981580fc9 (diff) | |
| download | rust-c34fbfaad38cf5829ef5cfe780dc9d58480adeaa.tar.gz rust-c34fbfaad38cf5829ef5cfe780dc9d58480adeaa.zip | |
Format libstd/sys with rustfmt
This commit applies rustfmt with rust-lang/rust's default settings to
files in src/libstd/sys *that are not involved in any currently open PR*
to minimize merge conflicts. THe list of files involved in open PRs was
determined by querying GitHub's GraphQL API with this script:
https://gist.github.com/dtolnay/aa9c34993dc051a4f344d1b10e4487e8
With the list of files from the script in outstanding_files, the
relevant commands were:
$ find src/libstd/sys -name '*.rs' \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ rg libstd/sys outstanding_files | xargs git checkout --
Repeating this process several months apart should get us coverage of
most of the rest of the files.
To confirm no funny business:
$ git checkout $THIS_COMMIT^
$ git show --pretty= --name-only $THIS_COMMIT \
| xargs rustfmt --edition=2018 --unstable-features --skip-children
$ git diff $THIS_COMMIT # there should be no difference
Diffstat (limited to 'src/libstd/sys/hermit')
| -rw-r--r-- | src/libstd/sys/hermit/alloc.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/args.rs | 45 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/cmath.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/condvar.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/fd.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/fs.rs | 84 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/mod.rs | 46 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/mutex.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/net.rs | 19 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/os.rs | 49 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/path.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/pipe.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/process.rs | 29 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/rwlock.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/stack_overflow.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/stdio.rs | 17 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/thread.rs | 42 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/thread_local.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sys/hermit/time.rs | 45 |
19 files changed, 211 insertions, 220 deletions
diff --git a/src/libstd/sys/hermit/alloc.rs b/src/libstd/sys/hermit/alloc.rs index 86cc4463632..d153914e77e 100644 --- a/src/libstd/sys/hermit/alloc.rs +++ b/src/libstd/sys/hermit/alloc.rs @@ -13,11 +13,7 @@ unsafe impl GlobalAlloc for System { let addr = abi::malloc(layout.size(), layout.align()); if !addr.is_null() { - ptr::write_bytes( - addr, - 0x00, - layout.size() - ); + ptr::write_bytes(addr, 0x00, layout.size()); } addr diff --git a/src/libstd/sys/hermit/args.rs b/src/libstd/sys/hermit/args.rs index 5b1f3add51f..72c1b8511ca 100644 --- a/src/libstd/sys/hermit/args.rs +++ b/src/libstd/sys/hermit/args.rs @@ -3,10 +3,14 @@ use crate::marker::PhantomData; use crate::vec; /// One-time global initialization. -pub unsafe fn init(argc: isize, argv: *const *const u8) { imp::init(argc, argv) } +pub unsafe fn init(argc: isize, argv: *const *const u8) { + imp::init(argc, argv) +} /// One-time global cleanup. -pub unsafe fn cleanup() { imp::cleanup() } +pub unsafe fn cleanup() { + imp::cleanup() +} /// Returns the command line arguments pub fn args() -> Args { @@ -26,24 +30,32 @@ impl Args { impl Iterator for Args { type Item = OsString; - fn next(&mut self) -> Option<OsString> { self.iter.next() } - fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() } + fn next(&mut self) -> Option<OsString> { + self.iter.next() + } + fn size_hint(&self) -> (usize, Option<usize>) { + self.iter.size_hint() + } } impl ExactSizeIterator for Args { - fn len(&self) -> usize { self.iter.len() } + fn len(&self) -> usize { + self.iter.len() + } } impl DoubleEndedIterator for Args { - fn next_back(&mut self) -> Option<OsString> { self.iter.next_back() } + fn next_back(&mut self) -> Option<OsString> { + self.iter.next_back() + } } mod imp { - use crate::sys_common::os_str_bytes::*; - use crate::ptr; + use super::Args; use crate::ffi::{CStr, OsString}; use crate::marker::PhantomData; - use super::Args; + use crate::ptr; + use crate::sys_common::os_str_bytes::*; use crate::sys_common::mutex::Mutex; @@ -64,19 +76,18 @@ mod imp { } pub fn args() -> Args { - Args { - iter: clone().into_iter(), - _dont_send_or_sync_me: PhantomData - } + Args { iter: clone().into_iter(), _dont_send_or_sync_me: PhantomData } } fn clone() -> Vec<OsString> { unsafe { let _guard = LOCK.lock(); - (0..ARGC).map(|i| { - let cstr = CStr::from_ptr(*ARGV.offset(i) as *const i8); - OsStringExt::from_vec(cstr.to_bytes().to_vec()) - }).collect() + (0..ARGC) + .map(|i| { + let cstr = CStr::from_ptr(*ARGV.offset(i) as *const i8); + OsStringExt::from_vec(cstr.to_bytes().to_vec()) + }) + .collect() } } } diff --git a/src/libstd/sys/hermit/cmath.rs b/src/libstd/sys/hermit/cmath.rs index fa7783122c2..304cf906b2a 100644 --- a/src/libstd/sys/hermit/cmath.rs +++ b/src/libstd/sys/hermit/cmath.rs @@ -1,5 +1,5 @@ // These symbols are all defined in `compiler-builtins` -extern { +extern "C" { pub fn acos(n: f64) -> f64; pub fn acosf(n: f32) -> f32; pub fn asin(n: f64) -> f64; diff --git a/src/libstd/sys/hermit/condvar.rs b/src/libstd/sys/hermit/condvar.rs index 8e52b3da1b1..5b7f16ce562 100644 --- a/src/libstd/sys/hermit/condvar.rs +++ b/src/libstd/sys/hermit/condvar.rs @@ -18,12 +18,12 @@ impl Condvar { } pub unsafe fn notify_one(&self) { - let _ = abi::notify(self.id(), 1); + let _ = abi::notify(self.id(), 1); } #[inline] pub unsafe fn notify_all(&self) { - let _ = abi::notify(self.id(), -1 /* =all */); + let _ = abi::notify(self.id(), -1 /* =all */); } pub unsafe fn wait(&self, mutex: &Mutex) { diff --git a/src/libstd/sys/hermit/fd.rs b/src/libstd/sys/hermit/fd.rs index 84c54736647..f2f61fdfb8c 100644 --- a/src/libstd/sys/hermit/fd.rs +++ b/src/libstd/sys/hermit/fd.rs @@ -1,6 +1,6 @@ #![unstable(reason = "not public", issue = "0", feature = "fd")] -use crate::io::{self, Read, ErrorKind}; +use crate::io::{self, ErrorKind, Read}; use crate::mem; use crate::sys::cvt; use crate::sys::hermit::abi; @@ -16,7 +16,9 @@ impl FileDesc { FileDesc { fd } } - pub fn raw(&self) -> i32 { self.fd } + pub fn raw(&self) -> i32 { + self.fd + } /// Extracts the actual file descriptor without closing it. pub fn into_raw(self) -> i32 { @@ -67,7 +69,9 @@ impl<'a> Read for &'a FileDesc { } impl AsInner<i32> for FileDesc { - fn as_inner(&self) -> &i32 { &self.fd } + fn as_inner(&self) -> &i32 { + &self.fd + } } impl Drop for FileDesc { diff --git a/src/libstd/sys/hermit/fs.rs b/src/libstd/sys/hermit/fs.rs index f8e5844a167..37ac5984eee 100644 --- a/src/libstd/sys/hermit/fs.rs +++ b/src/libstd/sys/hermit/fs.rs @@ -1,14 +1,14 @@ -use crate::ffi::{OsString, CString, CStr}; +use crate::ffi::{CStr, CString, OsString}; use crate::fmt; -use crate::io::{self, Error, ErrorKind}; use crate::hash::{Hash, Hasher}; -use crate::io::{SeekFrom, IoSlice, IoSliceMut}; +use crate::io::{self, Error, ErrorKind}; +use crate::io::{IoSlice, IoSliceMut, SeekFrom}; use crate::path::{Path, PathBuf}; -use crate::sys::time::SystemTime; -use crate::sys::{unsupported, Void}; +use crate::sys::cvt; use crate::sys::hermit::abi; use crate::sys::hermit::fd::FileDesc; -use crate::sys::cvt; +use crate::sys::time::SystemTime; +use crate::sys::{unsupported, Void}; use crate::sys_common::os_str_bytes::OsStrExt; pub use crate::sys_common::fs::copy; @@ -45,7 +45,7 @@ pub struct OpenOptions { create: bool, create_new: bool, // system-specific - mode: i32 + mode: i32, } pub struct FilePermissions(Void); @@ -53,7 +53,7 @@ pub struct FilePermissions(Void); pub struct FileType(Void); #[derive(Debug)] -pub struct DirBuilder { } +pub struct DirBuilder {} impl FileAttr { pub fn size(&self) -> u64 { @@ -109,8 +109,7 @@ impl PartialEq for FilePermissions { } } -impl Eq for FilePermissions { -} +impl Eq for FilePermissions {} impl fmt::Debug for FilePermissions { fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -146,8 +145,7 @@ impl PartialEq for FileType { } } -impl Eq for FileType { -} +impl Eq for FileType {} impl Hash for FileType { fn hash<H: Hasher>(&self, _h: &mut H) { @@ -204,50 +202,64 @@ impl OpenOptions { create: false, create_new: false, // system-specific - mode: 0x777 + mode: 0x777, } } - pub fn read(&mut self, read: bool) { self.read = read; } - pub fn write(&mut self, write: bool) { self.write = write; } - pub fn append(&mut self, append: bool) { self.append = append; } - pub fn truncate(&mut self, truncate: bool) { self.truncate = truncate; } - pub fn create(&mut self, create: bool) { self.create = create; } - pub fn create_new(&mut self, create_new: bool) { self.create_new = create_new; } + pub fn read(&mut self, read: bool) { + self.read = read; + } + pub fn write(&mut self, write: bool) { + self.write = write; + } + pub fn append(&mut self, append: bool) { + self.append = append; + } + pub fn truncate(&mut self, truncate: bool) { + self.truncate = truncate; + } + pub fn create(&mut self, create: bool) { + self.create = create; + } + pub fn create_new(&mut self, create_new: bool) { + self.create_new = create_new; + } fn get_access_mode(&self) -> io::Result<i32> { match (self.read, self.write, self.append) { - (true, false, false) => Ok(O_RDONLY), - (false, true, false) => Ok(O_WRONLY), - (true, true, false) => Ok(O_RDWR), - (false, _, true) => Ok(O_WRONLY | O_APPEND), - (true, _, true) => Ok(O_RDWR | O_APPEND), + (true, false, false) => Ok(O_RDONLY), + (false, true, false) => Ok(O_WRONLY), + (true, true, false) => Ok(O_RDWR), + (false, _, true) => Ok(O_WRONLY | O_APPEND), + (true, _, true) => Ok(O_RDWR | O_APPEND), (false, false, false) => { Err(io::Error::new(ErrorKind::InvalidInput, "invalid access mode")) - }, + } } } fn get_creation_mode(&self) -> io::Result<i32> { match (self.write, self.append) { (true, false) => {} - (false, false) => + (false, false) => { if self.truncate || self.create || self.create_new { return Err(io::Error::new(ErrorKind::InvalidInput, "invalid creation mode")); - }, - (_, true) => + } + } + (_, true) => { if self.truncate && !self.create_new { return Err(io::Error::new(ErrorKind::InvalidInput, "invalid creation mode")); - }, + } + } } Ok(match (self.create, self.truncate, self.create_new) { - (false, false, false) => 0, - (true, false, false) => O_CREAT, - (false, true, false) => O_TRUNC, - (true, true, false) => O_CREAT | O_TRUNC, - (_, _, true) => O_CREAT | O_EXCL, - }) + (false, false, false) => 0, + (true, false, false) => O_CREAT, + (false, true, false) => O_TRUNC, + (true, true, false) => O_CREAT | O_TRUNC, + (_, _, true) => O_CREAT | O_EXCL, + }) } } @@ -327,7 +339,7 @@ impl File { impl DirBuilder { pub fn new() -> DirBuilder { - DirBuilder { } + DirBuilder {} } pub fn mkdir(&self, _p: &Path) -> io::Result<()> { diff --git a/src/libstd/sys/hermit/mod.rs b/src/libstd/sys/hermit/mod.rs index d4359631769..1e4a53abdc7 100644 --- a/src/libstd/sys/hermit/mod.rs +++ b/src/libstd/sys/hermit/mod.rs @@ -13,34 +13,34 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! -use crate::os::raw::c_char; use crate::intrinsics; +use crate::os::raw::c_char; pub mod alloc; pub mod args; -pub mod condvar; -pub mod stdio; -pub mod memchr; -pub mod io; -pub mod mutex; -pub mod rwlock; -pub mod os; pub mod cmath; -pub mod thread; +pub mod condvar; pub mod env; -pub mod fs; +pub mod fast_thread_local; pub mod fd; +pub mod fs; +pub mod io; +pub mod memchr; +pub mod mutex; pub mod net; +pub mod os; pub mod path; pub mod pipe; pub mod process; +pub mod rwlock; pub mod stack_overflow; -pub mod time; +pub mod stdio; +pub mod thread; pub mod thread_local; -pub mod fast_thread_local; +pub mod time; -pub use crate::sys_common::os_str_bytes as os_str; use crate::io::ErrorKind; +pub use crate::sys_common::os_str_bytes as os_str; #[allow(unused_extern_crates)] pub extern crate hermit_abi as abi; @@ -50,8 +50,7 @@ pub fn unsupported<T>() -> crate::io::Result<T> { } pub fn unsupported_err() -> crate::io::Error { - crate::io::Error::new(crate::io::ErrorKind::Other, - "operation not supported on HermitCore yet") + crate::io::Error::new(crate::io::ErrorKind::Other, "operation not supported on HermitCore yet") } // This enum is used as the storage for a bunch of types which can't actually @@ -71,9 +70,7 @@ pub unsafe fn strlen(start: *const c_char) -> usize { #[no_mangle] pub extern "C" fn floor(x: f64) -> f64 { - unsafe { - intrinsics::floorf64(x) - } + unsafe { intrinsics::floorf64(x) } } pub unsafe fn abort_internal() -> ! { @@ -103,8 +100,11 @@ pub fn init() { #[cfg(not(test))] #[no_mangle] -pub unsafe extern "C" fn runtime_entry(argc: i32, argv: *const *const c_char, - env: *const *const c_char) -> ! { +pub unsafe extern "C" fn runtime_entry( + argc: i32, + argv: *const *const c_char, + env: *const *const c_char, +) -> ! { extern "C" { fn main(argc: isize, argv: *const *const c_char) -> i32; } @@ -139,9 +139,5 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { } pub fn cvt(result: i32) -> crate::io::Result<usize> { - if result < 0 { - Err(crate::io::Error::from_raw_os_error(-result)) - } else { - Ok(result as usize) - } + if result < 0 { Err(crate::io::Error::from_raw_os_error(-result)) } else { Ok(result as usize) } } diff --git a/src/libstd/sys/hermit/mutex.rs b/src/libstd/sys/hermit/mutex.rs index 9414bf8fbbb..b5c75f738d2 100644 --- a/src/libstd/sys/hermit/mutex.rs +++ b/src/libstd/sys/hermit/mutex.rs @@ -1,9 +1,9 @@ -use crate::ptr; use crate::ffi::c_void; +use crate::ptr; use crate::sys::hermit::abi; pub struct Mutex { - inner: *const c_void + inner: *const c_void, } unsafe impl Send for Mutex {} @@ -42,7 +42,7 @@ impl Mutex { } pub struct ReentrantMutex { - inner: *const c_void + inner: *const c_void, } impl ReentrantMutex { diff --git a/src/libstd/sys/hermit/net.rs b/src/libstd/sys/hermit/net.rs index 5b7ff642271..82917e71be1 100644 --- a/src/libstd/sys/hermit/net.rs +++ b/src/libstd/sys/hermit/net.rs @@ -1,7 +1,7 @@ -use crate::fmt; use crate::convert::TryFrom; +use crate::fmt; use crate::io::{self, IoSlice, IoSliceMut}; -use crate::net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; +use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; use crate::str; use crate::sys::{unsupported, Void}; use crate::time::Duration; @@ -234,23 +234,19 @@ impl UdpSocket { match self.0 {} } - pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) - -> io::Result<()> { + pub fn join_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> { match self.0 {} } - pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) - -> io::Result<()> { + pub fn join_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> { match self.0 {} } - pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) - -> io::Result<()> { + pub fn leave_multicast_v4(&self, _: &Ipv4Addr, _: &Ipv4Addr) -> io::Result<()> { match self.0 {} } - pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) - -> io::Result<()> { + pub fn leave_multicast_v6(&self, _: &Ipv6Addr, _: u32) -> io::Result<()> { match self.0 {} } @@ -357,8 +353,7 @@ pub mod netc { } #[derive(Copy, Clone)] - pub struct sockaddr { - } + pub struct sockaddr {} pub type socklen_t = usize; } diff --git a/src/libstd/sys/hermit/os.rs b/src/libstd/sys/hermit/os.rs index 8a25cbcf07b..ad63b0e0c13 100644 --- a/src/libstd/sys/hermit/os.rs +++ b/src/libstd/sys/hermit/os.rs @@ -1,5 +1,6 @@ +use crate::collections::HashMap; use crate::error::Error as StdError; -use crate::ffi::{CStr, OsString, OsStr}; +use crate::ffi::{CStr, OsStr, OsString}; use crate::fmt; use crate::io; use crate::marker::PhantomData; @@ -7,12 +8,11 @@ use crate::memchr; use crate::path::{self, PathBuf}; use crate::ptr; use crate::str; -use crate::sys::{unsupported, Void}; -use crate::collections::HashMap; -use crate::vec; use crate::sync::Mutex; -use crate::sys_common::os_str_bytes::*; use crate::sys::hermit::abi; +use crate::sys::{unsupported, Void}; +use crate::sys_common::os_str_bytes::*; +use crate::vec; pub fn errno() -> i32 { 0 @@ -47,7 +47,9 @@ impl<'a> Iterator for SplitPaths<'a> { pub struct JoinPathsError; pub fn join_paths<I, T>(_paths: I) -> Result<OsString, JoinPathsError> - where I: Iterator<Item=T>, T: AsRef<OsStr> +where + I: Iterator<Item = T>, + T: AsRef<OsStr>, { Err(JoinPathsError) } @@ -77,7 +79,7 @@ pub fn init_environment(env: *const *const i8) { let mut guard = ENV.as_ref().unwrap().lock().unwrap(); let mut environ = env; while environ != ptr::null() && *environ != ptr::null() { - if let Some((key,value)) = parse(CStr::from_ptr(*environ).to_bytes()) { + if let Some((key, value)) = parse(CStr::from_ptr(*environ).to_bytes()) { guard.insert(key, value); } environ = environ.offset(1); @@ -93,10 +95,12 @@ pub fn init_environment(env: *const *const i8) { return None; } let pos = memchr::memchr(b'=', &input[1..]).map(|p| p + 1); - pos.map(|p| ( - OsStringExt::from_vec(input[..p].to_vec()), - OsStringExt::from_vec(input[p+1..].to_vec()), - )) + pos.map(|p| { + ( + OsStringExt::from_vec(input[..p].to_vec()), + OsStringExt::from_vec(input[p + 1..].to_vec()), + ) + }) } } @@ -107,14 +111,18 @@ pub struct Env { impl Iterator for Env { type Item = (OsString, OsString); - fn next(&mut self) -> Option<(OsString, OsString)> { self.iter.next() } - fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() } + fn next(&mut self) -> Option<(OsString, OsString)> { + self.iter.next() + } + fn size_hint(&self) -> (usize, Option<usize>) { + self.iter.size_hint() + } } /// Returns a vector of (variable, value) byte-vector pairs for all the /// environment variables of the current process. pub fn env() -> Env { - unsafe { + unsafe { let guard = ENV.as_ref().unwrap().lock().unwrap(); let mut result = Vec::new(); @@ -122,18 +130,15 @@ pub fn env() -> Env { result.push((key.clone(), value.clone())); } - return Env { - iter: result.into_iter(), - _dont_send_or_sync_me: PhantomData, - } + return Env { iter: result.into_iter(), _dont_send_or_sync_me: PhantomData }; } } pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { unsafe { match ENV.as_ref().unwrap().lock().unwrap().get_mut(k) { - Some(value) => { Ok(Some(value.clone())) }, - None => { Ok(None) }, + Some(value) => Ok(Some(value.clone())), + None => Ok(None), } } } @@ -168,7 +173,5 @@ pub fn exit(code: i32) -> ! { } pub fn getpid() -> u32 { - unsafe { - abi::getpid() - } + unsafe { abi::getpid() } } diff --git a/src/libstd/sys/hermit/path.rs b/src/libstd/sys/hermit/path.rs index 7a183956107..840a7ae0426 100644 --- a/src/libstd/sys/hermit/path.rs +++ b/src/libstd/sys/hermit/path.rs @@ -1,5 +1,5 @@ -use crate::path::Prefix; use crate::ffi::OsStr; +use crate::path::Prefix; #[inline] pub fn is_sep_byte(b: u8) -> bool { diff --git a/src/libstd/sys/hermit/pipe.rs b/src/libstd/sys/hermit/pipe.rs index 9f07f054362..fb14dc59101 100644 --- a/src/libstd/sys/hermit/pipe.rs +++ b/src/libstd/sys/hermit/pipe.rs @@ -25,9 +25,6 @@ impl AnonPipe { } } -pub fn read2(p1: AnonPipe, - _v1: &mut Vec<u8>, - _p2: AnonPipe, - _v2: &mut Vec<u8>) -> io::Result<()> { +pub fn read2(p1: AnonPipe, _v1: &mut Vec<u8>, _p2: AnonPipe, _v2: &mut Vec<u8>) -> io::Result<()> { match p1.0 {} } diff --git a/src/libstd/sys/hermit/process.rs b/src/libstd/sys/hermit/process.rs index edf933d10e0..4702e5c5492 100644 --- a/src/libstd/sys/hermit/process.rs +++ b/src/libstd/sys/hermit/process.rs @@ -32,32 +32,28 @@ pub enum Stdio { impl Command { pub fn new(_program: &OsStr) -> Command { - Command { - env: Default::default() - } + Command { env: Default::default() } } - pub fn arg(&mut self, _arg: &OsStr) { - } + pub fn arg(&mut self, _arg: &OsStr) {} pub fn env_mut(&mut self) -> &mut CommandEnv { &mut self.env } - pub fn cwd(&mut self, _dir: &OsStr) { - } + pub fn cwd(&mut self, _dir: &OsStr) {} - pub fn stdin(&mut self, _stdin: Stdio) { - } + pub fn stdin(&mut self, _stdin: Stdio) {} - pub fn stdout(&mut self, _stdout: Stdio) { - } + pub fn stdout(&mut self, _stdout: Stdio) {} - pub fn stderr(&mut self, _stderr: Stdio) { - } + pub fn stderr(&mut self, _stderr: Stdio) {} - pub fn spawn(&mut self, _default: Stdio, _needs_stdin: bool) - -> io::Result<(Process, StdioPipes)> { + pub fn spawn( + &mut self, + _default: Stdio, + _needs_stdin: bool, + ) -> io::Result<(Process, StdioPipes)> { unsupported() } } @@ -106,8 +102,7 @@ impl PartialEq for ExitStatus { } } -impl Eq for ExitStatus { -} +impl Eq for ExitStatus {} impl fmt::Debug for ExitStatus { fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/libstd/sys/hermit/rwlock.rs b/src/libstd/sys/hermit/rwlock.rs index 990e7551114..c19799af3c7 100644 --- a/src/libstd/sys/hermit/rwlock.rs +++ b/src/libstd/sys/hermit/rwlock.rs @@ -1,7 +1,7 @@ use super::mutex::Mutex; pub struct RWLock { - mutex: Mutex + mutex: Mutex, } unsafe impl Send for RWLock {} @@ -9,9 +9,7 @@ unsafe impl Sync for RWLock {} impl RWLock { pub const fn new() -> RWLock { - RWLock { - mutex: Mutex::new() - } + RWLock { mutex: Mutex::new() } } #[inline] diff --git a/src/libstd/sys/hermit/stack_overflow.rs b/src/libstd/sys/hermit/stack_overflow.rs index b339e433e77..65a1b17acce 100644 --- a/src/libstd/sys/hermit/stack_overflow.rs +++ b/src/libstd/sys/hermit/stack_overflow.rs @@ -7,9 +7,7 @@ impl Handler { } #[inline] -pub unsafe fn init() { -} +pub unsafe fn init() {} #[inline] -pub unsafe fn cleanup() { -} +pub unsafe fn cleanup() {} diff --git a/src/libstd/sys/hermit/stdio.rs b/src/libstd/sys/hermit/stdio.rs index 9505f02fda8..2eb011ccb39 100644 --- a/src/libstd/sys/hermit/stdio.rs +++ b/src/libstd/sys/hermit/stdio.rs @@ -20,7 +20,6 @@ impl Stdin { // .read(data) Ok(0) } - } impl Stdout { @@ -31,9 +30,7 @@ impl Stdout { pub fn write(&self, data: &[u8]) -> io::Result<usize> { let len; - unsafe { - len = abi::write(1, data.as_ptr() as *const u8, data.len()) - } + unsafe { len = abi::write(1, data.as_ptr() as *const u8, data.len()) } if len < 0 { Err(io::Error::new(io::ErrorKind::Other, "Stdout is not able to print")) @@ -45,9 +42,7 @@ impl Stdout { pub fn write_vectored(&self, data: &[IoSlice<'_>]) -> io::Result<usize> { let len; - unsafe { - len = abi::write(1, data.as_ptr() as *const u8, data.len()) - } + unsafe { len = abi::write(1, data.as_ptr() as *const u8, data.len()) } if len < 0 { Err(io::Error::new(io::ErrorKind::Other, "Stdout is not able to print")) @@ -69,9 +64,7 @@ impl Stderr { pub fn write(&self, data: &[u8]) -> io::Result<usize> { let len; - unsafe { - len = abi::write(2, data.as_ptr() as *const u8, data.len()) - } + unsafe { len = abi::write(2, data.as_ptr() as *const u8, data.len()) } if len < 0 { Err(io::Error::new(io::ErrorKind::Other, "Stderr is not able to print")) @@ -83,9 +76,7 @@ impl Stderr { pub fn write_vectored(&self, data: &[IoSlice<'_>]) -> io::Result<usize> { let len; - unsafe { - len = abi::write(2, data.as_ptr() as *const u8, data.len()) - } + unsafe { len = abi::write(2, data.as_ptr() as *const u8, data.len()) } if len < 0 { Err(io::Error::new(io::ErrorKind::Other, "Stderr is not able to print")) diff --git a/src/libstd/sys/hermit/thread.rs b/src/libstd/sys/hermit/thread.rs index 99a9c830c9e..c3c29c93826 100644 --- a/src/libstd/sys/hermit/thread.rs +++ b/src/libstd/sys/hermit/thread.rs @@ -1,11 +1,11 @@ #![allow(dead_code)] use crate::ffi::CStr; +use crate::fmt; use crate::io; +use crate::mem; use crate::sys::hermit::abi; use crate::time::Duration; -use crate::mem; -use crate::fmt; use core::u32; use crate::sys_common::thread::*; @@ -35,7 +35,7 @@ impl fmt::Display for Priority { pub const NORMAL_PRIO: Priority = Priority::from(2); pub struct Thread { - tid: Tid + tid: Tid, } unsafe impl Send for Thread {} @@ -44,14 +44,20 @@ unsafe impl Sync for Thread {} pub const DEFAULT_MIN_STACK_SIZE: usize = 262144; impl Thread { - pub unsafe fn new_with_coreid(_stack: usize, p: Box<dyn FnOnce()>, core_id: isize) - -> io::Result<Thread> - { + pub unsafe fn new_with_coreid( + _stack: usize, + p: Box<dyn FnOnce()>, + core_id: isize, + ) -> io::Result<Thread> { let p = box p; let mut tid: Tid = u32::MAX; - let ret = abi::spawn(&mut tid as *mut Tid, thread_start, - &*p as *const _ as *const u8 as usize, - Priority::into(NORMAL_PRIO), core_id); + let ret = abi::spawn( + &mut tid as *mut Tid, + thread_start, + &*p as *const _ as *const u8 as usize, + Priority::into(NORMAL_PRIO), + core_id, + ); return if ret == 0 { mem::forget(p); // ownership passed to pthread_create @@ -60,16 +66,14 @@ impl Thread { Err(io::Error::new(io::ErrorKind::Other, "Unable to create thread!")) }; - extern fn thread_start(main: usize) { + extern "C" fn thread_start(main: usize) { unsafe { start_thread(main as *mut u8); } } } - pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) - -> io::Result<Thread> - { + pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> { Thread::new_with_coreid(stack, p, -1 /* = no specific core */) } @@ -99,7 +103,9 @@ impl Thread { } #[inline] - pub fn id(&self) -> Tid { self.tid } + pub fn id(&self) -> Tid { + self.tid + } #[inline] pub fn into_id(self) -> Tid { @@ -111,6 +117,10 @@ impl Thread { pub mod guard { pub type Guard = !; - pub unsafe fn current() -> Option<Guard> { None } - pub unsafe fn init() -> Option<Guard> { None } + pub unsafe fn current() -> Option<Guard> { + None + } + pub unsafe fn init() -> Option<Guard> { + None + } } diff --git a/src/libstd/sys/hermit/thread_local.rs b/src/libstd/sys/hermit/thread_local.rs index 268fb770eae..ba967c7676c 100644 --- a/src/libstd/sys/hermit/thread_local.rs +++ b/src/libstd/sys/hermit/thread_local.rs @@ -7,7 +7,7 @@ use crate::sys_common::mutex::Mutex; pub type Key = usize; -type Dtor = unsafe extern fn(*mut u8); +type Dtor = unsafe extern "C" fn(*mut u8); static NEXT_KEY: AtomicUsize = AtomicUsize::new(0); @@ -41,11 +41,7 @@ pub unsafe fn create(dtor: Option<Dtor>) -> Key { #[inline] pub unsafe fn get(key: Key) -> *mut u8 { - if let Some(&entry) = locals().get(&key) { - entry - } else { - ptr::null_mut() - } + if let Some(&entry) = locals().get(&key) { entry } else { ptr::null_mut() } } #[inline] diff --git a/src/libstd/sys/hermit/time.rs b/src/libstd/sys/hermit/time.rs index 8372189546d..c02de17c1fc 100644 --- a/src/libstd/sys/hermit/time.rs +++ b/src/libstd/sys/hermit/time.rs @@ -1,34 +1,35 @@ #![allow(dead_code)] -use crate::time::Duration; use crate::cmp::Ordering; use crate::convert::TryInto; -use core::hash::{Hash, Hasher}; use crate::sys::hermit::abi; -use crate::sys::hermit::abi::{CLOCK_REALTIME, CLOCK_MONOTONIC, NSEC_PER_SEC}; use crate::sys::hermit::abi::timespec; +use crate::sys::hermit::abi::{CLOCK_MONOTONIC, CLOCK_REALTIME, NSEC_PER_SEC}; +use crate::time::Duration; +use core::hash::{Hash, Hasher}; #[derive(Copy, Clone, Debug)] struct Timespec { - t: timespec + t: timespec, } impl Timespec { const fn zero() -> Timespec { - Timespec { - t: timespec { tv_sec: 0, tv_nsec: 0 }, - } + Timespec { t: timespec { tv_sec: 0, tv_nsec: 0 } } } fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> { if self >= other { Ok(if self.t.tv_nsec >= other.t.tv_nsec { - Duration::new((self.t.tv_sec - other.t.tv_sec) as u64, - (self.t.tv_nsec - other.t.tv_nsec) as u32) + Duration::new( + (self.t.tv_sec - other.t.tv_sec) as u64, + (self.t.tv_nsec - other.t.tv_nsec) as u32, + ) } else { - Duration::new((self.t.tv_sec - 1 - other.t.tv_sec) as u64, - self.t.tv_nsec as u32 + (NSEC_PER_SEC as u32) - - other.t.tv_nsec as u32) + Duration::new( + (self.t.tv_sec - 1 - other.t.tv_sec) as u64, + self.t.tv_nsec as u32 + (NSEC_PER_SEC as u32) - other.t.tv_nsec as u32, + ) }) } else { match other.sub_timespec(self) { @@ -52,12 +53,7 @@ impl Timespec { nsec -= NSEC_PER_SEC as u32; secs = secs.checked_add(1)?; } - Some(Timespec { - t: timespec { - tv_sec: secs, - tv_nsec: nsec as _, - }, - }) + Some(Timespec { t: timespec { tv_sec: secs, tv_nsec: nsec as _ } }) } fn checked_sub_duration(&self, other: &Duration) -> Option<Timespec> { @@ -73,12 +69,7 @@ impl Timespec { nsec += NSEC_PER_SEC as i32; secs = secs.checked_sub(1)?; } - Some(Timespec { - t: timespec { - tv_sec: secs, - tv_nsec: nsec as _, - }, - }) + Some(Timespec { t: timespec { tv_sec: secs, tv_nsec: nsec as _ } }) } } @@ -105,7 +96,7 @@ impl Ord for Timespec { } impl Hash for Timespec { - fn hash<H : Hasher>(&self, state: &mut H) { + fn hash<H: Hasher>(&self, state: &mut H) { self.t.tv_sec.hash(state); self.t.tv_nsec.hash(state); } @@ -150,9 +141,7 @@ pub struct SystemTime { t: Timespec, } -pub const UNIX_EPOCH: SystemTime = SystemTime { - t: Timespec::zero(), -}; +pub const UNIX_EPOCH: SystemTime = SystemTime { t: Timespec::zero() }; impl SystemTime { pub fn now() -> SystemTime { |
