Skip to content

Commit 518bcff

Browse files
committed
refactor so that it's no longer possible to call print_source incorrectly
1 parent ca901a1 commit 518bcff

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/tools/compiletest/src/runtest.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ struct DebuggerCommands {
242242

243243
enum ReadFrom {
244244
Path,
245-
Stdin,
245+
Stdin(String),
246246
}
247247

248248
impl<'test> TestCx<'test> {
@@ -426,11 +426,14 @@ impl<'test> TestCx<'test> {
426426
round, self.revision
427427
),
428428
);
429-
let read_from = if round == 0 { ReadFrom::Path } else { ReadFrom::Stdin };
430-
let proc_res = self.print_source(srcs[round].to_owned(),
431-
&self.props.pretty_mode,
432-
read_from);
429+
let read_from = if round == 0 {
430+
ReadFrom::Path
431+
} else {
432+
ReadFrom::Stdin(srcs[round].to_owned())
433+
};
433434

435+
let proc_res = self.print_source(read_from,
436+
&self.props.pretty_mode);
434437
if !proc_res.status.success() {
435438
self.fatal_proc_rec(
436439
&format!(
@@ -485,7 +488,7 @@ impl<'test> TestCx<'test> {
485488
}
486489

487490
// additionally, run `--pretty expanded` and try to build it.
488-
let proc_res = self.print_source(srcs[round].clone(), "expanded", ReadFrom::Path);
491+
let proc_res = self.print_source(ReadFrom::Path, "expanded");
489492
if !proc_res.status.success() {
490493
self.fatal_proc_rec("pretty-printing (expanded) failed", &proc_res);
491494
}
@@ -503,10 +506,10 @@ impl<'test> TestCx<'test> {
503506
}
504507
}
505508

506-
fn print_source(&self, src: String, pretty_type: &str, read_from: ReadFrom) -> ProcRes {
509+
fn print_source(&self, read_from: ReadFrom, pretty_type: &str) -> ProcRes {
507510
let aux_dir = self.aux_output_dir_name();
508511
let input: &str = match read_from {
509-
ReadFrom::Stdin => "-",
512+
ReadFrom::Stdin(_) => "-",
510513
ReadFrom::Path => self.testpaths.file.to_str().unwrap(),
511514
};
512515

@@ -521,16 +524,16 @@ impl<'test> TestCx<'test> {
521524
.args(&self.props.compile_flags)
522525
.envs(self.props.exec_env.clone());
523526

524-
let src_to_read = match read_from {
525-
ReadFrom::Stdin => Some(src),
527+
let src = match read_from {
528+
ReadFrom::Stdin(src) => Some(src),
526529
ReadFrom::Path => None
527530
};
528531

529532
self.compose_and_run(
530533
rustc,
531534
self.config.compile_lib_path.to_str().unwrap(),
532535
Some(aux_dir.to_str().unwrap()),
533-
src_to_read,
536+
src,
534537
)
535538
}
536539

0 commit comments

Comments
 (0)