@@ -15,7 +15,7 @@ use rustc_ast::CRATE_NODE_ID;
1515use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
1616use rustc_data_structures:: memmap:: Mmap ;
1717use rustc_data_structures:: temp_dir:: MaybeTempDir ;
18- use rustc_errors:: { DiagCtxtHandle , FatalError } ;
18+ use rustc_errors:: DiagCtxtHandle ;
1919use rustc_fs_util:: { fix_windows_verbatim_for_gcc, try_canonicalize} ;
2020use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
2121use rustc_metadata:: fs:: { METADATA_FILENAME , copy_to_stdout, emit_wrapper_file} ;
@@ -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,8 +259,9 @@ pub fn each_linked_rlib(
261259 info. dependency_formats . first ( ) . unwrap ( ) . 1
262260 } ;
263261
264- for & cnum in crates {
265- match fmts. get ( cnum. as_usize ( ) - 1 ) {
262+ let used_dep_crates = info. used_crates . iter ( ) ;
263+ for & cnum in used_dep_crates {
264+ match fmts. get ( cnum) {
266265 Some ( & Linkage :: NotLinked | & Linkage :: Dynamic | & Linkage :: IncludedFromDylib ) => continue ,
267266 Some ( _) => { }
268267 None => return Err ( errors:: LinkRlibError :: MissingFormat ) ,
@@ -624,7 +623,7 @@ fn link_staticlib(
624623
625624 let mut all_rust_dylibs = vec ! [ ] ;
626625 for & cnum in crates {
627- match fmts. get ( cnum. as_usize ( ) - 1 ) {
626+ match fmts. get ( cnum) {
628627 Some ( & Linkage :: Dynamic ) => { }
629628 _ => continue ,
630629 }
@@ -1039,22 +1038,22 @@ fn link_natively(
10391038 Err ( e) => {
10401039 let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
10411040
1042- if linker_not_found {
1043- sess. dcx ( ) . emit_err ( errors:: LinkerNotFound { linker_path, error : e } ) ;
1041+ let err = if linker_not_found {
1042+ sess. dcx ( ) . emit_err ( errors:: LinkerNotFound { linker_path, error : e } )
10441043 } else {
10451044 sess. dcx ( ) . emit_err ( errors:: UnableToExeLinker {
10461045 linker_path,
10471046 error : e,
10481047 command_formatted : format ! ( "{cmd:?}" ) ,
1049- } ) ;
1050- }
1048+ } )
1049+ } ;
10511050
10521051 if sess. target . is_like_msvc && linker_not_found {
10531052 sess. dcx ( ) . emit_note ( errors:: MsvcMissingLinker ) ;
10541053 sess. dcx ( ) . emit_note ( errors:: CheckInstalledVisualStudio ) ;
10551054 sess. dcx ( ) . emit_note ( errors:: InsufficientVSCodeProduct ) ;
10561055 }
1057- FatalError . raise ( ) ;
1056+ err . raise_fatal ( ) ;
10581057 }
10591058 }
10601059
@@ -2361,8 +2360,8 @@ fn linker_with_args(
23612360 . crate_info
23622361 . native_libraries
23632362 . iter ( )
2364- . filter_map ( |( cnum, libraries) | {
2365- ( dependency_linkage[ cnum. as_usize ( ) - 1 ] != Linkage :: Static ) . then_some ( libraries)
2363+ . filter_map ( |( & cnum, libraries) | {
2364+ ( dependency_linkage[ cnum] != Linkage :: Static ) . then_some ( libraries)
23662365 } )
23672366 . flatten ( )
23682367 . collect :: < Vec < _ > > ( ) ;
@@ -2754,7 +2753,7 @@ fn add_upstream_rust_crates(
27542753 // (e.g. `libstd` when `-C prefer-dynamic` is used).
27552754 // FIXME: `dependency_formats` can report `profiler_builtins` as `NotLinked` for some
27562755 // reason, it shouldn't do that because `profiler_builtins` should indeed be linked.
2757- let linkage = data[ cnum. as_usize ( ) - 1 ] ;
2756+ let linkage = data[ cnum] ;
27582757 let link_static_crate = linkage == Linkage :: Static
27592758 || ( linkage == Linkage :: IncludedFromDylib || linkage == Linkage :: NotLinked )
27602759 && ( codegen_results. crate_info . compiler_builtins == Some ( cnum)
0 commit comments