@@ -919,29 +919,17 @@ fn link_natively<'a>(
919
919
)
920
920
. is_some ( ) ;
921
921
922
- sess. note_without_error ( "`link.exe` returned an unexpected error" ) ;
922
+ sess. emit_note ( errors :: LinkExeUnexpectedError ) ;
923
923
if is_vs_installed && has_linker {
924
924
// the linker is broken
925
- sess. note_without_error (
926
- "the Visual Studio build tools may need to be repaired \
927
- using the Visual Studio installer",
928
- ) ;
929
- sess. note_without_error (
930
- "or a necessary component may be missing from the \
931
- \" C++ build tools\" workload",
932
- ) ;
925
+ sess. emit_note ( errors:: RepairVSBuildTools ) ;
926
+ sess. emit_note ( errors:: MissingCppBuildToolComponent ) ;
933
927
} else if is_vs_installed {
934
928
// the linker is not installed
935
- sess. note_without_error (
936
- "in the Visual Studio installer, ensure the \
937
- \" C++ build tools\" workload is selected",
938
- ) ;
929
+ sess. emit_note ( errors:: SelectCppBuildToolWorkload ) ;
939
930
} else {
940
931
// visual studio is not installed
941
- sess. note_without_error (
942
- "you may need to install Visual Studio build tools with the \
943
- \" C++ build tools\" workload",
944
- ) ;
932
+ sess. emit_note ( errors:: VisualStudioNotInstalled ) ;
945
933
}
946
934
}
947
935
}
@@ -954,35 +942,20 @@ fn link_natively<'a>(
954
942
Err ( e) => {
955
943
let linker_not_found = e. kind ( ) == io:: ErrorKind :: NotFound ;
956
944
957
- let mut linker_error = {
958
- if linker_not_found {
959
- sess. struct_err ( & format ! ( "linker `{}` not found" , linker_path. display( ) ) )
960
- } else {
961
- sess. struct_err ( & format ! (
962
- "could not exec the linker `{}`" ,
963
- linker_path. display( )
964
- ) )
965
- }
966
- } ;
967
-
968
- linker_error. note ( & e. to_string ( ) ) ;
969
-
970
- if !linker_not_found {
971
- linker_error. note ( & format ! ( "{:?}" , & cmd) ) ;
945
+ if linker_not_found {
946
+ sess. emit_err ( errors:: LinkerNotFound { linker_path, error : e } ) ;
947
+ } else {
948
+ sess. emit_err ( errors:: UnableToExeLinker {
949
+ linker_path,
950
+ error : e,
951
+ command_formatted : format ! ( "{:?}" , & cmd) ,
952
+ } ) ;
972
953
}
973
954
974
- linker_error. emit ( ) ;
975
-
976
955
if sess. target . is_like_msvc && linker_not_found {
977
- sess. note_without_error (
978
- "the msvc targets depend on the msvc linker \
979
- but `link.exe` was not found",
980
- ) ;
981
- sess. note_without_error (
982
- "please ensure that Visual Studio 2017 or later, or Build Tools \
983
- for Visual Studio were installed with the Visual C++ option.",
984
- ) ;
985
- sess. note_without_error ( "VS Code is a different product, and is not sufficient." ) ;
956
+ sess. emit_note ( errors:: MsvcMissingLinker ) ;
957
+ sess. emit_note ( errors:: CheckInstalledVisualStudio ) ;
958
+ sess. emit_note ( errors:: UnsufficientVSCodeProduct ) ;
986
959
}
987
960
sess. abort_if_errors ( ) ;
988
961
}
@@ -1007,15 +980,13 @@ fn link_natively<'a>(
1007
980
if !prog. status . success ( ) {
1008
981
let mut output = prog. stderr . clone ( ) ;
1009
982
output. extend_from_slice ( & prog. stdout ) ;
1010
- sess. struct_warn ( & format ! (
1011
- "processing debug info with `dsymutil` failed: {}" ,
1012
- prog. status
1013
- ) )
1014
- . note ( & escape_string ( & output) )
1015
- . emit ( ) ;
983
+ sess. emit_warning ( errors:: ProcessingDymutilFailed {
984
+ status : prog. status ,
985
+ output : escape_string ( & output) ,
986
+ } ) ;
1016
987
}
1017
988
}
1018
- Err ( e ) => sess. fatal ( & format ! ( "unable to run `dsymutil`: {}" , e ) ) ,
989
+ Err ( error ) => sess. emit_fatal ( errors :: UnableToRunDsymutil { error } ) ,
1019
990
}
1020
991
}
1021
992
@@ -1092,15 +1063,14 @@ fn strip_symbols_with_external_utility<'a>(
1092
1063
if !prog. status . success ( ) {
1093
1064
let mut output = prog. stderr . clone ( ) ;
1094
1065
output. extend_from_slice ( & prog. stdout ) ;
1095
- sess. struct_warn ( & format ! (
1096
- "stripping debug info with `{}` failed: {}" ,
1097
- util, prog. status
1098
- ) )
1099
- . note ( & escape_string ( & output) )
1100
- . emit ( ) ;
1066
+ sess. emit_warning ( errors:: StrippingDebugInfoFailed {
1067
+ util,
1068
+ status : prog. status ,
1069
+ output : escape_string ( & output) ,
1070
+ } ) ;
1101
1071
}
1102
1072
}
1103
- Err ( e ) => sess. fatal ( & format ! ( "unable to run `{}`: {}" , util, e ) ) ,
1073
+ Err ( error ) => sess. emit_fatal ( errors :: UnableToRun { util, error } ) ,
1104
1074
}
1105
1075
}
1106
1076
@@ -1251,7 +1221,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
1251
1221
) ) ,
1252
1222
( Some ( linker) , None ) => {
1253
1223
let stem = linker. file_stem ( ) . and_then ( |stem| stem. to_str ( ) ) . unwrap_or_else ( || {
1254
- sess. fatal ( "couldn't extract file stem from specified linker" )
1224
+ sess. emit_fatal ( errors :: LinkerFileStem ) ;
1255
1225
} ) ;
1256
1226
1257
1227
let flavor = if stem == "emcc" {
@@ -1378,13 +1348,9 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
1378
1348
} )
1379
1349
. collect ( ) ;
1380
1350
if !lib_args. is_empty ( ) {
1381
- sess. note_without_error (
1382
- "Link against the following native artifacts when linking \
1383
- against this static library. The order and any duplication \
1384
- can be significant on some platforms.",
1385
- ) ;
1351
+ sess. emit_note ( errors:: StaticLibraryNativeArtifacts ) ;
1386
1352
// Prefix for greppability
1387
- sess. note_without_error ( & format ! ( "native-static-libs: {}" , & lib_args. join( " " ) ) ) ;
1353
+ sess. emit_note ( errors :: NativeStaticLibs { arguments : lib_args. join ( " " ) } ) ;
1388
1354
}
1389
1355
}
1390
1356
@@ -1688,14 +1654,14 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty
1688
1654
match ( crate_type, & sess. target . link_script ) {
1689
1655
( CrateType :: Cdylib | CrateType :: Executable , Some ( script) ) => {
1690
1656
if !sess. target . linker_flavor . is_gnu ( ) {
1691
- sess. fatal ( "can only use link script when linking with GNU-like linker" ) ;
1657
+ sess. emit_fatal ( errors :: LinkScriptUnavailable ) ;
1692
1658
}
1693
1659
1694
1660
let file_name = [ "rustc" , & sess. target . llvm_target , "linkfile.ld" ] . join ( "-" ) ;
1695
1661
1696
1662
let path = tmpdir. join ( file_name) ;
1697
- if let Err ( e ) = fs:: write ( & path, script. as_ref ( ) ) {
1698
- sess. fatal ( & format ! ( "failed to write link script to {}: {}" , path. display ( ) , e ) ) ;
1663
+ if let Err ( error ) = fs:: write ( & path, script. as_ref ( ) ) {
1664
+ sess. emit_fatal ( errors :: LinkScriptWriteFailure { path, error } ) ;
1699
1665
}
1700
1666
1701
1667
cmd. arg ( "--script" ) ;
@@ -1841,8 +1807,8 @@ fn add_linked_symbol_object(
1841
1807
1842
1808
let path = tmpdir. join ( "symbols.o" ) ;
1843
1809
let result = std:: fs:: write ( & path, file. write ( ) . unwrap ( ) ) ;
1844
- if let Err ( e ) = result {
1845
- sess. fatal ( & format ! ( "failed to write {}: {}" , path. display ( ) , e ) ) ;
1810
+ if let Err ( error ) = result {
1811
+ sess. emit_fatal ( errors :: FailedToWrite { path, error } ) ;
1846
1812
}
1847
1813
cmd. add_object ( & path) ;
1848
1814
}
@@ -2299,14 +2265,10 @@ fn collect_natvis_visualizers(
2299
2265
visualizer_paths. push ( visualizer_out_file) ;
2300
2266
}
2301
2267
Err ( error) => {
2302
- sess. warn (
2303
- format ! (
2304
- "Unable to write debugger visualizer file `{}`: {} " ,
2305
- visualizer_out_file. display( ) ,
2306
- error
2307
- )
2308
- . as_str ( ) ,
2309
- ) ;
2268
+ sess. emit_warning ( errors:: UnableToWriteDebuggerVisualizer {
2269
+ path : visualizer_out_file,
2270
+ error,
2271
+ } ) ;
2310
2272
}
2311
2273
} ;
2312
2274
}
@@ -2484,7 +2446,7 @@ fn add_upstream_rust_crates<'a>(
2484
2446
let rlib = & src. rlib . as_ref ( ) . unwrap ( ) . 0 ;
2485
2447
archive_builder_builder
2486
2448
. extract_bundled_libs ( rlib, tmpdir, & bundled_libs)
2487
- . unwrap_or_else ( |e| sess. fatal ( e) ) ;
2449
+ . unwrap_or_else ( |e| sess. emit_fatal ( e) ) ;
2488
2450
}
2489
2451
2490
2452
let mut last = ( None , NativeLibKind :: Unspecified , None ) ;
@@ -2641,7 +2603,7 @@ fn add_upstream_rust_crates<'a>(
2641
2603
|| !codegen_results. crate_info . is_no_builtins . contains ( & cnum) ;
2642
2604
2643
2605
let mut archive = archive_builder_builder. new_archive_builder ( sess) ;
2644
- if let Err ( e ) = archive. add_archive (
2606
+ if let Err ( error ) = archive. add_archive (
2645
2607
cratepath,
2646
2608
Box :: new ( move |f| {
2647
2609
if f == METADATA_FILENAME {
@@ -2681,7 +2643,7 @@ fn add_upstream_rust_crates<'a>(
2681
2643
false
2682
2644
} ) ,
2683
2645
) {
2684
- sess. fatal ( & format ! ( "failed to build archive from rlib: {}" , e ) ) ;
2646
+ sess. emit_fatal ( errors :: RlibArchiveBuildFailure { error } ) ;
2685
2647
}
2686
2648
if archive. build ( & dst) {
2687
2649
link_upstream ( & dst) ;
@@ -2813,14 +2775,14 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
2813
2775
( "arm" , "watchos" ) => "watchos" ,
2814
2776
( _, "macos" ) => "macosx" ,
2815
2777
_ => {
2816
- sess. err ( & format ! ( "unsupported arch `{}` for os `{}`" , arch, os) ) ;
2778
+ sess. emit_err ( errors :: UnsupportedArch { arch, os } ) ;
2817
2779
return ;
2818
2780
}
2819
2781
} ;
2820
2782
let sdk_root = match get_apple_sdk_root ( sdk_name) {
2821
2783
Ok ( s) => s,
2822
2784
Err ( e) => {
2823
- sess. err ( & e) ;
2785
+ sess. emit_err ( e) ;
2824
2786
return ;
2825
2787
}
2826
2788
} ;
@@ -2836,7 +2798,7 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
2836
2798
}
2837
2799
}
2838
2800
2839
- fn get_apple_sdk_root ( sdk_name : & str ) -> Result < String , String > {
2801
+ fn get_apple_sdk_root ( sdk_name : & str ) -> Result < String , errors :: AppleSdkRootError < ' _ > > {
2840
2802
// Following what clang does
2841
2803
// (https://github.com/llvm/llvm-project/blob/
2842
2804
// 296a80102a9b72c3eda80558fb78a3ed8849b341/clang/lib/Driver/ToolChains/Darwin.cpp#L1661-L1678)
@@ -2886,7 +2848,7 @@ fn get_apple_sdk_root(sdk_name: &str) -> Result<String, String> {
2886
2848
2887
2849
match res {
2888
2850
Ok ( output) => Ok ( output. trim ( ) . to_string ( ) ) ,
2889
- Err ( e ) => Err ( format ! ( "failed to get {} SDK path: {}" , sdk_name, e ) ) ,
2851
+ Err ( error ) => Err ( errors :: AppleSdkRootError :: SdkPath { sdk_name, error } ) ,
2890
2852
}
2891
2853
}
2892
2854
@@ -2919,7 +2881,7 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
2919
2881
}
2920
2882
}
2921
2883
} else {
2922
- sess. fatal ( "option `-Z gcc-ld` is used even though linker flavor is not gcc" ) ;
2884
+ sess. emit_fatal ( errors :: OptionGccOnly ) ;
2923
2885
}
2924
2886
}
2925
2887
}
0 commit comments