@@ -15,7 +15,7 @@ use rustc_ast::CRATE_NODE_ID;
15
15
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
16
16
use rustc_data_structures:: memmap:: Mmap ;
17
17
use rustc_data_structures:: temp_dir:: MaybeTempDir ;
18
- use rustc_errors:: { DiagCtxtHandle , FatalError } ;
18
+ use rustc_errors:: DiagCtxtHandle ;
19
19
use rustc_fs_util:: { fix_windows_verbatim_for_gcc, try_canonicalize} ;
20
20
use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
21
21
use rustc_metadata:: fs:: { METADATA_FILENAME , copy_to_stdout, emit_wrapper_file} ;
@@ -234,8 +234,6 @@ pub fn each_linked_rlib(
234
234
crate_type : Option < CrateType > ,
235
235
f : & mut dyn FnMut ( CrateNum , & Path ) ,
236
236
) -> Result < ( ) , errors:: LinkRlibError > {
237
- let crates = info. used_crates . iter ( ) ;
238
-
239
237
let fmts = if let Some ( crate_type) = crate_type {
240
238
let Some ( fmts) = info. dependency_formats . get ( & crate_type) else {
241
239
return Err ( errors:: LinkRlibError :: MissingFormat ) ;
@@ -261,8 +259,9 @@ pub fn each_linked_rlib(
261
259
info. dependency_formats . first ( ) . unwrap ( ) . 1
262
260
} ;
263
261
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) {
266
265
Some ( & Linkage :: NotLinked | & Linkage :: Dynamic | & Linkage :: IncludedFromDylib ) => continue ,
267
266
Some ( _) => { }
268
267
None => return Err ( errors:: LinkRlibError :: MissingFormat ) ,
@@ -624,7 +623,7 @@ fn link_staticlib(
624
623
625
624
let mut all_rust_dylibs = vec ! [ ] ;
626
625
for & cnum in crates {
627
- match fmts. get ( cnum. as_usize ( ) - 1 ) {
626
+ match fmts. get ( cnum) {
628
627
Some ( & Linkage :: Dynamic ) => { }
629
628
_ => continue ,
630
629
}
@@ -1039,22 +1038,22 @@ fn link_natively(
1039
1038
Err ( e) => {
1040
1039
let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
1041
1040
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 } )
1044
1043
} else {
1045
1044
sess. dcx ( ) . emit_err ( errors:: UnableToExeLinker {
1046
1045
linker_path,
1047
1046
error : e,
1048
1047
command_formatted : format ! ( "{cmd:?}" ) ,
1049
- } ) ;
1050
- }
1048
+ } )
1049
+ } ;
1051
1050
1052
1051
if sess. target . is_like_msvc && linker_not_found {
1053
1052
sess. dcx ( ) . emit_note ( errors:: MsvcMissingLinker ) ;
1054
1053
sess. dcx ( ) . emit_note ( errors:: CheckInstalledVisualStudio ) ;
1055
1054
sess. dcx ( ) . emit_note ( errors:: InsufficientVSCodeProduct ) ;
1056
1055
}
1057
- FatalError . raise ( ) ;
1056
+ err . raise_fatal ( ) ;
1058
1057
}
1059
1058
}
1060
1059
@@ -2361,8 +2360,8 @@ fn linker_with_args(
2361
2360
. crate_info
2362
2361
. native_libraries
2363
2362
. 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)
2366
2365
} )
2367
2366
. flatten ( )
2368
2367
. collect :: < Vec < _ > > ( ) ;
@@ -2754,7 +2753,7 @@ fn add_upstream_rust_crates(
2754
2753
// (e.g. `libstd` when `-C prefer-dynamic` is used).
2755
2754
// FIXME: `dependency_formats` can report `profiler_builtins` as `NotLinked` for some
2756
2755
// 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] ;
2758
2757
let link_static_crate = linkage == Linkage :: Static
2759
2758
|| ( linkage == Linkage :: IncludedFromDylib || linkage == Linkage :: NotLinked )
2760
2759
&& ( codegen_results. crate_info . compiler_builtins == Some ( cnum)
0 commit comments