Skip to content

Commit 8c9a8b6

Browse files
committed
Fix review comments
1 parent aa98c5d commit 8c9a8b6

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

compiler/rustc_codegen_ssa/src/back/metadata.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -479,15 +479,15 @@ pub fn create_compressed_metadata_file(
479479
metadata: &EncodedMetadata,
480480
symbol_name: &str,
481481
) -> Vec<u8> {
482-
let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
483-
compressed.write_all(&(metadata.raw_data().len() as u32).to_be_bytes()).unwrap();
484-
compressed.extend(metadata.raw_data());
482+
let mut packed_metadata = rustc_metadata::METADATA_HEADER.to_vec();
483+
packed_metadata.write_all(&(metadata.raw_data().len() as u32).to_be_bytes()).unwrap();
484+
packed_metadata.extend(metadata.raw_data());
485485

486486
let Some(mut file) = create_object_file(sess) else {
487-
return compressed.to_vec();
487+
return packed_metadata.to_vec();
488488
};
489489
if file.format() == BinaryFormat::Xcoff {
490-
return create_compressed_metadata_file_for_xcoff(file, &compressed, symbol_name);
490+
return create_compressed_metadata_file_for_xcoff(file, &packed_metadata, symbol_name);
491491
}
492492
let section = file.add_section(
493493
file.segment_name(StandardSegment::Data).to_vec(),
@@ -501,14 +501,14 @@ pub fn create_compressed_metadata_file(
501501
}
502502
_ => {}
503503
};
504-
let offset = file.append_section_data(section, &compressed, 1);
504+
let offset = file.append_section_data(section, &packed_metadata, 1);
505505

506506
// For MachO and probably PE this is necessary to prevent the linker from throwing away the
507507
// .rustc section. For ELF this isn't necessary, but it also doesn't harm.
508508
file.add_symbol(Symbol {
509509
name: symbol_name.as_bytes().to_vec(),
510510
value: offset,
511-
size: compressed.len() as u64,
511+
size: packed_metadata.len() as u64,
512512
kind: SymbolKind::Data,
513513
scope: SymbolScope::Dynamic,
514514
weak: false,

compiler/rustc_metadata/src/locator.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ impl<'a> CrateLocator<'a> {
511511
rlib: self.extract_one(rlibs, CrateFlavor::Rlib, &mut slot)?,
512512
dylib: self.extract_one(dylibs, CrateFlavor::Dylib, &mut slot)?,
513513
};
514-
Ok(slot.map(|(_, svh, metadata)| (svh, Library { source, metadata })))
514+
Ok(slot.map(|(svh, metadata, _)| (svh, Library { source, metadata })))
515515
}
516516

517517
fn needs_crate_flavor(&self, flavor: CrateFlavor) -> bool {
@@ -535,11 +535,13 @@ impl<'a> CrateLocator<'a> {
535535
// read the metadata from it if `*slot` is `None`. If the metadata couldn't
536536
// be read, it is assumed that the file isn't a valid rust library (no
537537
// errors are emitted).
538+
//
539+
// The `PathBuf` in `slot` will only be used for diagnostic purposes.
538540
fn extract_one(
539541
&mut self,
540542
m: FxHashMap<PathBuf, PathKind>,
541543
flavor: CrateFlavor,
542-
slot: &mut Option<(PathBuf, Svh, MetadataBlob)>,
544+
slot: &mut Option<(Svh, MetadataBlob, PathBuf)>,
543545
) -> Result<Option<(PathBuf, PathKind)>, CrateError> {
544546
// If we are producing an rlib, and we've already loaded metadata, then
545547
// we should not attempt to discover further crate sources (unless we're
@@ -595,15 +597,15 @@ impl<'a> CrateLocator<'a> {
595597
}
596598
};
597599
// If we see multiple hashes, emit an error about duplicate candidates.
598-
if slot.as_ref().is_some_and(|s| s.1 != hash) {
600+
if slot.as_ref().is_some_and(|s| s.0 != hash) {
599601
if let Some(candidates) = err_data {
600602
return Err(CrateError::MultipleCandidates(
601603
self.crate_name,
602604
flavor,
603605
candidates,
604606
));
605607
}
606-
err_data = Some(vec![slot.take().unwrap().0]);
608+
err_data = Some(vec![slot.take().unwrap().2]);
607609
}
608610
if let Some(candidates) = &mut err_data {
609611
candidates.push(lib);
@@ -636,7 +638,7 @@ impl<'a> CrateLocator<'a> {
636638
continue;
637639
}
638640
}
639-
*slot = Some((lib.clone(), hash, metadata));
641+
*slot = Some((hash, metadata, lib.clone()));
640642
ret = Some((lib, kind));
641643
}
642644

0 commit comments

Comments
 (0)