Skip to content

Commit 0e338d7

Browse files
authored
Rollup merge of #115535 - tshepang:patch-2, r=dtolnay
format doc-comment code examples in std::process
2 parents 980fba7 + d8c1533 commit 0e338d7

File tree

1 file changed

+69
-71
lines changed

1 file changed

+69
-71
lines changed

library/std/src/process.rs

+69-71
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
//! use std::process::Command;
1313
//!
1414
//! let output = Command::new("echo")
15-
//! .arg("Hello world")
16-
//! .output()
17-
//! .expect("Failed to execute command");
15+
//! .arg("Hello world")
16+
//! .output()
17+
//! .expect("Failed to execute command");
1818
//!
1919
//! assert_eq!(b"Hello world\n", output.stdout.as_slice());
2020
//! ```
@@ -154,12 +154,11 @@ use crate::sys_common::{AsInner, AsInnerMut, FromInner, IntoInner};
154154
/// use std::process::Command;
155155
///
156156
/// let mut child = Command::new("/bin/cat")
157-
/// .arg("file.txt")
158-
/// .spawn()
159-
/// .expect("failed to execute child");
157+
/// .arg("file.txt")
158+
/// .spawn()
159+
/// .expect("failed to execute child");
160160
///
161-
/// let ecode = child.wait()
162-
/// .expect("failed to wait on child");
161+
/// let ecode = child.wait().expect("failed to wait on child");
163162
///
164163
/// assert!(ecode.success());
165164
/// ```
@@ -481,15 +480,15 @@ impl fmt::Debug for ChildStderr {
481480
///
482481
/// let output = if cfg!(target_os = "windows") {
483482
/// Command::new("cmd")
484-
/// .args(["/C", "echo hello"])
485-
/// .output()
486-
/// .expect("failed to execute process")
483+
/// .args(["/C", "echo hello"])
484+
/// .output()
485+
/// .expect("failed to execute process")
487486
/// } else {
488487
/// Command::new("sh")
489-
/// .arg("-c")
490-
/// .arg("echo hello")
491-
/// .output()
492-
/// .expect("failed to execute process")
488+
/// .arg("-c")
489+
/// .arg("echo hello")
490+
/// .output()
491+
/// .expect("failed to execute process")
493492
/// };
494493
///
495494
/// let hello = output.stdout;
@@ -502,8 +501,7 @@ impl fmt::Debug for ChildStderr {
502501
/// use std::process::Command;
503502
///
504503
/// let mut echo_hello = Command::new("sh");
505-
/// echo_hello.arg("-c")
506-
/// .arg("echo hello");
504+
/// echo_hello.arg("-c").arg("echo hello");
507505
/// let hello_1 = echo_hello.output().expect("failed to execute process");
508506
/// let hello_2 = echo_hello.output().expect("failed to execute process");
509507
/// ```
@@ -576,8 +574,8 @@ impl Command {
576574
/// use std::process::Command;
577575
///
578576
/// Command::new("sh")
579-
/// .spawn()
580-
/// .expect("sh command failed to start");
577+
/// .spawn()
578+
/// .expect("sh command failed to start");
581579
/// ```
582580
#[stable(feature = "process", since = "1.0.0")]
583581
pub fn new<S: AsRef<OsStr>>(program: S) -> Command {
@@ -620,10 +618,10 @@ impl Command {
620618
/// use std::process::Command;
621619
///
622620
/// Command::new("ls")
623-
/// .arg("-l")
624-
/// .arg("-a")
625-
/// .spawn()
626-
/// .expect("ls command failed to start");
621+
/// .arg("-l")
622+
/// .arg("-a")
623+
/// .spawn()
624+
/// .expect("ls command failed to start");
627625
/// ```
628626
#[stable(feature = "process", since = "1.0.0")]
629627
pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Command {
@@ -650,9 +648,9 @@ impl Command {
650648
/// use std::process::Command;
651649
///
652650
/// Command::new("ls")
653-
/// .args(["-l", "-a"])
654-
/// .spawn()
655-
/// .expect("ls command failed to start");
651+
/// .args(["-l", "-a"])
652+
/// .spawn()
653+
/// .expect("ls command failed to start");
656654
/// ```
657655
#[stable(feature = "process", since = "1.0.0")]
658656
pub fn args<I, S>(&mut self, args: I) -> &mut Command
@@ -688,9 +686,9 @@ impl Command {
688686
/// use std::process::Command;
689687
///
690688
/// Command::new("ls")
691-
/// .env("PATH", "/bin")
692-
/// .spawn()
693-
/// .expect("ls command failed to start");
689+
/// .env("PATH", "/bin")
690+
/// .spawn()
691+
/// .expect("ls command failed to start");
694692
/// ```
695693
#[stable(feature = "process", since = "1.0.0")]
696694
pub fn env<K, V>(&mut self, key: K, val: V) -> &mut Command
@@ -731,12 +729,12 @@ impl Command {
731729
/// ).collect();
732730
///
733731
/// Command::new("printenv")
734-
/// .stdin(Stdio::null())
735-
/// .stdout(Stdio::inherit())
736-
/// .env_clear()
737-
/// .envs(&filtered_env)
738-
/// .spawn()
739-
/// .expect("printenv failed to start");
732+
/// .stdin(Stdio::null())
733+
/// .stdout(Stdio::inherit())
734+
/// .env_clear()
735+
/// .envs(&filtered_env)
736+
/// .spawn()
737+
/// .expect("printenv failed to start");
740738
/// ```
741739
#[stable(feature = "command_envs", since = "1.19.0")]
742740
pub fn envs<I, K, V>(&mut self, vars: I) -> &mut Command
@@ -772,9 +770,9 @@ impl Command {
772770
/// use std::process::Command;
773771
///
774772
/// Command::new("ls")
775-
/// .env_remove("PATH")
776-
/// .spawn()
777-
/// .expect("ls command failed to start");
773+
/// .env_remove("PATH")
774+
/// .spawn()
775+
/// .expect("ls command failed to start");
778776
/// ```
779777
#[stable(feature = "process", since = "1.0.0")]
780778
pub fn env_remove<K: AsRef<OsStr>>(&mut self, key: K) -> &mut Command {
@@ -802,9 +800,9 @@ impl Command {
802800
/// use std::process::Command;
803801
///
804802
/// Command::new("ls")
805-
/// .env_clear()
806-
/// .spawn()
807-
/// .expect("ls command failed to start");
803+
/// .env_clear()
804+
/// .spawn()
805+
/// .expect("ls command failed to start");
808806
/// ```
809807
#[stable(feature = "process", since = "1.0.0")]
810808
pub fn env_clear(&mut self) -> &mut Command {
@@ -830,9 +828,9 @@ impl Command {
830828
/// use std::process::Command;
831829
///
832830
/// Command::new("ls")
833-
/// .current_dir("/bin")
834-
/// .spawn()
835-
/// .expect("ls command failed to start");
831+
/// .current_dir("/bin")
832+
/// .spawn()
833+
/// .expect("ls command failed to start");
836834
/// ```
837835
///
838836
/// [`canonicalize`]: crate::fs::canonicalize
@@ -861,9 +859,9 @@ impl Command {
861859
/// use std::process::{Command, Stdio};
862860
///
863861
/// Command::new("ls")
864-
/// .stdin(Stdio::null())
865-
/// .spawn()
866-
/// .expect("ls command failed to start");
862+
/// .stdin(Stdio::null())
863+
/// .spawn()
864+
/// .expect("ls command failed to start");
867865
/// ```
868866
#[stable(feature = "process", since = "1.0.0")]
869867
pub fn stdin<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
@@ -890,9 +888,9 @@ impl Command {
890888
/// use std::process::{Command, Stdio};
891889
///
892890
/// Command::new("ls")
893-
/// .stdout(Stdio::null())
894-
/// .spawn()
895-
/// .expect("ls command failed to start");
891+
/// .stdout(Stdio::null())
892+
/// .spawn()
893+
/// .expect("ls command failed to start");
896894
/// ```
897895
#[stable(feature = "process", since = "1.0.0")]
898896
pub fn stdout<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
@@ -919,9 +917,9 @@ impl Command {
919917
/// use std::process::{Command, Stdio};
920918
///
921919
/// Command::new("ls")
922-
/// .stderr(Stdio::null())
923-
/// .spawn()
924-
/// .expect("ls command failed to start");
920+
/// .stderr(Stdio::null())
921+
/// .spawn()
922+
/// .expect("ls command failed to start");
925923
/// ```
926924
#[stable(feature = "process", since = "1.0.0")]
927925
pub fn stderr<T: Into<Stdio>>(&mut self, cfg: T) -> &mut Command {
@@ -941,8 +939,8 @@ impl Command {
941939
/// use std::process::Command;
942940
///
943941
/// Command::new("ls")
944-
/// .spawn()
945-
/// .expect("ls command failed to start");
942+
/// .spawn()
943+
/// .expect("ls command failed to start");
946944
/// ```
947945
#[stable(feature = "process", since = "1.0.0")]
948946
pub fn spawn(&mut self) -> io::Result<Child> {
@@ -963,9 +961,9 @@ impl Command {
963961
/// use std::process::Command;
964962
/// use std::io::{self, Write};
965963
/// let output = Command::new("/bin/cat")
966-
/// .arg("file.txt")
967-
/// .output()
968-
/// .expect("failed to execute process");
964+
/// .arg("file.txt")
965+
/// .output()
966+
/// .expect("failed to execute process");
969967
///
970968
/// println!("status: {}", output.status);
971969
/// io::stdout().write_all(&output.stdout).unwrap();
@@ -990,9 +988,9 @@ impl Command {
990988
/// use std::process::Command;
991989
///
992990
/// let status = Command::new("/bin/cat")
993-
/// .arg("file.txt")
994-
/// .status()
995-
/// .expect("failed to execute process");
991+
/// .arg("file.txt")
992+
/// .status()
993+
/// .expect("failed to execute process");
996994
///
997995
/// println!("process finished with: {status}");
998996
///
@@ -1618,9 +1616,9 @@ impl ExitStatus {
16181616
/// use std::process::Command;
16191617
///
16201618
/// let status = Command::new("ls")
1621-
/// .arg("/dev/nonexistent")
1622-
/// .status()
1623-
/// .expect("ls could not be executed");
1619+
/// .arg("/dev/nonexistent")
1620+
/// .status()
1621+
/// .expect("ls could not be executed");
16241622
///
16251623
/// println!("ls: {status}");
16261624
/// status.exit_ok().expect_err("/dev/nonexistent could be listed!");
@@ -1640,9 +1638,9 @@ impl ExitStatus {
16401638
/// use std::process::Command;
16411639
///
16421640
/// let status = Command::new("mkdir")
1643-
/// .arg("projects")
1644-
/// .status()
1645-
/// .expect("failed to execute mkdir");
1641+
/// .arg("projects")
1642+
/// .status()
1643+
/// .expect("failed to execute mkdir");
16461644
///
16471645
/// if status.success() {
16481646
/// println!("'projects/' directory created");
@@ -1673,13 +1671,13 @@ impl ExitStatus {
16731671
/// use std::process::Command;
16741672
///
16751673
/// let status = Command::new("mkdir")
1676-
/// .arg("projects")
1677-
/// .status()
1678-
/// .expect("failed to execute mkdir");
1674+
/// .arg("projects")
1675+
/// .status()
1676+
/// .expect("failed to execute mkdir");
16791677
///
16801678
/// match status.code() {
16811679
/// Some(code) => println!("Exited with status code: {code}"),
1682-
/// None => println!("Process terminated by signal")
1680+
/// None => println!("Process terminated by signal")
16831681
/// }
16841682
/// ```
16851683
#[must_use]

0 commit comments

Comments
 (0)