Fix bad-c-variadic error being emitted multiple times
If a function incorrectly contains multiple `...` args, and is also not foreign or `unsafe extern "C"`, only emit the latter error once.
This commit is contained in:
parent
ec2b311914
commit
8508e65895
5 changed files with 31 additions and 43 deletions
|
@ -485,6 +485,18 @@ impl<'a> AstValidator<'a> {
|
|||
/// Reject C-variadic type unless the function is foreign,
|
||||
/// or free and `unsafe extern "C"` semantically.
|
||||
fn check_c_variadic_type(&self, fk: FnKind<'a>) {
|
||||
let variadic_spans: Vec<_> = fk
|
||||
.decl()
|
||||
.inputs
|
||||
.iter()
|
||||
.filter(|arg| matches!(arg.ty.kind, TyKind::CVarArgs))
|
||||
.map(|arg| arg.span)
|
||||
.collect();
|
||||
|
||||
if variadic_spans.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
match (fk.ctxt(), fk.header()) {
|
||||
(Some(FnCtxt::Foreign), _) => return,
|
||||
(Some(FnCtxt::Free), Some(header)) => match header.ext {
|
||||
|
@ -499,11 +511,7 @@ impl<'a> AstValidator<'a> {
|
|||
_ => {}
|
||||
};
|
||||
|
||||
for Param { ty, span, .. } in &fk.decl().inputs {
|
||||
if let TyKind::CVarArgs = ty.kind {
|
||||
self.err_handler().emit_err(errors::BadCVariadic { span: *span });
|
||||
}
|
||||
}
|
||||
self.err_handler().emit_err(errors::BadCVariadic { span: variadic_spans });
|
||||
}
|
||||
|
||||
fn check_item_named(&self, ident: Ident, kind: &str) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue