Skip to content

Commit efee13a

Browse files
authored
Rollup merge of #116067 - saethlin:meta-stats-ice, r=WaffleLapkin
Open the FileEncoder file for reading and writing Maybe I just don't know `File` well enough, but the previous comment didn't make it clear enough to me that we can't use `File::create`. This one does. Fixes #116055 r? `@WaffleLapkin`
2 parents 952d660 + 09960e0 commit efee13a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Diff for: compiler/rustc_serialize/src/opaque.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ pub struct FileEncoder {
3838

3939
impl FileEncoder {
4040
pub fn new<P: AsRef<Path>>(path: P) -> io::Result<Self> {
41+
// File::create opens the file for writing only. When -Zmeta-stats is enabled, the metadata
42+
// encoder rewinds the file to inspect what was written. So we need to always open the file
43+
// for reading and writing.
44+
let file = File::options().read(true).write(true).create(true).truncate(true).open(path)?;
45+
4146
Ok(FileEncoder {
4247
buf: vec![0u8; BUF_SIZE].into_boxed_slice().try_into().unwrap(),
4348
buffered: 0,
4449
flushed: 0,
45-
file: File::create(path)?,
50+
file,
4651
res: Ok(()),
4752
})
4853
}

Diff for: tests/ui/stats/meta-stats.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// build-pass
2+
// dont-check-compiler-stderr
3+
// compile-flags: -Zmeta-stats
4+
5+
#![crate_type = "lib"]
6+
7+
pub fn a() {}

0 commit comments

Comments
 (0)