X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_hir_analysis%2Fsrc%2Flib.rs;h=bd1a461b93522235cb2b6423a48da8f0f11c4dfa;hb=c38ee06b62af10924259525c652ef29a70e98e08;hp=dba505149de87f2a3e12a85b57e460e4c772a730;hpb=b3ca68f9e9e55ee9553ed4177c5619e102f37ac3;p=rust.git diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index dba505149de..bd1a461b935 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -106,7 +106,7 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::util; -use rustc_session::config::EntryFnType; +use rustc_session::{config::EntryFnType, parse::feature_err}; use rustc_span::{symbol::sym, Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _; @@ -118,20 +118,40 @@ use bounds::Bounds; fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_>, decl: &hir::FnDecl<'_>, abi: Abi, span: Span) { - match (decl.c_variadic, abi) { - // The function has the correct calling convention, or isn't a "C-variadic" function. - (false, _) | (true, Abi::C { .. }) | (true, Abi::Cdecl { .. }) => {} - // The function is a "C-variadic" function with an incorrect calling convention. - (true, _) => { - let mut err = struct_span_err!( - tcx.sess, + const ERROR_HEAD: &str = "C-variadic function must have a compatible calling convention"; + const CONVENTIONS_UNSTABLE: &str = "`C`, `cdecl`, `win64`, `sysv64` or `efiapi`"; + const CONVENTIONS_STABLE: &str = "`C` or `cdecl`"; + const UNSTABLE_EXPLAIN: &str = + "using calling conventions other than `C` or `cdecl` for varargs functions is unstable"; + + if !decl.c_variadic || matches!(abi, Abi::C { .. } | Abi::Cdecl { .. }) { + return; + } + + 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, + + // 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.parse_sess, + sym::extended_varargs_abi_support, span, - E0045, - "C-variadic function must have C or cdecl calling convention" - ); - err.span_label(span, "C-variadics require C or cdecl calling convention").emit(); + UNSTABLE_EXPLAIN, + ) + .emit(); + CONVENTIONS_STABLE } - } + + (false, false) => CONVENTIONS_STABLE, + (true, false) => CONVENTIONS_UNSTABLE, + }; + + let mut err = struct_span_err!(tcx.sess, span, E0045, "{}, like {}", ERROR_HEAD, conventions); + err.span_label(span, ERROR_HEAD).emit(); } fn require_same_types<'tcx>( @@ -381,7 +401,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) { error = true; } if let hir::IsAsync::Async = sig.header.asyncness { - let span = tcx.def_span(it.def_id); + let span = tcx.def_span(it.owner_id); struct_span_err!( tcx.sess, span,