Skip to content

Commit 4c8ebbe

Browse files
committed
Open the FileEncoder file for reading and writing
1 parent f73d376 commit 4c8ebbe

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

compiler/rustc_serialize/src/opaque.rs

Lines changed: 6 additions & 1 deletion
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+
// rewinds the file to inspect what was written. So we need to always open the file for
43+
// 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
}

src/tools/tidy/src/ui_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::path::{Path, PathBuf};
1111
const ENTRY_LIMIT: usize = 900;
1212
// FIXME: The following limits should be reduced eventually.
1313
const ISSUES_ENTRY_LIMIT: usize = 1854;
14-
const ROOT_ENTRY_LIMIT: usize = 865;
14+
const ROOT_ENTRY_LIMIT: usize = 867;
1515

1616
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
1717
"rs", // test source files

tests/ui/meta-stats.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// build-pass
2+
// compile-flags: -Zmeta-stats
3+
4+
#![crate_type = "lib"]
5+
6+
pub fn a() {}

tests/ui/meta-stats.stderr

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
meta-stats METADATA STATS
2+
meta-stats Section Size
3+
meta-stats ----------------------------------------------------------------
4+
meta-stats lib-features 0 ( 0.0%)
5+
meta-stats stability-implications 0 ( 0.0%)
6+
meta-stats lang-items 0 ( 0.0%)
7+
meta-stats stripped-cfg-items 0 ( 0.0%)
8+
meta-stats diagnostic-items 0 ( 0.0%)
9+
meta-stats native-libs 0 ( 0.0%)
10+
meta-stats foreign-modules 0 ( 0.0%)
11+
meta-stats traits 0 ( 0.0%)
12+
meta-stats impls 0 ( 0.0%)
13+
meta-stats incoherent-impls 0 ( 0.0%)
14+
meta-stats mir 0 ( 0.0%)
15+
meta-stats interpret-alloc-index 0 ( 0.0%)
16+
meta-stats proc-macro-data 0 ( 0.0%)
17+
meta-stats debugger-visualizers 0 ( 0.0%)
18+
meta-stats exported-symbols 6 ( 0.3%)
19+
meta-stats def-path-table 22 ( 1.0%)
20+
meta-stats preamble 30 ( 1.3%)
21+
meta-stats source-map 105 ( 4.7%)
22+
meta-stats hygiene 111 ( 5.0%)
23+
meta-stats def-ids 153 ( 6.9%)
24+
meta-stats tables 192 ( 8.6%)
25+
meta-stats final 317 (14.2%)
26+
meta-stats def-path-hash-map 386 (17.3%)
27+
meta-stats dep 909 (40.7%)
28+
meta-stats ----------------------------------------------------------------
29+
meta-stats Total 2_231 (of which 33.2% are zero bytes)
30+
meta-stats

0 commit comments

Comments
 (0)