@@ -37,22 +37,23 @@ use {rustc_attr_data_structures as attrs, rustc_hir as hir};
37
37
use super :: compare_impl_item:: check_type_bounds;
38
38
use super :: * ;
39
39
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
+
40
54
pub fn check_abi ( tcx : TyCtxt < ' _ > , hir_id : hir:: HirId , span : Span , abi : ExternAbi ) {
41
55
// FIXME: this should be checked earlier, e.g. in `rustc_ast_lowering`, to fix
42
56
// 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
- }
56
57
57
58
match AbiMap :: from_target ( & tcx. sess . target ) . canonize_abi ( abi, false ) {
58
59
AbiMapping :: Direct ( ..) => ( ) ,
@@ -63,13 +64,13 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: ExternAbi
63
64
E0570 ,
64
65
"`{abi}` is not a supported ABI for the current target" ,
65
66
) ;
66
- add_help ( abi, & mut err) ;
67
+ add_abi_diag_help ( abi, & mut err) ;
67
68
err. emit ( ) ;
68
69
}
69
70
AbiMapping :: Deprecated ( ..) => {
70
71
tcx. node_span_lint ( UNSUPPORTED_CALLING_CONVENTIONS , hir_id, span, |lint| {
71
72
lint. primary_message ( "use of calling convention not supported on this target" ) ;
72
- add_help ( abi, lint) ;
73
+ add_abi_diag_help ( abi, lint) ;
73
74
} ) ;
74
75
}
75
76
}
@@ -80,7 +81,14 @@ pub fn check_abi_fn_ptr(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Ex
80
81
// in `check_abi` above.
81
82
match AbiMap :: from_target ( & tcx. sess . target ) . canonize_abi ( abi, false ) {
82
83
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 => {
84
92
tcx. node_span_lint ( UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS , hir_id, span, |lint| {
85
93
lint. primary_message ( format ! (
86
94
"the calling convention {abi} is not supported on this target"
0 commit comments