@@ -11,7 +11,8 @@ use rustc_hir::{LangItem, Node, intravisit};
11
11
use rustc_infer:: infer:: { RegionVariableOrigin , TyCtxtInferExt } ;
12
12
use rustc_infer:: traits:: { Obligation , ObligationCauseCode } ;
13
13
use rustc_lint_defs:: builtin:: {
14
- REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS , UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS ,
14
+ REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS , UNSUPPORTED_CALLING_CONVENTIONS ,
15
+ UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS ,
15
16
} ;
16
17
use rustc_middle:: hir:: nested_filter;
17
18
use rustc_middle:: middle:: resolve_bound_vars:: ResolvedArg ;
@@ -24,6 +25,7 @@ use rustc_middle::ty::{
24
25
TypeVisitable , TypeVisitableExt , fold_regions,
25
26
} ;
26
27
use rustc_session:: lint:: builtin:: UNINHABITED_STATIC ;
28
+ use rustc_target:: spec:: { AbiMap , AbiMapping } ;
27
29
use rustc_trait_selection:: error_reporting:: InferCtxtErrorExt ;
28
30
use rustc_trait_selection:: error_reporting:: traits:: on_unimplemented:: OnUnimplementedDirective ;
29
31
use rustc_trait_selection:: traits;
@@ -35,25 +37,38 @@ use {rustc_attr_data_structures as attrs, rustc_hir as hir};
35
37
use super :: compare_impl_item:: check_type_bounds;
36
38
use super :: * ;
37
39
38
- pub fn check_abi ( tcx : TyCtxt < ' _ > , span : Span , abi : ExternAbi ) {
39
- if !tcx. sess . target . is_abi_supported ( abi) {
40
- struct_span_code_err ! (
41
- tcx. dcx( ) ,
42
- span,
43
- E0570 ,
44
- "`{abi}` is not a supported ABI for the current target" ,
45
- )
46
- . emit ( ) ;
40
+ pub fn check_abi ( tcx : TyCtxt < ' _ > , hir_id : hir:: HirId , span : Span , abi : ExternAbi ) {
41
+ match AbiMap :: from_target ( & tcx. sess . target ) . canonize_abi ( abi, false ) {
42
+ AbiMapping :: Direct ( ..) => ( ) ,
43
+ AbiMapping :: Invalid => {
44
+ struct_span_code_err ! (
45
+ tcx. dcx( ) ,
46
+ span,
47
+ E0570 ,
48
+ "`{abi}` is not a supported ABI for the current target" ,
49
+ )
50
+ . emit ( ) ;
51
+ }
52
+ AbiMapping :: Deprecated ( ..) => {
53
+ tcx. node_span_lint ( UNSUPPORTED_CALLING_CONVENTIONS , hir_id, span, |lint| {
54
+ lint. primary_message ( "use of calling convention not supported on this target" ) ;
55
+ } ) ;
56
+ }
47
57
}
48
58
}
49
59
50
60
pub fn check_abi_fn_ptr ( tcx : TyCtxt < ' _ > , hir_id : hir:: HirId , span : Span , abi : ExternAbi ) {
51
- if !tcx. sess . target . is_abi_supported ( abi) {
52
- tcx. node_span_lint ( UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS , hir_id, span, |lint| {
53
- lint. primary_message ( format ! (
54
- "the calling convention {abi} is not supported on this target"
55
- ) ) ;
56
- } ) ;
61
+ // This is always an FCW, even for `AbiMapping::Invalid`, since we started linting later than
62
+ // in `check_abi` above.
63
+ match AbiMap :: from_target ( & tcx. sess . target ) . canonize_abi ( abi, false ) {
64
+ AbiMapping :: Direct ( ..) => ( ) ,
65
+ AbiMapping :: Deprecated ( ..) | AbiMapping :: Invalid => {
66
+ tcx. node_span_lint ( UNSUPPORTED_FN_PTR_CALLING_CONVENTIONS , hir_id, span, |lint| {
67
+ lint. primary_message ( format ! (
68
+ "the calling convention {abi} is not supported on this target"
69
+ ) ) ;
70
+ } ) ;
71
+ }
57
72
}
58
73
}
59
74
@@ -779,7 +794,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
779
794
let hir:: ItemKind :: ForeignMod { abi, items } = it. kind else {
780
795
return ;
781
796
} ;
782
- check_abi ( tcx, it. span , abi) ;
797
+ check_abi ( tcx, it. hir_id ( ) , it . span , abi) ;
783
798
784
799
for item in items {
785
800
let def_id = item. id . owner_id . def_id ;
0 commit comments