Skip to content

Commit 0999b01

Browse files
committed
Dogfood feature(file_buffered)
1 parent 1e9a50d commit 0999b01

File tree

28 files changed

+44
-40
lines changed

28 files changed

+44
-40
lines changed

compiler/rustc_borrowck/src/facts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::error::Error;
22
use std::fmt::Debug;
33
use std::fs::{self, File};
4-
use std::io::{BufWriter, Write};
4+
use std::io::Write;
55
use std::path::Path;
66

77
use polonius_engine::{AllFacts as PoloniusFacts, Atom};
@@ -127,7 +127,7 @@ impl<'w> FactWriter<'w> {
127127
T: FactRow,
128128
{
129129
let file = &self.dir.join(file_name);
130-
let mut file = BufWriter::new(File::create(file)?);
130+
let mut file = File::create_buffered(file)?;
131131
for row in rows {
132132
row.write(&mut file, self.location_table)?;
133133
}

compiler/rustc_borrowck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(assert_matches)]
77
#![feature(box_patterns)]
88
#![feature(control_flow_enum)]
9+
#![feature(file_buffered)]
910
#![feature(let_chains)]
1011
#![feature(never_type)]
1112
#![feature(rustc_attrs)]

compiler/rustc_codegen_llvm/src/back/lto.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,7 @@ struct ThinLTOKeysMap {
808808
impl ThinLTOKeysMap {
809809
fn save_to_file(&self, path: &Path) -> io::Result<()> {
810810
use std::io::Write;
811-
let file = File::create(path)?;
812-
let mut writer = io::BufWriter::new(file);
811+
let mut writer = File::create_buffered(path)?;
813812
// The entries are loaded back into a hash map in `load_from_file()`, so
814813
// the order in which we write them to file here does not matter.
815814
for (module, key) in &self.keys {
@@ -821,8 +820,8 @@ impl ThinLTOKeysMap {
821820
fn load_from_file(path: &Path) -> io::Result<Self> {
822821
use std::io::BufRead;
823822
let mut keys = BTreeMap::default();
824-
let file = File::open(path)?;
825-
for line in io::BufReader::new(file).lines() {
823+
let file = File::open_buffered(path)?;
824+
for line in file.lines() {
826825
let line = line?;
827826
let mut split = line.split(' ');
828827
let module = split.next().unwrap();

compiler/rustc_codegen_llvm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![feature(assert_matches)]
1212
#![feature(exact_size_is_empty)]
1313
#![feature(extern_types)]
14+
#![feature(file_buffered)]
1415
#![feature(hash_raw_entry)]
1516
#![feature(impl_trait_in_assoc_type)]
1617
#![feature(iter_intersperse)]

compiler/rustc_codegen_ssa/src/back/linker.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use std::ffi::{OsStr, OsString};
22
use std::fs::{self, File};
33
use std::io::prelude::*;
4-
use std::io::{self, BufWriter};
54
use std::path::{Path, PathBuf};
6-
use std::{env, iter, mem, str};
5+
use std::{env, io, iter, mem, str};
76

87
use cc::windows_registry;
98
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
@@ -754,7 +753,7 @@ impl<'a> Linker for GccLinker<'a> {
754753
if self.sess.target.is_like_osx {
755754
// Write a plain, newline-separated list of symbols
756755
let res: io::Result<()> = try {
757-
let mut f = BufWriter::new(File::create(&path)?);
756+
let mut f = File::create_buffered(&path)?;
758757
for sym in symbols {
759758
debug!(" _{sym}");
760759
writeln!(f, "_{sym}")?;
@@ -765,7 +764,7 @@ impl<'a> Linker for GccLinker<'a> {
765764
}
766765
} else if is_windows {
767766
let res: io::Result<()> = try {
768-
let mut f = BufWriter::new(File::create(&path)?);
767+
let mut f = File::create_buffered(&path)?;
769768

770769
// .def file similar to MSVC one but without LIBRARY section
771770
// because LD doesn't like when it's empty
@@ -781,7 +780,7 @@ impl<'a> Linker for GccLinker<'a> {
781780
} else {
782781
// Write an LD version script
783782
let res: io::Result<()> = try {
784-
let mut f = BufWriter::new(File::create(&path)?);
783+
let mut f = File::create_buffered(&path)?;
785784
writeln!(f, "{{")?;
786785
if !symbols.is_empty() {
787786
writeln!(f, " global:")?;
@@ -1059,7 +1058,7 @@ impl<'a> Linker for MsvcLinker<'a> {
10591058

10601059
let path = tmpdir.join("lib.def");
10611060
let res: io::Result<()> = try {
1062-
let mut f = BufWriter::new(File::create(&path)?);
1061+
let mut f = File::create_buffered(&path)?;
10631062

10641063
// Start off with the standard module name header and then go
10651064
// straight to exports.
@@ -1648,7 +1647,7 @@ impl<'a> Linker for AixLinker<'a> {
16481647
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
16491648
let path = tmpdir.join("list.exp");
16501649
let res: io::Result<()> = try {
1651-
let mut f = BufWriter::new(File::create(&path)?);
1650+
let mut f = File::create_buffered(&path)?;
16521651
// FIXME: use llvm-nm to generate export list.
16531652
for symbol in symbols {
16541653
debug!(" _{symbol}");
@@ -1961,7 +1960,7 @@ impl<'a> Linker for BpfLinker<'a> {
19611960
fn export_symbols(&mut self, tmpdir: &Path, _crate_type: CrateType, symbols: &[String]) {
19621961
let path = tmpdir.join("symbols");
19631962
let res: io::Result<()> = try {
1964-
let mut f = BufWriter::new(File::create(&path)?);
1963+
let mut f = File::create_buffered(&path)?;
19651964
for sym in symbols {
19661965
writeln!(f, "{sym}")?;
19671966
}

compiler/rustc_codegen_ssa/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![doc(rust_logo)]
77
#![feature(assert_matches)]
88
#![feature(box_patterns)]
9+
#![feature(file_buffered)]
910
#![feature(if_let_guard)]
1011
#![feature(let_chains)]
1112
#![feature(negative_impls)]

compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(cfg_match)]
2424
#![feature(core_intrinsics)]
2525
#![feature(extend_one)]
26+
#![feature(file_buffered)]
2627
#![feature(hash_raw_entry)]
2728
#![feature(macro_metavar_expr)]
2829
#![feature(map_try_insert)]

compiler/rustc_data_structures/src/obligation_forest/graphviz.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::env::var_os;
22
use std::fs::File;
3-
use std::io::BufWriter;
43
use std::path::Path;
54
use std::sync::atomic::{AtomicUsize, Ordering};
65

@@ -33,7 +32,7 @@ impl<O: ForestObligation> ObligationForest<O> {
3332

3433
let file_path = dir.as_ref().join(format!("{counter:010}_{description}.gv"));
3534

36-
let mut gv_file = BufWriter::new(File::create(file_path).unwrap());
35+
let mut gv_file = File::create_buffered(file_path).unwrap();
3736

3837
dot::render(&self, &mut gv_file).unwrap();
3938
}

compiler/rustc_incremental/src/assert_dep_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
3636
use std::env;
3737
use std::fs::{self, File};
38-
use std::io::{BufWriter, Write};
38+
use std::io::Write;
3939

4040
use rustc_data_structures::fx::FxIndexSet;
4141
use rustc_data_structures::graph::implementation::{Direction, INCOMING, NodeIndex, OUTGOING};
@@ -245,7 +245,7 @@ fn dump_graph(query: &DepGraphQuery) {
245245
{
246246
// dump a .txt file with just the edges:
247247
let txt_path = format!("{path}.txt");
248-
let mut file = BufWriter::new(File::create(&txt_path).unwrap());
248+
let mut file = File::create_buffered(&txt_path).unwrap();
249249
for (source, target) in &edges {
250250
write!(file, "{source:?} -> {target:?}\n").unwrap();
251251
}

compiler/rustc_incremental/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![deny(missing_docs)]
66
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
77
#![doc(rust_logo)]
8+
#![feature(file_buffered)]
89
#![feature(rustdoc_internals)]
910
#![warn(unreachable_pub)]
1011
// tidy-alphabetical-end

compiler/rustc_interface/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// tidy-alphabetical-start
22
#![feature(decl_macro)]
3+
#![feature(file_buffered)]
34
#![feature(let_chains)]
45
#![feature(try_blocks)]
56
#![warn(unreachable_pub)]

compiler/rustc_interface/src/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P
519519
write_deps_to_file(&mut file)?;
520520
}
521521
OutFileName::Real(ref path) => {
522-
let mut file = BufWriter::new(fs::File::create(path)?);
522+
let mut file = fs::File::create_buffered(path)?;
523523
write_deps_to_file(&mut file)?;
524524
}
525525
}

compiler/rustc_metadata/src/fs.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ pub fn non_durable_rename(src: &Path, dst: &Path) -> std::io::Result<()> {
128128
}
129129

130130
pub fn copy_to_stdout(from: &Path) -> io::Result<()> {
131-
let file = fs::File::open(from)?;
132-
let mut reader = io::BufReader::new(file);
131+
let mut reader = fs::File::open_buffered(from)?;
133132
let mut stdout = io::stdout();
134133
io::copy(&mut reader, &mut stdout)?;
135134
Ok(())

compiler/rustc_metadata/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(decl_macro)]
99
#![feature(error_iter)]
1010
#![feature(extract_if)]
11+
#![feature(file_buffered)]
1112
#![feature(if_let_guard)]
1213
#![feature(iter_from_coroutine)]
1314
#![feature(let_chains)]

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#![feature(discriminant_kind)]
4646
#![feature(extern_types)]
4747
#![feature(extract_if)]
48+
#![feature(file_buffered)]
4849
#![feature(if_let_guard)]
4950
#![feature(intra_doc_pointers)]
5051
#![feature(iter_from_coroutine)]

compiler/rustc_middle/src/mir/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ pub fn create_dump_file<'tcx>(
277277
)
278278
})?;
279279
}
280-
Ok(io::BufWriter::new(fs::File::create(&file_path).map_err(|e| {
280+
Ok(fs::File::create_buffered(&file_path).map_err(|e| {
281281
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {file_path:?}; {e}"))
282-
})?))
282+
})?)
283283
}
284284

285285
///////////////////////////////////////////////////////////////////////////

compiler/rustc_mir_dataflow/src/framework/engine.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ where
266266
A::Domain: DebugWithContext<A>,
267267
{
268268
use std::fs;
269-
use std::io::{self, Write};
269+
use std::io::Write;
270270

271271
let def_id = body.source.def_id();
272272
let Ok(attrs) = RustcMirAttrs::parse(tcx, def_id) else {
@@ -281,8 +281,7 @@ where
281281
if let Some(parent) = path.parent() {
282282
fs::create_dir_all(parent)?;
283283
}
284-
let f = fs::File::create(&path)?;
285-
io::BufWriter::new(f)
284+
fs::File::create_buffered(&path)?
286285
}
287286

288287
None if dump_enabled(tcx, A::NAME, def_id) => {

compiler/rustc_mir_dataflow/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(associated_type_defaults)]
44
#![feature(box_patterns)]
55
#![feature(exact_size_is_empty)]
6+
#![feature(file_buffered)]
67
#![feature(let_chains)]
78
#![feature(try_blocks)]
89
#![warn(unreachable_pub)]

compiler/rustc_mir_transform/src/dump_mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn emit_mir(tcx: TyCtxt<'_>) -> io::Result<()> {
2424
write_mir_pretty(tcx, None, &mut f)?;
2525
}
2626
OutFileName::Real(path) => {
27-
let mut f = io::BufWriter::new(File::create(&path)?);
27+
let mut f = File::create_buffered(&path)?;
2828
write_mir_pretty(tcx, None, &mut f)?;
2929
if tcx.sess.opts.json_artifact_notifications {
3030
tcx.dcx().emit_artifact_notification(&path, "mir");

compiler/rustc_mir_transform/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(box_patterns)]
44
#![feature(const_type_name)]
55
#![feature(cow_is_borrowed)]
6+
#![feature(file_buffered)]
67
#![feature(if_let_guard)]
78
#![feature(impl_trait_in_assoc_type)]
89
#![feature(let_chains)]

compiler/rustc_monomorphize/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// tidy-alphabetical-start
22
#![feature(array_windows)]
3+
#![feature(file_buffered)]
34
#![feature(if_let_guard)]
45
#![feature(let_chains)]
56
#![warn(unreachable_pub)]

compiler/rustc_monomorphize/src/partitioning.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
use std::cmp;
9696
use std::collections::hash_map::Entry;
9797
use std::fs::{self, File};
98-
use std::io::{BufWriter, Write};
98+
use std::io::Write;
9999
use std::path::{Path, PathBuf};
100100

101101
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
@@ -1243,8 +1243,7 @@ fn dump_mono_items_stats<'tcx>(
12431243
let ext = format.extension();
12441244
let filename = format!("{crate_name}.mono_items.{ext}");
12451245
let output_path = output_directory.join(&filename);
1246-
let file = File::create(&output_path)?;
1247-
let mut file = BufWriter::new(file);
1246+
let mut file = File::create_buffered(&output_path)?;
12481247

12491248
// Gather instantiated mono items grouped by def_id
12501249
let mut items_per_def_id: FxIndexMap<_, Vec<_>> = Default::default();

library/std/src/sys/pal/unix/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ mod cgroups {
517517
use crate::borrow::Cow;
518518
use crate::ffi::OsString;
519519
use crate::fs::{File, exists};
520-
use crate::io::{BufRead, BufReader, Read};
520+
use crate::io::{BufRead, Read};
521521
use crate::os::unix::ffi::OsStringExt;
522522
use crate::path::{Path, PathBuf};
523523
use crate::str::from_utf8;
@@ -690,7 +690,7 @@ mod cgroups {
690690
/// If the cgroupfs is a bind mount then `group_path` is adjusted to skip
691691
/// over the already-included prefix
692692
fn find_mountpoint(group_path: &Path) -> Option<(Cow<'static, str>, &Path)> {
693-
let mut reader = BufReader::new(File::open("/proc/self/mountinfo").ok()?);
693+
let mut reader = File::open_buffered("/proc/self/mountinfo").ok()?;
694694
let mut line = String::with_capacity(256);
695695
loop {
696696
line.clear();

library/test/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![doc(test(attr(deny(warnings))))]
1919
#![doc(rust_logo)]
2020
#![feature(rustdoc_internals)]
21+
#![feature(file_buffered)]
2122
#![feature(internal_output_capture)]
2223
#![feature(staged_api)]
2324
#![feature(process_exitcode_internals)]

library/test/src/term/terminfo/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
use std::collections::HashMap;
44
use std::fs::File;
55
use std::io::prelude::*;
6-
use std::io::{self, BufReader};
76
use std::path::Path;
8-
use std::{env, error, fmt};
7+
use std::{env, error, fmt, io};
98

109
use parm::{Param, Variables, expand};
1110
use parser::compiled::{msys_terminfo, parse};
@@ -102,8 +101,7 @@ impl TermInfo {
102101
}
103102
// Keep the metadata small
104103
fn _from_path(path: &Path) -> Result<TermInfo, Error> {
105-
let file = File::open(path).map_err(Error::IoError)?;
106-
let mut reader = BufReader::new(file);
104+
let mut reader = File::open_buffered(path).map_err(Error::IoError)?;
107105
parse(&mut reader, false).map_err(Error::MalformedTerminfo)
108106
}
109107
}

src/librustdoc/html/render/write_shared.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use std::cell::RefCell;
1717
use std::ffi::OsString;
1818
use std::fs::File;
19-
use std::io::{self, BufWriter, Write as _};
19+
use std::io::{self, Write as _};
2020
use std::iter::once;
2121
use std::marker::PhantomData;
2222
use std::path::{Component, Path, PathBuf};
@@ -1020,8 +1020,7 @@ where
10201020
for part in parts {
10211021
template.append(part);
10221022
}
1023-
let file = try_err!(File::create(&path), &path);
1024-
let mut file = BufWriter::new(file);
1023+
let mut file = try_err!(File::create_buffered(&path), &path);
10251024
try_err!(write!(file, "{template}"), &path);
10261025
try_err!(file.flush(), &path);
10271026
}

src/librustdoc/json/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
286286

287287
self.serialize_and_write(
288288
output_crate,
289-
BufWriter::new(try_err!(File::create(&p), p)),
289+
try_err!(File::create_buffered(&p), p),
290290
&p.display().to_string(),
291291
)
292292
} else {

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![feature(rustc_private)]
66
#![feature(assert_matches)]
77
#![feature(box_patterns)]
8+
#![feature(file_buffered)]
89
#![feature(if_let_guard)]
910
#![feature(impl_trait_in_assoc_type)]
1011
#![feature(iter_intersperse)]

0 commit comments

Comments
 (0)