@@ -15,13 +15,14 @@ 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 , ErrorGuaranteed , FatalError } ;
18+ use rustc_errors:: { DiagCtxtHandle , ErrorGuaranteed , FatalError , LintDiagnostic } ;
1919use rustc_fs_util:: { fix_windows_verbatim_for_gcc, try_canonicalize} ;
2020use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
21- use rustc_macros:: Diagnostic ;
21+ use rustc_macros:: LintDiagnostic ;
2222use rustc_metadata:: fs:: { METADATA_FILENAME , copy_to_stdout, emit_wrapper_file} ;
2323use rustc_metadata:: { find_native_static_library, walk_native_lib_search_dirs} ;
2424use rustc_middle:: bug;
25+ use rustc_middle:: lint:: lint_level;
2526use rustc_middle:: middle:: debugger_visualizer:: DebuggerVisualizerFile ;
2627use rustc_middle:: middle:: dependency_format:: Linkage ;
2728use rustc_middle:: middle:: exported_symbols:: SymbolExportKind ;
@@ -30,6 +31,7 @@ use rustc_session::config::{
3031 OutputType , PrintKind , SplitDwarfKind , Strip ,
3132} ;
3233use rustc_session:: cstore:: DllImport ;
34+ use rustc_session:: lint:: builtin:: LINKER_MESSAGES ;
3335use rustc_session:: output:: { check_file_is_writeable, invalid_output_for_target, out_filename} ;
3436use rustc_session:: search_paths:: PathKind ;
3537use rustc_session:: utils:: NativeLibKind ;
@@ -53,7 +55,7 @@ use super::metadata::{MetadataPosition, create_wrapper_file};
5355use super :: rpath:: { self , RPathConfig } ;
5456use super :: { apple, versioned_llvm_target} ;
5557use crate :: {
56- CodegenResults , CompiledModule , CrateInfo , NativeLib , common, errors,
58+ CodegenLintLevels , CodegenResults , CompiledModule , CrateInfo , NativeLib , common, errors,
5759 looks_like_rust_object_file,
5860} ;
5961
@@ -71,6 +73,7 @@ pub fn link_binary(
7173 sess : & Session ,
7274 archive_builder_builder : & dyn ArchiveBuilderBuilder ,
7375 codegen_results : CodegenResults ,
76+ lint_levels : CodegenLintLevels ,
7477 outputs : & OutputFilenames ,
7578) -> Result < ( ) , ErrorGuaranteed > {
7679 let _timer = sess. timer ( "link_binary" ) ;
@@ -139,6 +142,7 @@ pub fn link_binary(
139142 crate_type,
140143 & out_filename,
141144 & codegen_results,
145+ lint_levels,
142146 path. as_ref ( ) ,
143147 ) ?;
144148 }
@@ -763,7 +767,7 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
763767 }
764768}
765769
766- #[ derive( Diagnostic ) ]
770+ #[ derive( LintDiagnostic ) ]
767771#[ diag( codegen_ssa_linker_output) ]
768772/// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
769773/// end up with inconsistent languages within the same diagnostic.
@@ -781,6 +785,7 @@ fn link_natively(
781785 crate_type : CrateType ,
782786 out_filename : & Path ,
783787 codegen_results : & CodegenResults ,
788+ lint_levels : CodegenLintLevels ,
784789 tmpdir : & Path ,
785790) -> Result < ( ) , ErrorGuaranteed > {
786791 info ! ( "preparing {:?} to {:?}" , crate_type, out_filename) ;
@@ -1055,6 +1060,13 @@ fn link_natively(
10551060 sess. dcx ( ) . abort_if_errors ( ) ;
10561061 }
10571062
1063+ let ( level, src) = lint_levels. linker_messages ;
1064+ let lint = |msg| {
1065+ lint_level ( sess, LINKER_MESSAGES , level, src, None , |diag| {
1066+ LinkerOutput { inner : msg } . decorate_lint ( diag)
1067+ } )
1068+ } ;
1069+
10581070 if !prog. stderr . is_empty ( ) {
10591071 // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
10601072 let stderr = escape_string ( & prog. stderr ) ;
@@ -1063,12 +1075,10 @@ fn link_natively(
10631075 . strip_prefix ( "warning: " )
10641076 . unwrap_or ( & stderr)
10651077 . replace ( ": warning: " , ": " ) ;
1066- sess . dcx ( ) . emit_warn ( LinkerOutput { inner : format ! ( "linker stderr: {stderr}" ) } ) ;
1078+ lint ( format ! ( "linker stderr: {stderr}" ) ) ;
10671079 }
10681080 if !prog. stdout . is_empty ( ) && sess. opts . verbose {
1069- sess. dcx ( ) . emit_warn ( LinkerOutput {
1070- inner : format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) ,
1071- } ) ;
1081+ lint ( format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) )
10721082 }
10731083 }
10741084 Err ( e) => {
0 commit comments