Skip to content

Commit

Permalink
Rollup merge of #116067 - saethlin:meta-stats-ice, r=WaffleLapkin
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
matthiaskrgr committed Sep 22, 2023
2 parents 952d660 + 09960e0 commit efee13a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ pub struct FileEncoder {

impl FileEncoder {
pub fn new<P: AsRef<Path>>(path: P) -> io::Result<Self> {
// File::create opens the file for writing only. When -Zmeta-stats is enabled, the metadata
// encoder rewinds the file to inspect what was written. So we need to always open the file
// for reading and writing.
let file = File::options().read(true).write(true).create(true).truncate(true).open(path)?;

Ok(FileEncoder {
buf: vec![0u8; BUF_SIZE].into_boxed_slice().try_into().unwrap(),
buffered: 0,
flushed: 0,
file: File::create(path)?,
file,
res: Ok(()),
})
}
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/stats/meta-stats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// build-pass
// dont-check-compiler-stderr
// compile-flags: -Zmeta-stats

#![crate_type = "lib"]

pub fn a() {}

0 comments on commit efee13a

Please sign in to comment.