@@ -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 ;
18+ use rustc_errors:: { DiagCtxtHandle , 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 ;
@@ -750,7 +752,7 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
750752 }
751753}
752754
753- #[ derive( Diagnostic ) ]
755+ #[ derive( LintDiagnostic ) ]
754756#[ diag( codegen_ssa_linker_output) ]
755757/// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
756758/// end up with inconsistent languages within the same diagnostic.
@@ -1038,6 +1040,13 @@ fn link_natively(
10381040 sess. dcx ( ) . abort_if_errors ( ) ;
10391041 }
10401042
1043+ let ( level, src) = codegen_results. crate_info . lint_levels . linker_messages ;
1044+ let lint = |msg| {
1045+ lint_level ( sess, LINKER_MESSAGES , level, src, None , |diag| {
1046+ LinkerOutput { inner : msg } . decorate_lint ( diag)
1047+ } )
1048+ } ;
1049+
10411050 if !prog. stderr . is_empty ( ) {
10421051 // We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
10431052 let stderr = escape_string ( & prog. stderr ) ;
@@ -1046,12 +1055,10 @@ fn link_natively(
10461055 . strip_prefix ( "warning: " )
10471056 . unwrap_or ( & stderr)
10481057 . replace ( ": warning: " , ": " ) ;
1049- sess . dcx ( ) . emit_warn ( LinkerOutput { inner : format ! ( "linker stderr: {stderr}" ) } ) ;
1058+ lint ( format ! ( "linker stderr: {stderr}" ) ) ;
10501059 }
10511060 if !prog. stdout . is_empty ( ) && sess. opts . verbose {
1052- sess. dcx ( ) . emit_warn ( LinkerOutput {
1053- inner : format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) ,
1054- } ) ;
1061+ lint ( format ! ( "linker stdout: {}" , escape_string( & prog. stdout) ) )
10551062 }
10561063 }
10571064 Err ( e) => {
0 commit comments