@@ -90,7 +90,7 @@ mod outlives;
9090mod variance;
9191
9292pub use errors:: NoVariantNamed ;
93- use rustc_abi:: ExternAbi ;
93+ use rustc_abi:: { CVariadicStatus , ExternAbi } ;
9494use rustc_hir:: def:: DefKind ;
9595use rustc_hir:: lints:: DelayedLint ;
9696use rustc_hir:: { self as hir} ;
@@ -99,7 +99,6 @@ use rustc_middle::mir::interpret::GlobalId;
9999use rustc_middle:: query:: Providers ;
100100use rustc_middle:: ty:: { self , Const , Ty , TyCtxt } ;
101101use rustc_session:: parse:: feature_err;
102- use rustc_span:: symbol:: sym;
103102use rustc_span:: { ErrorGuaranteed , Span } ;
104103use rustc_trait_selection:: traits;
105104
@@ -108,46 +107,34 @@ use crate::hir_ty_lowering::{FeedConstTy, HirTyLowerer};
108107
109108rustc_fluent_macro:: fluent_messages! { "../messages.ftl" }
110109
111- fn require_c_abi_if_c_variadic (
112- tcx : TyCtxt < ' _ > ,
113- decl : & hir:: FnDecl < ' _ > ,
114- abi : ExternAbi ,
115- span : Span ,
116- ) {
117- // ABIs which can stably use varargs
118- if !decl. c_variadic || matches ! ( abi, ExternAbi :: C { .. } | ExternAbi :: Cdecl { .. } ) {
110+ fn check_c_variadic_abi ( tcx : TyCtxt < ' _ > , decl : & hir:: FnDecl < ' _ > , abi : ExternAbi , span : Span ) {
111+ if !decl. c_variadic {
112+ // Not even a variadic function.
119113 return ;
120114 }
121115
122- // ABIs with feature-gated stability
123- let extended_abi_support = tcx. features ( ) . extended_varargs_abi_support ( ) ;
124- let extern_system_varargs = tcx. features ( ) . extern_system_varargs ( ) ;
125-
126- // If the feature gate has been enabled, we can stop here
127- if extern_system_varargs && let ExternAbi :: System { .. } = abi {
128- return ;
129- } ;
130- if extended_abi_support && abi. supports_varargs ( ) {
131- return ;
132- } ;
133-
134- // Looks like we need to pick an error to emit.
135- // Is there any feature which we could have enabled to make this work?
136- let unstable_explain =
137- format ! ( "C-variadic functions with the {abi} calling convention are unstable" ) ;
138- match abi {
139- ExternAbi :: System { .. } => {
140- feature_err ( & tcx. sess , sym:: extern_system_varargs, span, unstable_explain)
116+ match abi. supports_c_variadic ( ) {
117+ CVariadicStatus :: Stable => { }
118+ CVariadicStatus :: NotSupported => {
119+ tcx. dcx ( )
120+ . create_err ( errors:: VariadicFunctionCompatibleConvention {
121+ span,
122+ convention : & format ! ( "{abi}" ) ,
123+ } )
124+ . emit ( ) ;
141125 }
142- abi if abi. supports_varargs ( ) => {
143- feature_err ( & tcx. sess , sym:: extended_varargs_abi_support, span, unstable_explain)
126+ CVariadicStatus :: Unstable { feature } => {
127+ if !tcx. features ( ) . enabled ( feature) {
128+ feature_err (
129+ & tcx. sess ,
130+ feature,
131+ span,
132+ format ! ( "C-variadic functions with the {abi} calling convention are unstable" ) ,
133+ )
134+ . emit ( ) ;
135+ }
144136 }
145- _ => tcx. dcx ( ) . create_err ( errors:: VariadicFunctionCompatibleConvention {
146- span,
147- convention : & format ! ( "{abi}" ) ,
148- } ) ,
149137 }
150- . emit ( ) ;
151138}
152139
153140/// Adds query implementations to the [Providers] vtable, see [`rustc_middle::query`]
0 commit comments