diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-02-13 03:53:32 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-13 03:53:32 -0500 |
| commit | 36d37966dff8b52653d153d446048c8cb2f84e68 (patch) | |
| tree | e2927edd1a63602c7603b647ce99ceb97e9e83c7 /compiler/rustc_hir_analysis | |
| parent | 6fbca256275eb9ba5d8a804cf5825c501df06cbc (diff) | |
| parent | 4bb0c3da2c1397034a5036b73bc78369b719f593 (diff) | |
| download | rust-36d37966dff8b52653d153d446048c8cb2f84e68.tar.gz rust-36d37966dff8b52653d153d446048c8cb2f84e68.zip | |
Rollup merge of #136948 - workingjubilee:split-off-extern-system-varargs, r=compiler-errors
Split out the `extern_system_varargs` feature After the stabilization PR was opened, `extern "system"` functions were added to `extended_varargs_abi_support`. This has a number of questions regarding it that were not discussed and were somewhat surprising. It deserves to be considered as its own feature, separate from `extended_varargs_abi_support`. Tracking issue: - https://github.com/rust-lang/rust/issues/136946
Diffstat (limited to 'compiler/rustc_hir_analysis')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/lib.rs | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 323b912ca18..8a529e9c686 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -122,28 +122,42 @@ fn require_c_abi_if_c_variadic( const UNSTABLE_EXPLAIN: &str = "using calling conventions other than `C` or `cdecl` for varargs functions is unstable"; + // ABIs which can stably use varargs if !decl.c_variadic || matches!(abi, ExternAbi::C { .. } | ExternAbi::Cdecl { .. }) { return; } + // ABIs with feature-gated stability let extended_abi_support = tcx.features().extended_varargs_abi_support(); - let conventions = match (extended_abi_support, abi.supports_varargs()) { - // User enabled additional ABI support for varargs and function ABI matches those ones. - (true, true) => return, + let extern_system_varargs = tcx.features().extern_system_varargs(); - // Using this ABI would be ok, if the feature for additional ABI support was enabled. - // Return CONVENTIONS_STABLE, because we want the other error to look the same. - (false, true) => { - feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, UNSTABLE_EXPLAIN) - .emit(); - CONVENTIONS_STABLE - } - - (false, false) => CONVENTIONS_STABLE, - (true, false) => CONVENTIONS_UNSTABLE, + // If the feature gate has been enabled, we can stop here + if extern_system_varargs && let ExternAbi::System { .. } = abi { + return; + }; + if extended_abi_support && abi.supports_varargs() { + return; }; - tcx.dcx().emit_err(errors::VariadicFunctionCompatibleConvention { span, conventions }); + // Looks like we need to pick an error to emit. + // Is there any feature which we could have enabled to make this work? + match abi { + ExternAbi::System { .. } => { + feature_err(&tcx.sess, sym::extern_system_varargs, span, UNSTABLE_EXPLAIN) + } + abi if abi.supports_varargs() => { + feature_err(&tcx.sess, sym::extended_varargs_abi_support, span, UNSTABLE_EXPLAIN) + } + _ => tcx.dcx().create_err(errors::VariadicFunctionCompatibleConvention { + span, + conventions: if tcx.sess.opts.unstable_features.is_nightly_build() { + CONVENTIONS_UNSTABLE + } else { + CONVENTIONS_STABLE + }, + }), + } + .emit(); } pub fn provide(providers: &mut Providers) { |
