Skip to content

Commit 0daa921

Browse files
committed
Review comments
1 parent 943f6a8 commit 0daa921

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,6 @@ pub fn each_linked_rlib(
234234
crate_type: Option<CrateType>,
235235
f: &mut dyn FnMut(CrateNum, &Path),
236236
) -> Result<(), errors::LinkRlibError> {
237-
let crates = info.used_crates.iter();
238-
239237
let fmts = if let Some(crate_type) = crate_type {
240238
let Some(fmts) = info.dependency_formats.get(&crate_type) else {
241239
return Err(errors::LinkRlibError::MissingFormat);
@@ -261,7 +259,8 @@ pub fn each_linked_rlib(
261259
info.dependency_formats.first().unwrap().1
262260
};
263261

264-
for &cnum in crates {
262+
let used_dep_crates = info.used_crates.iter();
263+
for &cnum in used_dep_crates {
265264
match fmts.get(cnum) {
266265
Some(&Linkage::NotLinked | &Linkage::Dynamic | &Linkage::IncludedFromDylib) => continue,
267266
Some(_) => {}

compiler/rustc_metadata/src/dependency_format.rs

+7
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,14 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList {
212212
// Collect what we've got so far in the return vector.
213213
let last_crate = tcx.crates(()).len();
214214
let mut ret = IndexVec::new();
215+
216+
// We need to fill in something for LOCAL_CRATE as IndexVec is a dense map.
217+
// Linkage::Static semantically the most correct thing to use as the local
218+
// crate is always statically linked into the linker output, even when
219+
// linking a dylib. Using Linkage::Static also allow avoiding special cases
220+
// for LOCAL_CRATE in some places.
215221
assert_eq!(ret.push(Linkage::Static), LOCAL_CRATE);
222+
216223
for cnum in 1..last_crate + 1 {
217224
let cnum = CrateNum::new(cnum);
218225
assert_eq!(

0 commit comments

Comments
 (0)