Skip to content

Commit 09960e0

Browse files
committed
Open the FileEncoder file for reading and writing
1 parent f73d376 commit 09960e0

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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
}

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)