@@ -90,7 +90,7 @@ mod outlives;
90
90
mod variance;
91
91
92
92
pub use errors:: NoVariantNamed ;
93
- use rustc_abi:: ExternAbi ;
93
+ use rustc_abi:: { CVariadicStatus , ExternAbi } ;
94
94
use rustc_hir:: def:: DefKind ;
95
95
use rustc_hir:: lints:: DelayedLint ;
96
96
use rustc_hir:: { self as hir} ;
@@ -99,7 +99,6 @@ use rustc_middle::mir::interpret::GlobalId;
99
99
use rustc_middle:: query:: Providers ;
100
100
use rustc_middle:: ty:: { self , Const , Ty , TyCtxt } ;
101
101
use rustc_session:: parse:: feature_err;
102
- use rustc_span:: symbol:: sym;
103
102
use rustc_span:: { ErrorGuaranteed , Span } ;
104
103
use rustc_trait_selection:: traits;
105
104
@@ -108,46 +107,34 @@ use crate::hir_ty_lowering::{FeedConstTy, HirTyLowerer};
108
107
109
108
rustc_fluent_macro:: fluent_messages! { "../messages.ftl" }
110
109
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.
119
113
return ;
120
114
}
121
115
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 ( ) ;
141
125
}
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
+ }
144
136
}
145
- _ => tcx. dcx ( ) . create_err ( errors:: VariadicFunctionCompatibleConvention {
146
- span,
147
- convention : & format ! ( "{abi}" ) ,
148
- } ) ,
149
137
}
150
- . emit ( ) ;
151
138
}
152
139
153
140
/// Adds query implementations to the [Providers] vtable, see [`rustc_middle::query`]
0 commit comments