From b18fee64ddfd717e778d0bf44bfd2aaa3d0dee87 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Fri, 22 Sep 2023 12:34:30 -0400 Subject: [PATCH] Open the FileEncoder file for reading and writing --- compiler/rustc_serialize/src/opaque.rs | 7 +++++- tests/ui/meta-stats.rs | 6 ++++++ tests/ui/meta-stats.stderr | 30 ++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/ui/meta-stats.rs create mode 100644 tests/ui/meta-stats.stderr diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index 44855ae629c13..86bb542ef170a 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>(path: P) -> io::Result { + // File::create opens the file for writing only. When -Zmeta-stats is enabled, the metadata + // 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/meta-stats.rs b/tests/ui/meta-stats.rs new file mode 100644 index 0000000000000..7fd3b7b3c63bc --- /dev/null +++ b/tests/ui/meta-stats.rs @@ -0,0 +1,6 @@ +// build-pass +// compile-flags: -Zmeta-stats + +#![crate_type = "lib"] + +pub fn a() {} diff --git a/tests/ui/meta-stats.stderr b/tests/ui/meta-stats.stderr new file mode 100644 index 0000000000000..643920645dfe0 --- /dev/null +++ b/tests/ui/meta-stats.stderr @@ -0,0 +1,30 @@ +meta-stats METADATA STATS +meta-stats Section Size +meta-stats ---------------------------------------------------------------- +meta-stats lib-features 0 ( 0.0%) +meta-stats stability-implications 0 ( 0.0%) +meta-stats lang-items 0 ( 0.0%) +meta-stats stripped-cfg-items 0 ( 0.0%) +meta-stats diagnostic-items 0 ( 0.0%) +meta-stats native-libs 0 ( 0.0%) +meta-stats foreign-modules 0 ( 0.0%) +meta-stats traits 0 ( 0.0%) +meta-stats impls 0 ( 0.0%) +meta-stats incoherent-impls 0 ( 0.0%) +meta-stats mir 0 ( 0.0%) +meta-stats interpret-alloc-index 0 ( 0.0%) +meta-stats proc-macro-data 0 ( 0.0%) +meta-stats debugger-visualizers 0 ( 0.0%) +meta-stats exported-symbols 6 ( 0.3%) +meta-stats def-path-table 22 ( 1.0%) +meta-stats preamble 30 ( 1.3%) +meta-stats source-map 105 ( 4.7%) +meta-stats hygiene 111 ( 5.0%) +meta-stats def-ids 153 ( 6.9%) +meta-stats tables 192 ( 8.6%) +meta-stats final 317 (14.2%) +meta-stats def-path-hash-map 386 (17.3%) +meta-stats dep 909 (40.7%) +meta-stats ---------------------------------------------------------------- +meta-stats Total 2_231 (of which 33.2% are zero bytes) +meta-stats