From 4436c9d35498e7ae3da261f6141d6d73b915e1e8 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 27 Nov 2019 10:29:00 -0800 Subject: Format libstd with rustfmt This commit applies rustfmt with rust-lang/rust's default settings to files in src/libstd *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 -name '*.rs' \ | xargs rustfmt --edition=2018 --unstable-features --skip-children $ rg libstd outstanding_files | xargs git checkout -- Repeating this process several months apart should get us coverage of most of the rest of libstd. 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 --- src/libstd/process.rs | 219 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 133 insertions(+), 86 deletions(-) (limited to 'src/libstd/process.rs') diff --git a/src/libstd/process.rs b/src/libstd/process.rs index b1274a08cbe..3eee45d000c 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -186,7 +186,9 @@ pub struct Child { } impl AsInner for Child { - fn as_inner(&self) -> &imp::Process { &self.handle } + fn as_inner(&self) -> &imp::Process { + &self.handle + } } impl FromInner<(imp::Process, imp::StdioPipes)> for Child { @@ -201,7 +203,9 @@ impl FromInner<(imp::Process, imp::StdioPipes)> for Child { } impl IntoInner for Child { - fn into_inner(self) -> imp::Process { self.handle } + fn into_inner(self) -> imp::Process { + self.handle + } } #[stable(feature = "std_debug", since = "1.16.0")] @@ -228,7 +232,7 @@ impl fmt::Debug for Child { /// [dropped]: ../ops/trait.Drop.html #[stable(feature = "process", since = "1.0.0")] pub struct ChildStdin { - inner: AnonPipe + inner: AnonPipe, } #[stable(feature = "process", since = "1.0.0")] @@ -247,11 +251,15 @@ impl Write for ChildStdin { } impl AsInner for ChildStdin { - fn as_inner(&self) -> &AnonPipe { &self.inner } + fn as_inner(&self) -> &AnonPipe { + &self.inner + } } impl IntoInner for ChildStdin { - fn into_inner(self) -> AnonPipe { self.inner } + fn into_inner(self) -> AnonPipe { + self.inner + } } impl FromInner for ChildStdin { @@ -279,7 +287,7 @@ impl fmt::Debug for ChildStdin { /// [dropped]: ../ops/trait.Drop.html #[stable(feature = "process", since = "1.0.0")] pub struct ChildStdout { - inner: AnonPipe + inner: AnonPipe, } #[stable(feature = "process", since = "1.0.0")] @@ -299,11 +307,15 @@ impl Read for ChildStdout { } impl AsInner for ChildStdout { - fn as_inner(&self) -> &AnonPipe { &self.inner } + fn as_inner(&self) -> &AnonPipe { + &self.inner + } } impl IntoInner for ChildStdout { - fn into_inner(self) -> AnonPipe { self.inner } + fn into_inner(self) -> AnonPipe { + self.inner + } } impl FromInner for ChildStdout { @@ -331,7 +343,7 @@ impl fmt::Debug for ChildStdout { /// [dropped]: ../ops/trait.Drop.html #[stable(feature = "process", since = "1.0.0")] pub struct ChildStderr { - inner: AnonPipe + inner: AnonPipe, } #[stable(feature = "process", since = "1.0.0")] @@ -351,11 +363,15 @@ impl Read for ChildStderr { } impl AsInner for ChildStderr { - fn as_inner(&self) -> &AnonPipe { &self.inner } + fn as_inner(&self) -> &AnonPipe { + &self.inner + } } impl IntoInner for ChildStderr { - fn into_inner(self) -> AnonPipe { self.inner } + fn into_inner(self) -> AnonPipe { + self.inner + } } impl FromInner for ChildStderr { @@ -533,7 +549,9 @@ impl Command { /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn args(&mut self, args: I) -> &mut Command - where I: IntoIterator, S: AsRef + where + I: IntoIterator, + S: AsRef, { for arg in args { self.arg(arg.as_ref()); @@ -560,7 +578,9 @@ impl Command { /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn env(&mut self, key: K, val: V) -> &mut Command - where K: AsRef, V: AsRef + where + K: AsRef, + V: AsRef, { self.inner.env_mut().set(key.as_ref(), val.as_ref()); self @@ -592,7 +612,10 @@ impl Command { /// ``` #[stable(feature = "command_envs", since = "1.19.0")] pub fn envs(&mut self, vars: I) -> &mut Command - where I: IntoIterator, K: AsRef, V: AsRef + where + I: IntoIterator, + K: AsRef, + V: AsRef, { for (ref key, ref val) in vars { self.inner.env_mut().set(key.as_ref(), val.as_ref()); @@ -794,7 +817,9 @@ impl Command { /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn output(&mut self) -> io::Result { - self.inner.spawn(imp::Stdio::MakePipe, false).map(Child::from_inner) + self.inner + .spawn(imp::Stdio::MakePipe, false) + .map(Child::from_inner) .and_then(|p| p.wait_with_output()) } @@ -819,8 +844,10 @@ impl Command { /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn status(&mut self) -> io::Result { - self.inner.spawn(imp::Stdio::Inherit, true).map(Child::from_inner) - .and_then(|mut p| p.wait()) + self.inner + .spawn(imp::Stdio::Inherit, true) + .map(Child::from_inner) + .and_then(|mut p| p.wait()) } } @@ -835,11 +862,15 @@ impl fmt::Debug for Command { } impl AsInner for Command { - fn as_inner(&self) -> &imp::Command { &self.inner } + fn as_inner(&self) -> &imp::Command { + &self.inner + } } impl AsInnerMut for Command { - fn as_inner_mut(&mut self) -> &mut imp::Command { &mut self.inner } + fn as_inner_mut(&mut self) -> &mut imp::Command { + &mut self.inner + } } /// The output of a finished process. @@ -871,17 +902,16 @@ pub struct Output { #[stable(feature = "process_output_debug", since = "1.7.0")] impl fmt::Debug for Output { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - let stdout_utf8 = str::from_utf8(&self.stdout); let stdout_debug: &dyn fmt::Debug = match stdout_utf8 { Ok(ref str) => str, - Err(_) => &self.stdout + Err(_) => &self.stdout, }; let stderr_utf8 = str::from_utf8(&self.stderr); let stderr_debug: &dyn fmt::Debug = match stderr_utf8 { Ok(ref str) => str, - Err(_) => &self.stderr + Err(_) => &self.stderr, }; fmt.debug_struct("Output") @@ -943,7 +973,9 @@ impl Stdio { /// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH"); /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } + pub fn piped() -> Stdio { + Stdio(imp::Stdio::MakePipe) + } /// The child inherits from the corresponding parent descriptor. /// @@ -980,7 +1012,9 @@ impl Stdio { /// io::stdout().write_all(&output.stdout).unwrap(); /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } + pub fn inherit() -> Stdio { + Stdio(imp::Stdio::Inherit) + } /// This stream will be ignored. This is the equivalent of attaching the /// stream to `/dev/null` @@ -1017,7 +1051,9 @@ impl Stdio { /// // Ignores any piped-in input /// ``` #[stable(feature = "process", since = "1.0.0")] - pub fn null() -> Stdio { Stdio(imp::Stdio::Null) } + pub fn null() -> Stdio { + Stdio(imp::Stdio::Null) + } } impl FromInner for Stdio { @@ -1217,7 +1253,9 @@ impl ExitStatus { } impl AsInner for ExitStatus { - fn as_inner(&self) -> &imp::ExitStatus { &self.0 } + fn as_inner(&self) -> &imp::ExitStatus { + &self.0 + } } impl FromInner for ExitStatus { @@ -1449,11 +1487,7 @@ impl Child { } let status = self.wait()?; - Ok(Output { - status, - stdout, - stderr, - }) + Ok(Output { status, stdout, stderr }) } } @@ -1604,8 +1638,9 @@ pub fn id() -> u32 { #[cfg_attr(not(test), lang = "termination")] #[unstable(feature = "termination_trait_lib", issue = "43301")] #[rustc_on_unimplemented( - message="`main` has invalid return type `{Self}`", - label="`main` can only return types that implement `{Termination}`")] + message = "`main` has invalid return type `{Self}`", + label = "`main` can only return types that implement `{Termination}`" +)] pub trait Termination { /// Is called to get the representation of the value as status code. /// This status code is returned to the operating system. @@ -1615,7 +1650,9 @@ pub trait Termination { #[unstable(feature = "termination_trait_lib", issue = "43301")] impl Termination for () { #[inline] - fn report(self) -> i32 { ExitCode::SUCCESS.report() } + fn report(self) -> i32 { + ExitCode::SUCCESS.report() + } } #[unstable(feature = "termination_trait_lib", issue = "43301")] @@ -1630,7 +1667,9 @@ impl Termination for Result<(), E> { #[unstable(feature = "termination_trait_lib", issue = "43301")] impl Termination for ! { - fn report(self) -> i32 { self } + fn report(self) -> i32 { + self + } } #[unstable(feature = "termination_trait_lib", issue = "43301")] @@ -1654,9 +1693,9 @@ impl Termination for ExitCode { mod tests { use crate::io::prelude::*; + use super::{Command, Output, Stdio}; use crate::io::ErrorKind; use crate::str; - use super::{Command, Output, Stdio}; // FIXME(#10380) these tests should not all be ignored on android. @@ -1702,15 +1741,12 @@ mod tests { fn signal_reported_right() { use crate::os::unix::process::ExitStatusExt; - let mut p = Command::new("/bin/sh") - .arg("-c").arg("read a") - .stdin(Stdio::piped()) - .spawn().unwrap(); + let mut p = + Command::new("/bin/sh").arg("-c").arg("read a").stdin(Stdio::piped()).spawn().unwrap(); p.kill().unwrap(); match p.wait().unwrap().signal() { - Some(9) => {}, - result => panic!("not terminated by signal 9 (instead, {:?})", - result), + Some(9) => {} + result => panic!("not terminated by signal 9 (instead, {:?})", result), } } @@ -1743,9 +1779,7 @@ mod tests { #[cfg_attr(any(windows, target_os = "android", target_os = "vxworks"), ignore)] fn set_current_dir_works() { let mut cmd = Command::new("/bin/sh"); - cmd.arg("-c").arg("pwd") - .current_dir("/") - .stdout(Stdio::piped()); + cmd.arg("-c").arg("pwd").current_dir("/").stdout(Stdio::piped()); assert_eq!(run_output(cmd), "/\n"); } @@ -1753,10 +1787,12 @@ mod tests { #[cfg_attr(any(windows, target_os = "android", target_os = "vxworks"), ignore)] fn stdin_works() { let mut p = Command::new("/bin/sh") - .arg("-c").arg("read line; echo $line") - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .spawn().unwrap(); + .arg("-c") + .arg("read line; echo $line") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() + .unwrap(); p.stdin.as_mut().unwrap().write("foobar".as_bytes()).unwrap(); drop(p.stdin.take()); let mut out = String::new(); @@ -1787,19 +1823,18 @@ mod tests { fn test_process_output_fail_to_start() { match Command::new("/no-binary-by-this-name-should-exist").output() { Err(e) => assert_eq!(e.kind(), ErrorKind::NotFound), - Ok(..) => panic!() + Ok(..) => panic!(), } } #[test] #[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)] fn test_process_output_output() { - let Output {status, stdout, stderr} - = if cfg!(target_os = "windows") { - Command::new("cmd").args(&["/C", "echo hello"]).output().unwrap() - } else { - Command::new("echo").arg("hello").output().unwrap() - }; + let Output { status, stdout, stderr } = if cfg!(target_os = "windows") { + Command::new("cmd").args(&["/C", "echo hello"]).output().unwrap() + } else { + Command::new("echo").arg("hello").output().unwrap() + }; let output_str = str::from_utf8(&stdout).unwrap(); assert!(status.success()); @@ -1810,12 +1845,11 @@ mod tests { #[test] #[cfg_attr(any(target_os = "vxworks", target_os = "android"), ignore)] fn test_process_output_error() { - let Output {status, stdout, stderr} - = if cfg!(target_os = "windows") { - Command::new("cmd").args(&["/C", "mkdir ."]).output().unwrap() - } else { - Command::new("mkdir").arg("./").output().unwrap() - }; + let Output { status, stdout, stderr } = if cfg!(target_os = "windows") { + Command::new("cmd").args(&["/C", "mkdir ."]).output().unwrap() + } else { + Command::new("mkdir").arg("./").output().unwrap() + }; assert!(status.code() == Some(1)); assert_eq!(stdout, Vec::new()); @@ -1854,7 +1888,7 @@ mod tests { Command::new("echo").arg("hello").stdout(Stdio::piped()).spawn().unwrap() }; - let Output {status, stdout, stderr} = prog.wait_with_output().unwrap(); + let Output { status, stdout, stderr } = prog.wait_with_output().unwrap(); let output_str = str::from_utf8(&stdout).unwrap(); assert!(status.success()); @@ -1862,11 +1896,11 @@ mod tests { assert_eq!(stderr, Vec::new()); } - #[cfg(all(unix, not(target_os="android")))] + #[cfg(all(unix, not(target_os = "android")))] pub fn env_cmd() -> Command { Command::new("env") } - #[cfg(target_os="android")] + #[cfg(target_os = "android")] pub fn env_cmd() -> Command { let mut cmd = Command::new("/system/bin/sh"); cmd.arg("-c").arg("set"); @@ -1897,8 +1931,11 @@ mod tests { let result = cmd.output().unwrap(); let output = String::from_utf8_lossy(&result.stdout).to_string(); - assert!(output.contains("RUN_TEST_NEW_ENV=123"), - "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); + assert!( + output.contains("RUN_TEST_NEW_ENV=123"), + "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", + output + ); } #[test] @@ -1907,8 +1944,11 @@ mod tests { let result = env_cmd().env("RUN_TEST_NEW_ENV", "123").output().unwrap(); let output = String::from_utf8_lossy(&result.stdout).to_string(); - assert!(output.contains("RUN_TEST_NEW_ENV=123"), - "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", output); + assert!( + output.contains("RUN_TEST_NEW_ENV=123"), + "didn't find RUN_TEST_NEW_ENV inside of:\n\n{}", + output + ); } #[test] @@ -1927,10 +1967,16 @@ mod tests { let output = String::from_utf8_lossy(&result.stdout).to_string(); - assert!(output.contains("RUN_TEST_NEW_ENV1=123"), - "didn't find RUN_TEST_NEW_ENV1 inside of:\n\n{}", output); - assert!(output.contains("RUN_TEST_NEW_ENV2=456"), - "didn't find RUN_TEST_NEW_ENV2 inside of:\n\n{}", output); + assert!( + output.contains("RUN_TEST_NEW_ENV1=123"), + "didn't find RUN_TEST_NEW_ENV1 inside of:\n\n{}", + output + ); + assert!( + output.contains("RUN_TEST_NEW_ENV2=456"), + "didn't find RUN_TEST_NEW_ENV2 inside of:\n\n{}", + output + ); } // Regression tests for #30858. @@ -2005,8 +2051,11 @@ mod tests { extern "system" { fn WaitForDebugEvent(lpDebugEvent: *mut DEBUG_EVENT, dwMilliseconds: DWORD) -> BOOL; - fn ContinueDebugEvent(dwProcessId: DWORD, dwThreadId: DWORD, - dwContinueStatus: DWORD) -> BOOL; + fn ContinueDebugEvent( + dwProcessId: DWORD, + dwThreadId: DWORD, + dwContinueStatus: DWORD, + ) -> BOOL; } const DEBUG_PROCESS: DWORD = 1; @@ -2015,15 +2064,12 @@ mod tests { let mut child = Command::new("cmd") .creation_flags(DEBUG_PROCESS) - .stdin(Stdio::piped()).spawn().unwrap(); + .stdin(Stdio::piped()) + .spawn() + .unwrap(); child.stdin.take().unwrap().write_all(b"exit\r\n").unwrap(); let mut events = 0; - let mut event = DEBUG_EVENT { - event_code: 0, - process_id: 0, - thread_id: 0, - _junk: [0; 164], - }; + let mut event = DEBUG_EVENT { event_code: 0, process_id: 0, thread_id: 0, _junk: [0; 164] }; loop { if unsafe { WaitForDebugEvent(&mut event as *mut DEBUG_EVENT, INFINITE) } == 0 { panic!("WaitForDebugEvent failed!"); @@ -2034,9 +2080,10 @@ mod tests { break; } - if unsafe { ContinueDebugEvent(event.process_id, - event.thread_id, - DBG_EXCEPTION_NOT_HANDLED) } == 0 { + if unsafe { + ContinueDebugEvent(event.process_id, event.thread_id, DBG_EXCEPTION_NOT_HANDLED) + } == 0 + { panic!("ContinueDebugEvent failed!"); } } -- cgit 1.4.1-3-g733a5