Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change wait_with_output to borrow instead of taking ownership #127862

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,7 @@ fn exec_linker(
// will read all its options out of there instead of looking at the command line.
if !cmd.very_likely_to_exceed_some_spawn_limit() {
match cmd.command().stdout(Stdio::piped()).stderr(Stdio::piped()).spawn() {
Ok(child) => {
Ok(mut child) => {
let output = child.wait_with_output();
flush_linked_file(&output, out_filename)?;
return output;
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2238,7 +2238,7 @@ impl Child {
/// ```should_panic
/// use std::process::{Command, Stdio};
///
/// let child = Command::new("/bin/cat")
/// let mut child = Command::new("/bin/cat")
/// .arg("file.txt")
/// .stdout(Stdio::piped())
/// .spawn()
Expand All @@ -2252,7 +2252,7 @@ impl Child {
/// ```
///
#[stable(feature = "process", since = "1.0.0")]
pub fn wait_with_output(mut self) -> io::Result<Output> {
pub fn wait_with_output(&mut self) -> io::Result<Output> {
drop(self.stdin.take());

let (mut stdout, mut stderr) = (Vec::new(), Vec::new());
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/process/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn test_finish_twice() {
#[test]
#[cfg_attr(any(target_os = "vxworks"), ignore)]
fn test_wait_with_output_once() {
let prog = if cfg!(target_os = "windows") {
let mut prog = if cfg!(target_os = "windows") {
Command::new("cmd").args(&["/C", "echo hello"]).stdout(Stdio::piped()).spawn().unwrap()
} else {
shell_cmd().arg("-c").arg("echo hello").stdout(Stdio::piped()).spawn().unwrap()
Expand Down
40 changes: 18 additions & 22 deletions tests/ui/backtrace/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ fn double() {
struct Double;

impl Drop for Double {
fn drop(&mut self) { panic!("twice") }
fn drop(&mut self) {
panic!("twice")
}
}

let _d = Double;
Expand All @@ -35,9 +37,7 @@ fn double() {

fn template(me: &str) -> Command {
let mut m = Command::new(me);
m.env("IS_TEST", "1")
.stdout(Stdio::piped())
.stderr(Stdio::piped());
m.env("IS_TEST", "1").stdout(Stdio::piped()).stderr(Stdio::piped());
return m;
}

Expand All @@ -63,65 +63,61 @@ fn contains_verbose_expected(s: &str, fn_name: &str) -> bool {

fn runtest(me: &str) {
// Make sure that the stack trace is printed
let p = template(me).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
let mut p = template(me).arg("fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(&out.stderr).unwrap();
assert!(s.contains("stack backtrace") && s.contains(&expected("foo")),
"bad output: {}", s);
assert!(s.contains("stack backtrace") && s.contains(&expected("foo")), "bad output: {}", s);
assert!(s.contains(" 0:"), "the frame number should start at 0");

// Make sure the stack trace is *not* printed
// (Remove RUST_BACKTRACE from our own environment, in case developer
// is running `make check` with it on.)
let p = template(me).arg("fail").env_remove("RUST_BACKTRACE").spawn().unwrap();
let mut p = template(me).arg("fail").env_remove("RUST_BACKTRACE").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(&out.stderr).unwrap();
assert!(!s.contains("stack backtrace") && !s.contains(&expected("foo")),
"bad output2: {}", s);
assert!(!s.contains("stack backtrace") && !s.contains(&expected("foo")), "bad output2: {}", s);

// Make sure the stack trace is *not* printed
// (RUST_BACKTRACE=0 acts as if it were unset from our own environment,
// in case developer is running `make check` with it set.)
let p = template(me).arg("fail").env("RUST_BACKTRACE","0").spawn().unwrap();
let mut p = template(me).arg("fail").env("RUST_BACKTRACE", "0").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(&out.stderr).unwrap();
assert!(!s.contains("stack backtrace") && !s.contains(" - foo"),
"bad output3: {}", s);
assert!(!s.contains("stack backtrace") && !s.contains(" - foo"), "bad output3: {}", s);

#[cfg(not(panic = "abort"))]
{
// Make sure a stack trace is printed
let p = template(me).arg("double-fail").env("RUST_BACKTRACE","0").spawn().unwrap();
let mut p = template(me).arg("double-fail").env("RUST_BACKTRACE", "0").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(&out.stderr).unwrap();
// loosened the following from double::h to double:: due to
// spurious failures on mac, 32bit, optimized
assert!(
s.contains("stack backtrace") &&
s.contains("panic in a destructor during cleanup") &&
contains_verbose_expected(s, "double"),
"bad output3: {}", s
s.contains("stack backtrace")
&& s.contains("panic in a destructor during cleanup")
&& contains_verbose_expected(s, "double"),
"bad output3: {}",
s
);
// Make sure it's only one stack trace.
assert_eq!(s.split("stack backtrace").count(), 2);

// Make sure a stack trace isn't printed too many times
// even with RUST_BACKTRACE=1. It should be printed twice.
let p = template(me).arg("double-fail")
.env("RUST_BACKTRACE", "1").spawn().unwrap();
let mut p = template(me).arg("double-fail").env("RUST_BACKTRACE", "1").spawn().unwrap();
let out = p.wait_with_output().unwrap();
assert!(!out.status.success());
let s = str::from_utf8(&out.stderr).unwrap();
let mut i = 0;
for _ in 0..2 {
i += s[i + 10..].find("stack backtrace").unwrap() + 10;
}
assert!(s[i + 10..].find("stack backtrace").is_none(),
"bad output4: {}", s);
assert!(s[i + 10..].find("stack backtrace").is_none(), "bad output4: {}", s);
}
}

Expand Down
Loading