@@ -116,49 +116,42 @@ fn require_c_abi_if_c_variadic(
116
116
abi : ExternAbi ,
117
117
span : Span ,
118
118
) {
119
- const CONVENTIONS_UNSTABLE : & str =
120
- "`C`, `cdecl`, `system`, `aapcs`, `win64`, `sysv64` or `efiapi`" ;
121
119
const CONVENTIONS_STABLE : & str = "`C` or `cdecl`" ;
122
120
const UNSTABLE_EXPLAIN : & str =
123
121
"using calling conventions other than `C` or `cdecl` for varargs functions is unstable" ;
124
122
123
+ // ABIs which can stably use varargs
125
124
if !decl. c_variadic || matches ! ( abi, ExternAbi :: C { .. } | ExternAbi :: Cdecl { .. } ) {
126
125
return ;
127
126
}
128
127
128
+ // ABIs with feature-gated stability
129
129
let extended_abi_support = tcx. features ( ) . extended_varargs_abi_support ( ) ;
130
130
let extern_system_varargs = tcx. features ( ) . extern_system_varargs ( ) ;
131
- let conventions = if extended_abi_support { CONVENTIONS_UNSTABLE } else { CONVENTIONS_STABLE } ;
131
+
132
+ // If the feature gate has been enabled, we can stop here
133
+ if extern_system_varargs && let ExternAbi :: System { .. } = abi {
134
+ return ;
135
+ } ;
136
+ if extended_abi_support && abi. supports_varargs ( ) {
137
+ return ;
138
+ } ;
139
+
140
+ // Looks like we need to pick an error to emit.
141
+ // Is there any feature which we could have enabled to make this work?
132
142
match abi {
133
143
ExternAbi :: System { .. } => {
134
- // User enabled additional ABI support for varargs and function ABI matches those ones.
135
- if extern_system_varargs {
136
- return ;
137
- } else {
138
- // Using this ABI would be ok, if the feature for additional ABI support was enabled.
139
- feature_err ( & tcx. sess , sym:: extern_system_varargs, span, UNSTABLE_EXPLAIN ) . emit ( ) ;
140
- }
144
+ feature_err ( & tcx. sess , sym:: extern_system_varargs, span, UNSTABLE_EXPLAIN )
141
145
}
142
- abi => {
143
- if abi. supports_varargs ( ) {
144
- // User enabled additional ABI support for varargs and function ABI matches those ones.
145
- if extended_abi_support {
146
- return ;
147
- } else {
148
- // Using this ABI would be ok, if the feature for additional ABI support was enabled.
149
- feature_err (
150
- & tcx. sess ,
151
- sym:: extended_varargs_abi_support,
152
- span,
153
- UNSTABLE_EXPLAIN ,
154
- )
155
- . emit ( ) ;
156
- } ;
157
- }
146
+ abi if abi. supports_varargs ( ) => {
147
+ feature_err ( & tcx. sess , sym:: extended_varargs_abi_support, span, UNSTABLE_EXPLAIN )
158
148
}
159
- } ;
160
-
161
- tcx. dcx ( ) . emit_err ( errors:: VariadicFunctionCompatibleConvention { span, conventions } ) ;
149
+ _ => tcx. dcx ( ) . create_err ( errors:: VariadicFunctionCompatibleConvention {
150
+ span,
151
+ conventions : CONVENTIONS_STABLE ,
152
+ } ) ,
153
+ }
154
+ . emit ( ) ;
162
155
}
163
156
164
157
pub fn provide ( providers : & mut Providers ) {
0 commit comments