Skip to content

Commit

Permalink
Format libstd/sys with rustfmt
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dtolnay committed Nov 30, 2019
1 parent 9081929 commit c34fbfa
Show file tree
Hide file tree
Showing 144 changed files with 2,527 additions and 2,285 deletions.
4 changes: 1 addition & 3 deletions src/libstd/sys/cloudabi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ pub fn errno() -> i32 {
pub fn error_string(errno: i32) -> String {
// cloudlibc's strerror() is guaranteed to be thread-safe. There is
// thus no need to use strerror_r().
str::from_utf8(unsafe { CStr::from_ptr(libc::strerror(errno)) }.to_bytes())
.unwrap()
.to_owned()
str::from_utf8(unsafe { CStr::from_ptr(libc::strerror(errno)) }.to_bytes()).unwrap().to_owned()
}

pub fn exit(code: i32) -> ! {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/cloudabi/shims/fs.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ffi::OsString;
use crate::fmt;
use crate::hash::{Hash, Hasher};
use crate::io::{self, SeekFrom, IoSlice, IoSliceMut};
use crate::io::{self, IoSlice, IoSliceMut, SeekFrom};
use crate::path::{Path, PathBuf};
use crate::sys::time::SystemTime;
use crate::sys::{unsupported, Void};
Expand Down
7 changes: 2 additions & 5 deletions src/libstd/sys/cloudabi/shims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ pub mod args;
pub mod env;
pub mod fs;
pub mod net;
pub mod os;
#[path = "../../unix/path.rs"]
pub mod path;
pub mod pipe;
pub mod process;
pub mod os;

// This enum is used as the storage for a bunch of types which can't actually exist.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub enum Void {}

pub fn unsupported<T>() -> io::Result<T> {
Err(io::Error::new(
io::ErrorKind::Other,
"This function is not available on CloudABI.",
))
Err(io::Error::new(io::ErrorKind::Other, "This function is not available on CloudABI."))
}
4 changes: 2 additions & 2 deletions src/libstd/sys/cloudabi/shims/net.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::convert::TryFrom;
use crate::fmt;
use crate::io::{self, IoSlice, IoSliceMut};
use crate::net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr};
use crate::time::Duration;
use crate::sys::{unsupported, Void};
use crate::convert::TryFrom;
use crate::time::Duration;

#[allow(unused_extern_crates)]
pub extern crate libc as netc;
Expand Down
4 changes: 1 addition & 3 deletions src/libstd/sys/cloudabi/shims/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ 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) {}
Expand Down
10 changes: 3 additions & 7 deletions src/libstd/sys/cloudabi/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl Thread {
}

pub fn sleep(dur: Duration) {
let timeout = checked_dur2intervals(&dur)
.expect("overflow converting duration to nanoseconds");
let timeout =
checked_dur2intervals(&dur).expect("overflow converting duration to nanoseconds");
unsafe {
let subscription = abi::subscription {
type_: abi::eventtype::CLOCK,
Expand All @@ -85,11 +85,7 @@ impl Thread {
unsafe {
let ret = libc::pthread_join(self.id, ptr::null_mut());
mem::forget(self);
assert!(
ret == 0,
"failed to join thread: {}",
io::Error::from_raw_os_error(ret)
);
assert!(ret == 0, "failed to join thread: {}", io::Error::from_raw_os_error(ret));
}
}
}
Expand Down
30 changes: 7 additions & 23 deletions src/libstd/sys/cloudabi/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ pub struct Instant {
}

pub fn checked_dur2intervals(dur: &Duration) -> Option<abi::timestamp> {
dur.as_secs()
.checked_mul(NSEC_PER_SEC)?
.checked_add(dur.subsec_nanos() as abi::timestamp)
dur.as_secs().checked_mul(NSEC_PER_SEC)?.checked_add(dur.subsec_nanos() as abi::timestamp)
}

impl Instant {
Expand All @@ -39,15 +37,11 @@ impl Instant {
}

pub fn checked_add_duration(&self, other: &Duration) -> Option<Instant> {
Some(Instant {
t: self.t.checked_add(checked_dur2intervals(other)?)?,
})
Some(Instant { t: self.t.checked_add(checked_dur2intervals(other)?)? })
}

pub fn checked_sub_duration(&self, other: &Duration) -> Option<Instant> {
Some(Instant {
t: self.t.checked_sub(checked_dur2intervals(other)?)?,
})
Some(Instant { t: self.t.checked_sub(checked_dur2intervals(other)?)? })
}
}

Expand All @@ -69,29 +63,19 @@ impl SystemTime {
pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {
if self.t >= other.t {
let diff = self.t - other.t;
Ok(Duration::new(
diff / NSEC_PER_SEC,
(diff % NSEC_PER_SEC) as u32,
))
Ok(Duration::new(diff / NSEC_PER_SEC, (diff % NSEC_PER_SEC) as u32))
} else {
let diff = other.t - self.t;
Err(Duration::new(
diff / NSEC_PER_SEC,
(diff % NSEC_PER_SEC) as u32,
))
Err(Duration::new(diff / NSEC_PER_SEC, (diff % NSEC_PER_SEC) as u32))
}
}

pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> {
Some(SystemTime {
t: self.t.checked_add(checked_dur2intervals(other)?)?,
})
Some(SystemTime { t: self.t.checked_add(checked_dur2intervals(other)?)? })
}

pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> {
Some(SystemTime {
t: self.t.checked_sub(checked_dur2intervals(other)?)?,
})
Some(SystemTime { t: self.t.checked_sub(checked_dur2intervals(other)?)? })
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/libstd/sys/hermit/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 28 additions & 17 deletions src/libstd/sys/hermit/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand All @@ -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()
}
}
}
2 changes: 1 addition & 1 deletion src/libstd/sys/hermit/cmath.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/hermit/condvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 7 additions & 3 deletions src/libstd/sys/hermit/fd.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit c34fbfa

Please sign in to comment.