@@ -15,13 +15,14 @@ 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 ;
18
+ use rustc_errors:: { DiagCtxtHandle , LintDiagnostic } ;
19
19
use rustc_fs_util:: { fix_windows_verbatim_for_gcc, try_canonicalize} ;
20
20
use rustc_hir:: def_id:: { CrateNum , LOCAL_CRATE } ;
21
- use rustc_macros:: Diagnostic ;
21
+ use rustc_macros:: LintDiagnostic ;
22
22
use rustc_metadata:: fs:: { METADATA_FILENAME , copy_to_stdout, emit_wrapper_file} ;
23
23
use rustc_metadata:: { find_native_static_library, walk_native_lib_search_dirs} ;
24
24
use rustc_middle:: bug;
25
+ use rustc_middle:: lint:: lint_level;
25
26
use rustc_middle:: middle:: debugger_visualizer:: DebuggerVisualizerFile ;
26
27
use rustc_middle:: middle:: dependency_format:: Linkage ;
27
28
use rustc_middle:: middle:: exported_symbols:: SymbolExportKind ;
@@ -30,6 +31,7 @@ use rustc_session::config::{
30
31
OutputType , PrintKind , SplitDwarfKind , Strip ,
31
32
} ;
32
33
use rustc_session:: cstore:: DllImport ;
34
+ use rustc_session:: lint:: builtin:: LINKER_MESSAGES ;
33
35
use rustc_session:: output:: { check_file_is_writeable, invalid_output_for_target, out_filename} ;
34
36
use rustc_session:: search_paths:: PathKind ;
35
37
use rustc_session:: utils:: NativeLibKind ;
@@ -750,7 +752,7 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
750
752
}
751
753
}
752
754
753
- #[ derive( Diagnostic ) ]
755
+ #[ derive( LintDiagnostic ) ]
754
756
#[ diag( codegen_ssa_linker_output) ]
755
757
/// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
756
758
/// end up with inconsistent languages within the same diagnostic.
@@ -1038,6 +1040,13 @@ fn link_natively(
1038
1040
sess. dcx ( ) . abort_if_errors ( ) ;
1039
1041
}
1040
1042
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
+
1041
1050
if !prog. stderr . is_empty ( ) {
1042
1051
// We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.
1043
1052
let stderr = escape_string ( & prog. stderr ) ;
@@ -1046,12 +1055,10 @@ fn link_natively(
1046
1055
. strip_prefix ( "warning: " )
1047
1056
. unwrap_or ( & stderr)
1048
1057
. replace ( ": warning: " , ": " ) ;
1049
- sess . dcx ( ) . emit_warn ( LinkerOutput { inner : format ! ( "linker stderr: {stderr}" ) } ) ;
1058
+ lint ( format ! ( "linker stderr: {stderr}" ) ) ;
1050
1059
}
1051
1060
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) ) )
1055
1062
}
1056
1063
}
1057
1064
Err ( e) => {
0 commit comments