@@ -37,22 +37,23 @@ use {rustc_attr_data_structures as attrs, rustc_hir as hir};
3737use super :: compare_impl_item:: check_type_bounds;
3838use super :: * ;
3939
40+ fn add_abi_diag_help < T : EmissionGuarantee > ( abi : ExternAbi , diag : & mut Diag < ' _ , T > ) {
41+ if let ExternAbi :: Cdecl { unwind } = abi {
42+ let c_abi = ExternAbi :: C { unwind } ;
43+ diag. help ( format ! ( "use `extern {c_abi}` instead" , ) ) ;
44+ } else if let ExternAbi :: Stdcall { unwind } = abi {
45+ let c_abi = ExternAbi :: C { unwind } ;
46+ let system_abi = ExternAbi :: System { unwind } ;
47+ diag. help ( format ! (
48+ "if you need `extern {abi}` on win32 and `extern {c_abi}` everywhere else, \
49+ use `extern {system_abi}`"
50+ ) ) ;
51+ }
52+ }
53+
4054pub fn check_abi ( tcx : TyCtxt < ' _ > , hir_id : hir:: HirId , span : Span , abi : ExternAbi ) {
4155 // FIXME: this should be checked earlier, e.g. in `rustc_ast_lowering`, to fix
4256 // things like #86232.
43- fn add_help < T : EmissionGuarantee > ( abi : ExternAbi , diag : & mut Diag < ' _ , T > ) {
44- if let ExternAbi :: Cdecl { unwind } = abi {
45- let c_abi = ExternAbi :: C { unwind } ;
46- diag. help ( format ! ( "use `extern {c_abi}` instead" , ) ) ;
47- } else if let ExternAbi :: Stdcall { unwind } = abi {
48- let c_abi = ExternAbi :: C { unwind } ;
49- let system_abi = ExternAbi :: System { unwind } ;
50- diag. help ( format ! (
51- "if you need `extern {abi}` on win32 and `extern {c_abi}` everywhere else, \
52- use `extern {system_abi}`"
53- ) ) ;
54- }
55- }
5657
5758 match AbiMap :: from_target ( & tcx. sess . target ) . canonize_abi ( abi, false ) {
5859 AbiMapping :: Direct ( ..) => ( ) ,
@@ -63,13 +64,13 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi
6364 E0570 ,
6465 "`{abi}` is not a supported ABI for the current target" ,
6566 ) ;
66- add_help ( abi, & mut err) ;
67+ add_abi_diag_help ( abi, & mut err) ;
6768 err. emit ( ) ;
6869 }
6970 AbiMapping :: Deprecated ( ..) => {
7071 tcx. node_span_lint ( UNSUPPORTED_CALLING_CONVENTIONS , hir_id, span, |lint| {
7172 lint. primary_message ( "use of calling convention not supported on this target" ) ;
72- add_help ( abi, lint) ;
73+ add_abi_diag_help ( abi, lint) ;
7374 } ) ;
7475 }
7576 }
@@ -80,7 +81,14 @@ pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Ex
8081 // in `check_abi` above.
8182 match AbiMap :: from_target ( & tcx. sess . target ) . canonize_abi ( abi, false ) {
8283 AbiMapping :: Direct ( ..) => ( ) ,
83- AbiMapping :: Deprecated ( ..) | AbiMapping :: Invalid => {
84+ // this is not a redundant match arm: these ABIs started linting after reviving this lint
85+ AbiMapping :: Deprecated ( ..) => {
86+ tcx. node_span_lint ( UNSUPPORTED_CALLING_CONVENTIONS , hir_id, span, |lint| {
87+ lint. primary_message ( "use of calling convention not supported on this target" ) ;
88+ add_abi_diag_help ( abi, lint) ;
89+ } ) ;
90+ }
91+ AbiMapping :: Invalid => {
8492 tcx. node_span_lint ( UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS , hir_id, span, |lint| {
8593 lint. primary_message ( format ! (
8694 "the calling convention {abi} is not supported on this target"
0 commit comments