@@ -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,21 +1063,21 @@ 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:: StrippingDebuInfoFailed {
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
1107
1077
fn escape_string ( s : & [ u8 ] ) -> String {
1108
1078
match str:: from_utf8 ( s) {
1109
1079
Ok ( s) => s. to_owned ( ) ,
1080
+ // FIXME: return a type that can conform to IntoDiagnosticArg
1110
1081
Err ( _) => format ! ( "Non-UTF-8 output: {}" , s. escape_ascii( ) ) ,
1111
1082
}
1112
1083
}
@@ -1251,7 +1222,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
1251
1222
) ) ,
1252
1223
( Some ( linker) , None ) => {
1253
1224
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" )
1225
+ sess. emit_fatal ( errors :: LinkerFileStem ) ;
1255
1226
} ) ;
1256
1227
1257
1228
let flavor = if stem == "emcc" {
@@ -1378,13 +1349,9 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
1378
1349
} )
1379
1350
. collect ( ) ;
1380
1351
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
- ) ;
1352
+ sess. emit_note ( errors:: StaticLibraryNativeArtifacts ) ;
1386
1353
// Prefix for greppability
1387
- sess. note_without_error ( & format ! ( "native-static-libs: {}" , & lib_args. join( " " ) ) ) ;
1354
+ sess. emit_note ( errors :: NativeStaticLibs { arguments : lib_args. join ( " " ) } ) ;
1388
1355
}
1389
1356
}
1390
1357
@@ -1688,14 +1655,14 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty
1688
1655
match ( crate_type, & sess. target . link_script ) {
1689
1656
( CrateType :: Cdylib | CrateType :: Executable , Some ( script) ) => {
1690
1657
if !sess. target . linker_flavor . is_gnu ( ) {
1691
- sess. fatal ( "can only use link script when linking with GNU-like linker" ) ;
1658
+ sess. emit_fatal ( errors :: LinkScriptUnavailable ) ;
1692
1659
}
1693
1660
1694
1661
let file_name = [ "rustc" , & sess. target . llvm_target , "linkfile.ld" ] . join ( "-" ) ;
1695
1662
1696
1663
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 ) ) ;
1664
+ if let Err ( error ) = fs:: write ( & path, script. as_ref ( ) ) {
1665
+ sess. emit_fatal ( errors :: LinkScriptWriteFailure { path, error } ) ;
1699
1666
}
1700
1667
1701
1668
cmd. arg ( "--script" ) ;
@@ -1841,8 +1808,8 @@ fn add_linked_symbol_object(
1841
1808
1842
1809
let path = tmpdir. join ( "symbols.o" ) ;
1843
1810
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 ) ) ;
1811
+ if let Err ( error ) = result {
1812
+ sess. emit_fatal ( errors :: FailedToWrite { path, error } ) ;
1846
1813
}
1847
1814
cmd. add_object ( & path) ;
1848
1815
}
@@ -2299,14 +2266,10 @@ fn collect_natvis_visualizers(
2299
2266
visualizer_paths. push ( visualizer_out_file) ;
2300
2267
}
2301
2268
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
- ) ;
2269
+ sess. emit_warning ( errors:: UnableToWriteDebuggerVisualizer {
2270
+ path : visualizer_out_file,
2271
+ error,
2272
+ } ) ;
2310
2273
}
2311
2274
} ;
2312
2275
}
@@ -2641,7 +2604,7 @@ fn add_upstream_rust_crates<'a>(
2641
2604
|| !codegen_results. crate_info . is_no_builtins . contains ( & cnum) ;
2642
2605
2643
2606
let mut archive = archive_builder_builder. new_archive_builder ( sess) ;
2644
- if let Err ( e ) = archive. add_archive (
2607
+ if let Err ( error ) = archive. add_archive (
2645
2608
cratepath,
2646
2609
Box :: new ( move |f| {
2647
2610
if f == METADATA_FILENAME {
@@ -2681,7 +2644,7 @@ fn add_upstream_rust_crates<'a>(
2681
2644
false
2682
2645
} ) ,
2683
2646
) {
2684
- sess. fatal ( & format ! ( "failed to build archive from rlib: {}" , e ) ) ;
2647
+ sess. emit_fatal ( errors :: RlibArchiveBuildFailure { error } ) ;
2685
2648
}
2686
2649
if archive. build ( & dst) {
2687
2650
link_upstream ( & dst) ;
@@ -2919,7 +2882,7 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
2919
2882
}
2920
2883
}
2921
2884
} else {
2922
- sess. fatal ( "option `-Z gcc-ld` is used even though linker flavor is not gcc" ) ;
2885
+ sess. emit_fatal ( errors :: OptionGccOnly ) ;
2923
2886
}
2924
2887
}
2925
2888
}
0 commit comments