diff options
| author | Ben Kimock <kimockb@gmail.com> | 2023-09-22 12:34:30 -0400 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2023-09-22 16:13:25 -0400 |
| commit | 09960e03194626738b3533b6c2d06a0c505117d3 (patch) | |
| tree | 6ca271de52a399327fc4351bda53d08a7a3c8e53 | |
| parent | f73d376fb669859b167cb04121c52f7f6f71a05e (diff) | |
| download | rust-09960e03194626738b3533b6c2d06a0c505117d3.tar.gz rust-09960e03194626738b3533b6c2d06a0c505117d3.zip | |
Open the FileEncoder file for reading and writing
| -rw-r--r-- | compiler/rustc_serialize/src/opaque.rs | 7 | ||||
| -rw-r--r-- | tests/ui/stats/meta-stats.rs | 7 |
2 files changed, 13 insertions, 1 deletions
diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index 44855ae629c..55255439051 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -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(()), }) } diff --git a/tests/ui/stats/meta-stats.rs b/tests/ui/stats/meta-stats.rs new file mode 100644 index 00000000000..2d38e088286 --- /dev/null +++ b/tests/ui/stats/meta-stats.rs @@ -0,0 +1,7 @@ +// build-pass +// dont-check-compiler-stderr +// compile-flags: -Zmeta-stats + +#![crate_type = "lib"] + +pub fn a() {} |
