Skip to content

Commit ed2ecb6

Browse files
authored
Merge pull request #2187 from brotzeit/master
don't print verbose output when formatting with stdin
2 parents 67d36c7 + 32953d0 commit ed2ecb6

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

rustfmt-core/src/lib.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ mod types;
7575
mod vertical;
7676
pub mod visitor;
7777

78+
const STDIN: &'static str = "<stdin>";
79+
7880
// A map of the files of a crate, with their new content
7981
pub type FileMap = Vec<FileRecord>;
8082

@@ -294,6 +296,15 @@ impl fmt::Display for FormatReport {
294296
}
295297
}
296298

299+
fn should_emit_verbose<F>(path: &FileName, config: &Config, f: F)
300+
where
301+
F: Fn(),
302+
{
303+
if config.verbose() && path.to_string() != STDIN {
304+
f();
305+
}
306+
}
307+
297308
// Formatting which depends on the AST.
298309
fn format_ast<F>(
299310
krate: &ast::Crate,
@@ -316,9 +327,7 @@ where
316327
if skip_children && path != *main_file {
317328
continue;
318329
}
319-
if config.verbose() {
320-
println!("Formatting {}", path);
321-
}
330+
should_emit_verbose(&path, config, || println!("Formatting {}", path));
322331
let filemap = parse_session
323332
.codemap()
324333
.lookup_char_pos(module.inner.lo())
@@ -676,7 +685,7 @@ pub fn format_input<T: Write>(
676685

677686
summary.mark_format_time();
678687

679-
if config.verbose() {
688+
should_emit_verbose(&main_file, config, || {
680689
fn duration_to_f32(d: Duration) -> f32 {
681690
d.as_secs() as f32 + d.subsec_nanos() as f32 / 1_000_000_000f32
682691
}
@@ -685,8 +694,8 @@ pub fn format_input<T: Write>(
685694
"Spent {0:.3} secs in the parsing phase, and {1:.3} secs in the formatting phase",
686695
duration_to_f32(summary.get_parse_time().unwrap()),
687696
duration_to_f32(summary.get_format_time().unwrap()),
688-
);
689-
}
697+
)
698+
});
690699

691700
match format_result {
692701
Ok((file_map, has_diff)) => {

0 commit comments

Comments
 (0)