diff --git a/src/librustc_data_structures/obligation_forest/graphviz.rs b/src/librustc_data_structures/obligation_forest/graphviz.rs index ddf89d99621ca..0fd83dad56b1a 100644 --- a/src/librustc_data_structures/obligation_forest/graphviz.rs +++ b/src/librustc_data_structures/obligation_forest/graphviz.rs @@ -2,6 +2,7 @@ use crate::obligation_forest::{ForestObligation, ObligationForest}; use graphviz as dot; use std::env::var_os; use std::fs::File; +use std::io::BufWriter; use std::path::Path; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; @@ -31,7 +32,7 @@ impl ObligationForest { let file_path = dir.as_ref().join(format!("{:010}_{}.gv", counter, description)); - let mut gv_file = File::create(file_path).unwrap(); + let mut gv_file = BufWriter::new(File::create(file_path).unwrap()); dot::render(&self, &mut gv_file).unwrap(); } diff --git a/src/librustc_incremental/assert_dep_graph.rs b/src/librustc_incremental/assert_dep_graph.rs index 9490128e32d6a..51cc091b6c0af 100644 --- a/src/librustc_incremental/assert_dep_graph.rs +++ b/src/librustc_incremental/assert_dep_graph.rs @@ -49,7 +49,7 @@ use syntax::ast; use std::env; use std::fs::{self, File}; -use std::io::Write; +use std::io::{BufWriter, Write}; pub fn assert_dep_graph(tcx: TyCtxt<'_>) { tcx.dep_graph.with_ignore(|| { @@ -235,7 +235,7 @@ fn dump_graph(tcx: TyCtxt<'_>) { { // dump a .txt file with just the edges: let txt_path = format!("{}.txt", path); - let mut file = File::create(&txt_path).unwrap(); + let mut file = BufWriter::new(File::create(&txt_path).unwrap()); for &(ref source, ref target) in &edges { write!(file, "{:?} -> {:?}\n", source, target).unwrap(); } diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index d62c7539d5f21..6af83a4c5abc1 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -49,7 +49,7 @@ use tempfile::Builder as TempFileBuilder; use std::any::Any; use std::cell::RefCell; use std::ffi::OsString; -use std::io::{self, Write}; +use std::io::{self, BufWriter, Write}; use std::path::PathBuf; use std::rc::Rc; use std::{env, fs, iter, mem}; @@ -575,7 +575,7 @@ fn write_out_deps( }); } - let mut file = fs::File::create(&deps_filename)?; + let mut file = BufWriter::new(fs::File::create(&deps_filename)?); for path in out_filenames { writeln!(file, "{}: {}\n", path.display(), files.join(" "))?; } diff --git a/src/librustc_mir/borrow_check/facts.rs b/src/librustc_mir/borrow_check/facts.rs index a16c36d749f0d..827ccb1c85733 100644 --- a/src/librustc_mir/borrow_check/facts.rs +++ b/src/librustc_mir/borrow_check/facts.rs @@ -8,7 +8,7 @@ use rustc_index::vec::Idx; use std::error::Error; use std::fmt::Debug; use std::fs::{self, File}; -use std::io::Write; +use std::io::{BufWriter, Write}; use std::path::Path; #[derive(Copy, Clone, Debug)] @@ -117,7 +117,7 @@ impl<'w> FactWriter<'w> { T: FactRow, { let file = &self.dir.join(file_name); - let mut file = File::create(file)?; + let mut file = BufWriter::new(File::create(file)?); for row in rows { row.write(&mut file, self.location_table)?; } @@ -126,11 +126,19 @@ impl<'w> FactWriter<'w> { } trait FactRow { - fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box>; + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box>; } impl FactRow for RegionVid { - fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box> { write_row(out, location_table, &[self]) } } @@ -140,7 +148,11 @@ where A: FactCell, B: FactCell, { - fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box> { write_row(out, location_table, &[&self.0, &self.1]) } } @@ -151,7 +163,11 @@ where B: FactCell, C: FactCell, { - fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box> { write_row(out, location_table, &[&self.0, &self.1, &self.2]) } } @@ -163,7 +179,11 @@ where C: FactCell, D: FactCell, { - fn write(&self, out: &mut File, location_table: &LocationTable) -> Result<(), Box> { + fn write( + &self, + out: &mut dyn Write, + location_table: &LocationTable, + ) -> Result<(), Box> { write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3]) } } diff --git a/src/librustc_mir/transform/dump_mir.rs b/src/librustc_mir/transform/dump_mir.rs index 2cbda33ad2db1..5dec2c6df99dc 100644 --- a/src/librustc_mir/transform/dump_mir.rs +++ b/src/librustc_mir/transform/dump_mir.rs @@ -61,7 +61,7 @@ pub fn on_mir_pass<'tcx>( pub fn emit_mir(tcx: TyCtxt<'_>, outputs: &OutputFilenames) -> io::Result<()> { let path = outputs.path(OutputType::Mir); - let mut f = File::create(&path)?; + let mut f = io::BufWriter::new(File::create(&path)?); mir_util::write_mir_pretty(tcx, None, &mut f)?; Ok(()) } diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 1488bfe4d627a..b12ad1e4c15cc 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -36,7 +36,7 @@ use rustc_data_structures::work_queue::WorkQueue; use rustc_index::bit_set::BitSet; use rustc_index::vec::{Idx, IndexVec}; use std::fs; -use std::io::{self, Write}; +use std::io::{self, BufWriter, Write}; use std::path::{Path, PathBuf}; pub type LiveVarSet = BitSet; @@ -288,7 +288,8 @@ fn dump_matched_mir_node<'tcx>( let item_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap(); let file_name = format!("rustc.node{}{}-liveness.mir", item_id, pass_name); file_path.push(&file_name); - let _ = fs::File::create(&file_path).and_then(|mut file| { + let _ = fs::File::create(&file_path).and_then(|file| { + let mut file = BufWriter::new(file); writeln!(file, "// MIR local liveness analysis for `{}`", node_path)?; writeln!(file, "// source = {:?}", source)?; writeln!(file, "// pass_name = {}", pass_name)?;