From 06139e57d5c0afb1e7e8d7815d742cd2da7d5dca Mon Sep 17 00:00:00 2001 From: "Sikkema, Isaac" <sikkemaic@ornl.gov> Date: Thu, 25 Aug 2022 18:00:45 -0400 Subject: [PATCH 1/2] use `File::options()` instead of `File::create()` --- compiler/rustc_serialize/src/opaque.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index 5c17ef6ace2..f9edb073a2d 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -193,7 +193,7 @@ impl FileEncoder { // shaves an instruction off those code paths (on x86 at least). assert!(capacity <= usize::MAX - max_leb128_len()); - let file = File::create(path)?; + let file = File::options().read(true).write(true).create(true).truncate(true).open(path)?; Ok(FileEncoder { buf: Box::new_uninit_slice(capacity), From a2cb8a49498c9eab1cf5617135e7de0b3013843b Mon Sep 17 00:00:00 2001 From: "Sikkema, Isaac" <sikkemaic@ornl.gov> Date: Tue, 20 Sep 2022 10:06:50 -0400 Subject: [PATCH 2/2] add comment explaining read permissions --- compiler/rustc_serialize/src/opaque.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_serialize/src/opaque.rs b/compiler/rustc_serialize/src/opaque.rs index f9edb073a2d..f35cc08f4fb 100644 --- a/compiler/rustc_serialize/src/opaque.rs +++ b/compiler/rustc_serialize/src/opaque.rs @@ -193,6 +193,8 @@ impl FileEncoder { // shaves an instruction off those code paths (on x86 at least). assert!(capacity <= usize::MAX - max_leb128_len()); + // Create the file for reading and writing, because some encoders do both + // (e.g. the metadata encoder when -Zmeta-stats is enabled) let file = File::options().read(true).write(true).create(true).truncate(true).open(path)?; Ok(FileEncoder {