1
Fork 0

Rename variadic to c_variadic

Function signatures with the `variadic` member set are actually
C-variadic functions. Make this a little more explicit by renaming the
`variadic` boolean value, `c_variadic`.
This commit is contained in:
Dan Robertson 2019-02-08 17:30:42 +00:00
parent a618ad6335
commit 08bd4ff998
No known key found for this signature in database
GPG key ID: 4DE6EEF84B5C9783
43 changed files with 119 additions and 119 deletions

View file

@ -954,7 +954,7 @@ impl<'a> LoweringContext<'a> {
let decl = FnDecl {
inputs: vec![],
output,
variadic: false
c_variadic: false
};
let body_id = self.record_body(body_expr, Some(&decl));
self.is_generator = prev_is_generator;
@ -2118,7 +2118,7 @@ impl<'a> LoweringContext<'a> {
P(hir::FnDecl {
inputs,
output,
variadic: decl.variadic,
c_variadic: decl.c_variadic,
implicit_self: decl.inputs.get(0).map_or(
hir::ImplicitSelfKind::None,
|arg| {
@ -3973,7 +3973,7 @@ impl<'a> LoweringContext<'a> {
let outer_decl = FnDecl {
inputs: decl.inputs.clone(),
output: FunctionRetTy::Default(fn_decl_span),
variadic: false,
c_variadic: false,
};
// We need to lower the declaration outside the new scope, because we
// have to conserve the state of being inside a loop condition for the

View file

@ -1868,7 +1868,7 @@ pub struct Arg {
pub struct FnDecl {
pub inputs: HirVec<Ty>,
pub output: FunctionRetTy,
pub variadic: bool,
pub c_variadic: bool,
/// Does the function have an implicit self?
pub implicit_self: ImplicitSelfKind,
}

View file

@ -2007,7 +2007,7 @@ impl<'a> State<'a> {
s.print_type(ty)?;
s.end()
})?;
if decl.variadic {
if decl.c_variadic {
self.s.word(", ...")?;
}
self.pclose()?;

View file

@ -368,7 +368,7 @@ impl_stable_hash_for!(enum hir::TyKind {
impl_stable_hash_for!(struct hir::FnDecl {
inputs,
output,
variadic,
c_variadic,
implicit_self
});

View file

@ -232,7 +232,7 @@ impl_stable_hash_for!(struct ty::GenSig<'tcx> {
impl_stable_hash_for!(struct ty::FnSig<'tcx> {
inputs_and_output,
variadic,
c_variadic,
unsafety,
abi
});

View file

@ -1944,7 +1944,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
if let ty::FnSig {
unsafety: hir::Unsafety::Normal,
abi: Abi::Rust,
variadic: false,
c_variadic: false,
..
} = self_ty.fn_sig(self.tcx()).skip_binder()
{

View file

@ -2453,7 +2453,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.mk_fn_sig(
params_iter,
s.output(),
s.variadic,
s.c_variadic,
hir::Unsafety::Normal,
abi::Abi::Rust,
)
@ -2779,7 +2779,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
pub fn mk_fn_sig<I>(self,
inputs: I,
output: I::Item,
variadic: bool,
c_variadic: bool,
unsafety: hir::Unsafety,
abi: abi::Abi)
-> <I::Item as InternIteratorElement<Ty<'tcx>, ty::FnSig<'tcx>>>::Output
@ -2788,7 +2788,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
{
inputs.chain(iter::once(output)).intern_with(|xs| ty::FnSig {
inputs_and_output: self.intern_type_list(xs),
variadic, unsafety, abi
c_variadic, unsafety, abi
})
}

View file

@ -65,7 +65,7 @@ impl<'a, 'tcx> Instance<'tcx> {
sig.map_bound(|sig| tcx.mk_fn_sig(
iter::once(*env_ty.skip_binder()).chain(sig.inputs().iter().cloned()),
sig.output(),
sig.variadic,
sig.c_variadic,
sig.unsafety,
sig.abi
))

View file

@ -147,9 +147,9 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
{
let tcx = relation.tcx();
if a.variadic != b.variadic {
if a.c_variadic != b.c_variadic {
return Err(TypeError::VariadicMismatch(
expected_found(relation, &a.variadic, &b.variadic)));
expected_found(relation, &a.c_variadic, &b.c_variadic)));
}
let unsafety = relation.relate(&a.unsafety, &b.unsafety)?;
let abi = relation.relate(&a.abi, &b.abi)?;
@ -171,7 +171,7 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> {
});
Ok(ty::FnSig {
inputs_and_output: tcx.mk_type_list(inputs_and_output)?,
variadic: a.variadic,
c_variadic: a.c_variadic,
unsafety,
abi,
})

View file

@ -396,7 +396,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> {
tcx.lift(&self.inputs_and_output).map(|x| {
ty::FnSig {
inputs_and_output: x,
variadic: self.variadic,
c_variadic: self.c_variadic,
unsafety: self.unsafety,
abi: self.abi,
}
@ -832,7 +832,7 @@ BraceStructTypeFoldableImpl! {
BraceStructTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> {
inputs_and_output, variadic, unsafety, abi
inputs_and_output, c_variadic, unsafety, abi
}
}

View file

@ -979,11 +979,11 @@ impl<'tcx> PolyGenSig<'tcx> {
///
/// - `inputs`: is the list of arguments and their modes.
/// - `output`: is the return type.
/// - `variadic`: indicates whether this is a C-variadic function.
/// - `c_variadic`: indicates whether this is a C-variadic function.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
pub struct FnSig<'tcx> {
pub inputs_and_output: &'tcx List<Ty<'tcx>>,
pub variadic: bool,
pub c_variadic: bool,
pub unsafety: hir::Unsafety,
pub abi: abi::Abi,
}
@ -1016,8 +1016,8 @@ impl<'tcx> PolyFnSig<'tcx> {
pub fn output(&self) -> ty::Binder<Ty<'tcx>> {
self.map_bound_ref(|fn_sig| fn_sig.output())
}
pub fn variadic(&self) -> bool {
self.skip_binder().variadic
pub fn c_variadic(&self) -> bool {
self.skip_binder().c_variadic
}
pub fn unsafety(&self) -> hir::Unsafety {
self.skip_binder().unsafety

View file

@ -360,7 +360,7 @@ impl PrintContext {
fn fn_sig<F: fmt::Write>(&mut self,
f: &mut F,
inputs: &[Ty<'_>],
variadic: bool,
c_variadic: bool,
output: Ty<'_>)
-> fmt::Result {
write!(f, "(")?;
@ -370,7 +370,7 @@ impl PrintContext {
for &ty in inputs {
print!(f, self, write(", "), print_display(ty))?;
}
if variadic {
if c_variadic {
write!(f, ", ...")?;
}
}
@ -1074,10 +1074,10 @@ define_print! {
}
write!(f, "fn")?;
cx.fn_sig(f, self.inputs(), self.variadic, self.output())
cx.fn_sig(f, self.inputs(), self.c_variadic, self.output())
}
debug {
write!(f, "({:?}; variadic: {})->{:?}", self.inputs(), self.variadic, self.output())
write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output())
}
}
}

View file

@ -422,7 +422,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
let mut inputs = sig.inputs();
let extra_args = if sig.abi == RustCall {
assert!(!sig.variadic && extra_args.is_empty());
assert!(!sig.c_variadic && extra_args.is_empty());
match sig.inputs().last().unwrap().sty {
ty::Tuple(ref tupled_arguments) => {
@ -435,7 +435,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
}
}
} else {
assert!(sig.variadic || extra_args.is_empty());
assert!(sig.c_variadic || extra_args.is_empty());
extra_args
};
@ -531,7 +531,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
// If this is a C-variadic function, this is not the return value,
// and there is one or more fixed arguments; ensure that the `VaList`
// is ignored as an argument.
if sig.variadic {
if sig.c_variadic {
match (last_arg_idx, arg_idx) {
(Some(last_idx), Some(cur_idx)) if last_idx == cur_idx => {
let va_list_did = match cx.tcx.lang_items().va_list() {
@ -589,7 +589,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
args: inputs.iter().chain(extra_args).enumerate().map(|(i, ty)| {
arg_of(ty, Some(i))
}).collect(),
variadic: sig.variadic,
c_variadic: sig.c_variadic,
conv,
};
fn_ty.adjust_for_abi(cx, sig.abi);
@ -717,7 +717,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
llargument_tys.push(llarg_ty);
}
if self.variadic {
if self.c_variadic {
cx.type_variadic_func(&llargument_tys, llreturn_ty)
} else {
cx.type_func(&llargument_tys, llreturn_ty)

View file

@ -143,7 +143,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
output.pop();
}
if sig.variadic {
if sig.c_variadic {
if !sig.inputs().is_empty() {
output.push_str(", ...");
} else {

View file

@ -232,7 +232,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&mut self,
mut bx: Bx,
) {
if self.fn_ty.variadic {
if self.fn_ty.c_variadic {
if let Some(va_list) = self.va_list_ref {
bx.va_end(va_list.llval);
}
@ -507,7 +507,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// The "spoofed" `VaList` added to a C-variadic functions signature
// should not be included in the `extra_args` calculation.
let extra_args_start_idx = sig.inputs().len() - if sig.variadic { 1 } else { 0 };
let extra_args_start_idx = sig.inputs().len() - if sig.c_variadic { 1 } else { 0 };
let extra_args = &args[extra_args_start_idx..];
let extra_args = extra_args.iter().map(|op_arg| {
let op_ty = op_arg.ty(self.mir, bx.tcx());
@ -695,7 +695,7 @@ impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// an "spoofed" `VaList`. This argument is ignored, but we need to
// populate it with a dummy operand so that the users real arguments
// are not overwritten.
let i = if sig.variadic && last_arg_idx.map(|x| x == i).unwrap_or(false) {
let i = if sig.c_variadic && last_arg_idx.map(|x| x == i).unwrap_or(false) {
let layout = match self.cx.tcx().lang_items().va_list() {
Some(did) => bx.cx().layout_of(bx.tcx().type_of(did)),
None => bug!("`va_list` language item required for C-variadics"),

View file

@ -585,7 +585,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>(
indirect_operand.store(bx, tmp);
tmp
} else {
if fx.fn_ty.variadic && last_arg_idx.map(|idx| arg_index == idx).unwrap_or(false) {
if fx.fn_ty.c_variadic && last_arg_idx.map(|idx| arg_index == idx).unwrap_or(false) {
let va_list_impl = match arg_decl.ty.ty_adt_def() {
Some(adt) => adt.non_enum_variant(),
None => bug!("`va_list` language item improperly constructed")

View file

@ -766,7 +766,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
let def_id = self.cx.tcx.hir().local_def_id(id);
let sig = self.cx.tcx.fn_sig(def_id);
let sig = self.cx.tcx.erase_late_bound_regions(&sig);
let inputs = if sig.variadic {
let inputs = if sig.c_variadic {
// Don't include the spoofed `VaList` in the functions list
// of inputs.
&sig.inputs()[..sig.inputs().len() - 1]

View file

@ -1604,12 +1604,12 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
debug!("check_call_inputs({:?}, {:?})", sig, args);
// Do not count the `VaList` argument as a "true" argument to
// a C-variadic function.
let inputs = if sig.variadic {
let inputs = if sig.c_variadic {
&sig.inputs()[..sig.inputs().len() - 1]
} else {
&sig.inputs()[..]
};
if args.len() < inputs.len() || (args.len() > inputs.len() && !sig.variadic) {
if args.len() < inputs.len() || (args.len() > inputs.len() && !sig.c_variadic) {
span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
}
for (n, (fn_arg, op_arg)) in inputs.iter().zip(args).enumerate() {

View file

@ -353,7 +353,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> {
output.pop();
}
if sig.variadic {
if sig.c_variadic {
if !sig.inputs().is_empty() {
output.push_str(", ...");
} else {

View file

@ -99,7 +99,7 @@ pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>)
// `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates.
let vfp = cx.target_spec().llvm_target.ends_with("hf")
&& fty.conv != Conv::ArmAapcs
&& !fty.variadic;
&& !fty.c_variadic;
if !fty.ret.is_ignore() {
classify_ret_ty(cx, &mut fty.ret, vfp);

View file

@ -531,7 +531,7 @@ pub struct FnType<'a, Ty> {
/// LLVM return type.
pub ret: ArgType<'a, Ty>,
pub variadic: bool,
pub c_variadic: bool,
pub conv: Conv,
}

View file

@ -105,7 +105,7 @@ fn assemble_builtin_sized_impls<'tcx>(
let fn_ptr = generic_types::fn_ptr(
tcx,
fn_ptr.inputs_and_output.len(),
fn_ptr.variadic,
fn_ptr.c_variadic,
fn_ptr.unsafety,
fn_ptr.abi
);
@ -190,11 +190,11 @@ fn wf_clause_for_raw_ptr<'tcx>(
fn wf_clause_for_fn_ptr<'tcx>(
tcx: ty::TyCtxt<'_, '_, 'tcx>,
arity_and_output: usize,
variadic: bool,
c_variadic: bool,
unsafety: hir::Unsafety,
abi: abi::Abi
) -> Clauses<'tcx> {
let fn_ptr = generic_types::fn_ptr(tcx, arity_and_output, variadic, unsafety, abi);
let fn_ptr = generic_types::fn_ptr(tcx, arity_and_output, c_variadic, unsafety, abi);
let wf_clause = ProgramClause {
goal: DomainGoal::WellFormed(WellFormed::Ty(fn_ptr)),
@ -503,7 +503,7 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> {
wf_clause_for_fn_ptr(
self.infcx.tcx,
fn_ptr.inputs_and_output.len(),
fn_ptr.variadic,
fn_ptr.c_variadic,
fn_ptr.unsafety,
fn_ptr.abi
)

View file

@ -24,7 +24,7 @@ crate fn raw_ptr(tcx: TyCtxt<'_, '_, 'tcx>, mutbl: hir::Mutability) -> Ty<'tcx>
crate fn fn_ptr(
tcx: ty::TyCtxt<'_, '_, 'tcx>,
arity_and_output: usize,
variadic: bool,
c_variadic: bool,
unsafety: hir::Unsafety,
abi: abi::Abi
) -> Ty<'tcx> {
@ -37,7 +37,7 @@ crate fn fn_ptr(
let fn_sig = ty::Binder::bind(ty::FnSig {
inputs_and_output,
variadic,
c_variadic,
unsafety,
abi,
});

View file

@ -18,7 +18,7 @@ use rustc::ty::subst::{Kind, Subst, InternalSubsts, SubstsRef};
use rustc::ty::wf::object_region_bounds;
use rustc_data_structures::sync::Lrc;
use rustc_target::spec::abi;
use crate::require_c_abi_if_variadic;
use crate::require_c_abi_if_c_variadic;
use smallvec::SmallVec;
use syntax::ast;
use syntax::feature_gate::{GateIssue, emit_feature_err};
@ -1768,7 +1768,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
tcx.mk_tup(fields.iter().map(|t| self.ast_ty_to_ty(&t)))
}
hir::TyKind::BareFn(ref bf) => {
require_c_abi_if_variadic(tcx, &bf.decl, bf.abi, ast_ty.span);
require_c_abi_if_c_variadic(tcx, &bf.decl, bf.abi, ast_ty.span);
tcx.mk_fn_ptr(self.ty_of_fn(bf.unsafety, bf.abi, &bf.decl))
}
hir::TyKind::TraitObject(ref bounds, ref lifetime) => {
@ -1913,7 +1913,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
let bare_fn_ty = ty::Binder::bind(tcx.mk_fn_sig(
input_tys,
output_ty,
decl.variadic,
decl.c_variadic,
unsafety,
abi
));

View file

@ -368,7 +368,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
.0;
let fn_sig = self.normalize_associated_types_in(call_expr.span, &fn_sig);
let inputs = if fn_sig.variadic {
let inputs = if fn_sig.c_variadic {
if fn_sig.inputs().len() > 1 {
&fn_sig.inputs()[..fn_sig.inputs().len() - 1]
} else {
@ -391,7 +391,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
inputs,
&expected_arg_tys[..],
arg_exprs,
fn_sig.variadic,
fn_sig.c_variadic,
TupleArgumentsFlag::DontTupleArguments,
def_span,
);
@ -424,7 +424,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn_sig.inputs(),
&expected_arg_tys,
arg_exprs,
fn_sig.variadic,
fn_sig.c_variadic,
TupleArgumentsFlag::TupleArguments,
None,
);

View file

@ -141,7 +141,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.tcx.mk_fn_sig(
iter::once(self.tcx.intern_tup(sig.inputs())),
sig.output(),
sig.variadic,
sig.c_variadic,
sig.unsafety,
sig.abi,
)
@ -386,7 +386,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// Watch out for some surprises and just ignore the
// expectation if things don't see to match up with what we
// expect.
if expected_sig.sig.variadic != decl.variadic {
if expected_sig.sig.c_variadic != decl.c_variadic {
return self.sig_of_closure_no_expectation(expr_def_id, decl, body);
} else if expected_sig.sig.inputs_and_output.len() != decl.inputs.len() + 1 {
return self.sig_of_closure_with_mismatched_number_of_arguments(
@ -404,7 +404,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let bound_sig = ty::Binder::bind(self.tcx.mk_fn_sig(
expected_sig.sig.inputs().iter().cloned(),
expected_sig.sig.output(),
decl.variadic,
decl.c_variadic,
hir::Unsafety::Normal,
Abi::RustCall,
));
@ -586,7 +586,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let result = ty::Binder::bind(self.tcx.mk_fn_sig(
supplied_arguments,
supplied_return,
decl.variadic,
decl.c_variadic,
hir::Unsafety::Normal,
Abi::RustCall,
));
@ -621,7 +621,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let result = ty::Binder::bind(self.tcx.mk_fn_sig(
supplied_arguments,
self.tcx.types.err,
decl.variadic,
decl.c_variadic,
hir::Unsafety::Normal,
Abi::RustCall,
));

View file

@ -130,7 +130,7 @@ use std::mem::replace;
use std::ops::{self, Deref};
use std::slice;
use crate::require_c_abi_if_variadic;
use crate::require_c_abi_if_c_variadic;
use crate::session::{CompileIncomplete, Session};
use crate::session::config::EntryFnType;
use crate::TypeAndSubsts;
@ -1072,7 +1072,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>,
fn_sig = fcx.tcx.mk_fn_sig(
fn_sig.inputs().iter().cloned(),
revealed_ret_ty,
fn_sig.variadic,
fn_sig.c_variadic,
fn_sig.unsafety,
fn_sig.abi
);
@ -1426,7 +1426,7 @@ pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Ite
}
if let hir::ForeignItemKind::Fn(ref fn_decl, _, _) = item.node {
require_c_abi_if_variadic(tcx, fn_decl, m.abi, item.span);
require_c_abi_if_c_variadic(tcx, fn_decl, m.abi, item.span);
}
}
}
@ -2783,7 +2783,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
&method.sig.inputs()[1..]
);
self.check_argument_types(sp, expr_sp, &method.sig.inputs()[1..], &expected_arg_tys[..],
args_no_rcvr, method.sig.variadic, tuple_arguments,
args_no_rcvr, method.sig.c_variadic, tuple_arguments,
self.tcx.hir().span_if_local(method.def_id));
method.sig.output()
}
@ -2862,7 +2862,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
fn_inputs: &[Ty<'tcx>],
mut expected_arg_tys: &[Ty<'tcx>],
args: &'gcx [hir::Expr],
variadic: bool,
c_variadic: bool,
tuple_arguments: TupleArgumentsFlag,
def_span: Option<Span>) {
let tcx = self.tcx;
@ -2886,11 +2886,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let param_count_error = |expected_count: usize,
arg_count: usize,
error_code: &str,
variadic: bool,
c_variadic: bool,
sugg_unit: bool| {
let mut err = tcx.sess.struct_span_err_with_code(sp,
&format!("this function takes {}{} but {} {} supplied",
if variadic {"at least "} else {""},
if c_variadic { "at least " } else { "" },
potentially_plural_count(expected_count, "parameter"),
potentially_plural_count(arg_count, "parameter"),
if arg_count == 1 {"was"} else {"were"}),
@ -2910,7 +2910,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
Applicability::MachineApplicable);
} else {
err.span_label(sp, format!("expected {}{}",
if variadic {"at least "} else {""},
if c_variadic { "at least " } else { "" },
potentially_plural_count(expected_count, "parameter")));
}
err.emit();
@ -2944,7 +2944,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}
} else if expected_arg_count == supplied_arg_count {
fn_inputs.to_vec()
} else if variadic {
} else if c_variadic {
if supplied_arg_count >= expected_arg_count {
fn_inputs.to_vec()
} else {
@ -2991,10 +2991,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.select_obligations_where_possible(false);
}
// For variadic functions, we don't have a declared type for all of
// For C-variadic functions, we don't have a declared type for all of
// the arguments hence we only do our usual type checking with
// the arguments who's types we do know.
let t = if variadic {
let t = if c_variadic {
expected_arg_count
} else if tuple_arguments == TupleArguments {
args.len()
@ -3043,7 +3043,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// We also need to make sure we at least write the ty of the other
// arguments which we skipped above.
if variadic {
if c_variadic {
fn variadic_error<'tcx>(s: &Session, span: Span, t: Ty<'tcx>, cast_ty: &str) {
use crate::structured_errors::{VariadicError, StructuredDiagnostic};
VariadicError::new(s, span, t, cast_ty).diagnostic().emit();

View file

@ -136,14 +136,14 @@ fn check_type_alias_enum_variants_enabled<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx,
}
}
fn require_c_abi_if_variadic(tcx: TyCtxt<'_, '_, '_>,
fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_, '_, '_>,
decl: &hir::FnDecl,
abi: Abi,
span: Span) {
if decl.variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
if decl.c_variadic && !(abi == Abi::C || abi == Abi::Cdecl) {
let mut err = struct_span_err!(tcx.sess, span, E0045,
"variadic function must have C or cdecl calling convention");
err.span_label(span, "variadics require C or cdecl calling convention").emit();
"C-variadic function must have C or cdecl calling convention");
err.span_label(span, "C-variadics require C or cdecl calling convention").emit();
}
}

View file

@ -1804,7 +1804,7 @@ impl Arg {
pub struct FnDecl {
pub inputs: Vec<Arg>,
pub output: FunctionRetTy,
pub variadic: bool,
pub c_variadic: bool,
}
impl FnDecl {

View file

@ -985,7 +985,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
P(ast::FnDecl {
inputs,
output,
variadic: false
c_variadic: false
})
}

View file

@ -673,7 +673,7 @@ pub fn noop_visit_asyncness<T: MutVisitor>(asyncness: &mut IsAsync, vis: &mut T)
}
pub fn noop_visit_fn_decl<T: MutVisitor>(decl: &mut P<FnDecl>, vis: &mut T) {
let FnDecl { inputs, output, variadic: _ } = decl.deref_mut();
let FnDecl { inputs, output, c_variadic: _ } = decl.deref_mut();
visit_vec(inputs, |input| vis.visit_arg(input));
match output {
FunctionRetTy::Default(span) => vis.visit_span(span),

View file

@ -1457,12 +1457,12 @@ impl<'a> Parser<'a> {
};
self.expect_keyword(keywords::Fn)?;
let (inputs, variadic) = self.parse_fn_args(false, true)?;
let (inputs, c_variadic) = self.parse_fn_args(false, true)?;
let ret_ty = self.parse_ret_ty(false)?;
let decl = P(FnDecl {
inputs,
output: ret_ty,
variadic,
c_variadic,
});
Ok(TyKind::BareFn(P(BareFnTy {
abi,
@ -1635,7 +1635,7 @@ impl<'a> Parser<'a> {
}
fn parse_ty_common(&mut self, allow_plus: bool, allow_qpath_recovery: bool,
allow_variadic: bool) -> PResult<'a, P<Ty>> {
allow_c_variadic: bool) -> PResult<'a, P<Ty>> {
maybe_whole!(self, NtTy, |x| x);
let lo = self.span;
@ -1773,12 +1773,12 @@ impl<'a> Parser<'a> {
}
}
} else if self.check(&token::DotDotDot) {
if allow_variadic {
if allow_c_variadic {
self.eat(&token::DotDotDot);
TyKind::CVarArgs
} else {
return Err(self.fatal(
"only foreign functions are allowed to be variadic"
"only foreign functions are allowed to be C-variadic"
));
}
} else {
@ -1969,7 +1969,7 @@ impl<'a> Parser<'a> {
/// This version of parse arg doesn't necessarily require identifier names.
fn parse_arg_general(&mut self, require_name: bool, is_trait_item: bool,
allow_variadic: bool) -> PResult<'a, Arg> {
allow_c_variadic: bool) -> PResult<'a, Arg> {
maybe_whole!(self, NtArg, |x| x);
if let Ok(Some(_)) = self.parse_self_arg() {
@ -2018,12 +2018,12 @@ impl<'a> Parser<'a> {
}
self.eat_incorrect_doc_comment("a method argument's type");
(pat, self.parse_ty_common(true, true, allow_variadic)?)
(pat, self.parse_ty_common(true, true, allow_c_variadic)?)
} else {
debug!("parse_arg_general ident_to_pat");
let parser_snapshot_before_ty = self.clone();
self.eat_incorrect_doc_comment("a method argument's type");
let mut ty = self.parse_ty_common(true, true, allow_variadic);
let mut ty = self.parse_ty_common(true, true, allow_c_variadic);
if ty.is_ok() && self.token != token::Comma &&
self.token != token::CloseDelim(token::Paren) {
// This wasn't actually a type, but a pattern looking like a type,
@ -2042,7 +2042,7 @@ impl<'a> Parser<'a> {
(pat, ty)
}
Err(mut err) => {
// If this is a variadic argument and we hit an error, return the
// If this is a C-variadic argument and we hit an error, return the
// error.
if self.token == token::DotDotDot {
return Err(err);
@ -6122,12 +6122,12 @@ impl<'a> Parser<'a> {
Ok(where_clause)
}
fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool)
fn parse_fn_args(&mut self, named_args: bool, allow_c_variadic: bool)
-> PResult<'a, (Vec<Arg> , bool)> {
self.expect(&token::OpenDelim(token::Paren))?;
let sp = self.span;
let mut variadic = false;
let mut c_variadic = false;
let (args, recovered): (Vec<Option<Arg>>, bool) =
self.parse_seq_to_before_end(
&token::CloseDelim(token::Paren),
@ -6141,14 +6141,14 @@ impl<'a> Parser<'a> {
named_args
};
match p.parse_arg_general(enforce_named_args, false,
allow_variadic) {
allow_c_variadic) {
Ok(arg) => {
if let TyKind::CVarArgs = arg.ty.node {
variadic = true;
c_variadic = true;
if p.token != token::CloseDelim(token::Paren) {
let span = p.span;
p.span_err(span,
"`...` must be last in argument list in variadic function");
"`...` must be the last argument of a C-variadic function");
Ok(None)
} else {
Ok(Some(arg))
@ -6176,24 +6176,24 @@ impl<'a> Parser<'a> {
let args: Vec<_> = args.into_iter().filter_map(|x| x).collect();
if variadic && args.is_empty() {
if c_variadic && args.is_empty() {
self.span_err(sp,
"variadic function must be declared with at least one named argument");
"C-variadic function must be declared with at least one named argument");
}
Ok((args, variadic))
Ok((args, c_variadic))
}
/// Parses the argument list and result type of a function declaration.
fn parse_fn_decl(&mut self, allow_variadic: bool) -> PResult<'a, P<FnDecl>> {
fn parse_fn_decl(&mut self, allow_c_variadic: bool) -> PResult<'a, P<FnDecl>> {
let (args, variadic) = self.parse_fn_args(true, allow_variadic)?;
let (args, c_variadic) = self.parse_fn_args(true, allow_c_variadic)?;
let ret_ty = self.parse_ret_ty(true)?;
Ok(P(FnDecl {
inputs: args,
output: ret_ty,
variadic,
c_variadic,
}))
}
@ -6340,7 +6340,7 @@ impl<'a> Parser<'a> {
Ok(P(FnDecl {
inputs: fn_inputs,
output: self.parse_ret_ty(true)?,
variadic: false
c_variadic: false
}))
}
@ -6366,7 +6366,7 @@ impl<'a> Parser<'a> {
Ok(P(FnDecl {
inputs: inputs_captures,
output,
variadic: false
c_variadic: false
}))
}
@ -6398,8 +6398,8 @@ impl<'a> Parser<'a> {
abi: Abi)
-> PResult<'a, ItemInfo> {
let (ident, mut generics) = self.parse_fn_header()?;
let allow_variadic = abi == Abi::C && unsafety == Unsafety::Unsafe;
let decl = self.parse_fn_decl(allow_variadic)?;
let allow_c_variadic = abi == Abi::C && unsafety == Unsafety::Unsafe;
let decl = self.parse_fn_decl(allow_c_variadic)?;
generics.where_clause = self.parse_where_clause()?;
let (inner_attrs, body) = self.parse_inner_attrs_and_block()?;
let header = FnHeader { unsafety, asyncness, constness, abi };

View file

@ -2814,7 +2814,7 @@ impl<'a> State<'a> {
-> io::Result<()> {
self.popen()?;
self.commasep(Inconsistent, &decl.inputs, |s, arg| s.print_arg(arg, false))?;
if decl.variadic {
if decl.c_variadic {
self.s.word(", ...")?;
}
self.pclose()?;
@ -3241,7 +3241,7 @@ mod tests {
let decl = ast::FnDecl {
inputs: Vec::new(),
output: ast::FunctionRetTy::Default(syntax_pos::DUMMY_SP),
variadic: false
c_variadic: false
};
let generics = ast::Generics::default();
assert_eq!(

View file

@ -112,7 +112,7 @@ fn iter_exprs(depth: usize, f: &mut FnMut(P<Expr>)) {
let decl = P(FnDecl {
inputs: vec![],
output: FunctionRetTy::Default(DUMMY_SP),
variadic: false,
c_variadic: false,
});
iter_exprs(depth - 1, &mut |e| g(
ExprKind::Closure(CaptureBy::Value,

View file

@ -1,8 +1,8 @@
error[E0045]: variadic function must have C or cdecl calling convention
error[E0045]: C-variadic function must have C or cdecl calling convention
--> $DIR/variadic-ffi-1.rs:5:5
|
LL | fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C or cdecl calling
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variadics require C or cdecl calling convention
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention
error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0045]: variadic function must have C or cdecl calling convention
error[E0045]: C-variadic function must have C or cdecl calling convention
--> $DIR/variadic-ffi-2.rs:3:11
|
LL | fn baz(f: extern "stdcall" fn(usize, ...)) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variadics require C or cdecl calling convention
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention
error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0045]: variadic function must have C or cdecl calling convention
error[E0045]: C-variadic function must have C or cdecl calling convention
--> $DIR/E0045.rs:1:17
|
LL | extern "Rust" { fn foo(x: u8, ...); } //~ ERROR E0045
| ^^^^^^^^^^^^^^^^^^^ variadics require C or cdecl calling convention
| ^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention
error: aborting due to previous error

View file

@ -1,3 +1,3 @@
extern "C" fn foo(x: u8, ...);
//~^ ERROR only foreign functions are allowed to be variadic
//~^ ERROR only foreign functions are allowed to be C-variadic
//~| ERROR expected one of `->`, `where`, or `{`, found `;`

View file

@ -1,4 +1,4 @@
error: only foreign functions are allowed to be variadic
error: only foreign functions are allowed to be C-variadic
--> $DIR/invalid-variadic-function.rs:1:26
|
LL | extern "C" fn foo(x: u8, ...);

View file

@ -1,5 +1,5 @@
fn foo(x: isize, ...) {
//~^ ERROR: only foreign functions are allowed to be variadic
//~^ ERROR: only foreign functions are allowed to be C-variadic
}
fn main() {}

View file

@ -1,4 +1,4 @@
error: only foreign functions are allowed to be variadic
error: only foreign functions are allowed to be C-variadic
--> $DIR/variadic-ffi-3.rs:1:18
|
LL | fn foo(x: isize, ...) {

View file

@ -1,5 +1,5 @@
extern "C" fn foo(x: isize, ...) {
//~^ ERROR: only foreign functions are allowed to be variadic
//~^ ERROR: only foreign functions are allowed to be C-variadic
}
fn main() {}

View file

@ -1,4 +1,4 @@
error: only foreign functions are allowed to be variadic
error: only foreign functions are allowed to be C-variadic
--> $DIR/variadic-ffi-4.rs:1:29
|
LL | extern "C" fn foo(x: isize, ...) {