Skip to content

Commit ad55481

Browse files
committed
add some comments for encode_and_write_metadata
1 parent 63dec94 commit ad55481

File tree

1 file changed

+6
-0
lines changed
  • compiler/rustc_metadata/src

1 file changed

+6
-0
lines changed

compiler/rustc_metadata/src/fs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ pub fn encode_and_write_metadata(
6969
let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps);
7070
let metadata_filename = metadata_tmpdir.as_ref().join(METADATA_FILENAME);
7171

72+
// Always create a file at `metadata_filename`, even if we have nothing to write to it.
73+
// This simplifies the creation of the output `out_filename` when requested.
7274
match metadata_kind {
7375
MetadataKind::None => {
7476
std::fs::File::create(&metadata_filename).unwrap_or_else(|e| {
@@ -86,6 +88,9 @@ pub fn encode_and_write_metadata(
8688

8789
let _prof_timer = tcx.sess.prof.generic_activity("write_crate_metadata");
8890

91+
// If the user requests metadata as output, rename `metadata_filename`
92+
// to the expected output `out_filename`. The match above should ensure
93+
// this file always exists.
8994
let need_metadata_file = tcx.sess.opts.output_types.contains_key(&OutputType::Metadata);
9095
let (metadata_filename, metadata_tmpdir) = if need_metadata_file {
9196
if let Err(e) = non_durable_rename(&metadata_filename, &out_filename) {
@@ -102,6 +107,7 @@ pub fn encode_and_write_metadata(
102107
(metadata_filename, Some(metadata_tmpdir))
103108
};
104109

110+
// Load metadata back to memory: codegen may need to include it in object files.
105111
let metadata =
106112
EncodedMetadata::from_path(metadata_filename, metadata_tmpdir).unwrap_or_else(|e| {
107113
tcx.sess.fatal(&format!("failed to create encoded metadata from file: {}", e))

0 commit comments

Comments
 (0)