Skip to content

Commit

Permalink
Rollup merge of rust-lang#63459 - eddyb:issue-63430, r=petrochenkov
Browse files Browse the repository at this point in the history
syntax: account for CVarArgs being in the argument list.

Fixes rust-lang#63430 by testing for `1` argument (the `CVarArgs` itself) instead of `0`.

Note that the error has basically been impossible to trigger since the change that caused rust-lang#63430, so perhaps we need an audit of untested errors.

Also, this check probably belongs in AST validation/HIR lowering, but I'd rather fix it in place for now.

r? @petrochenkov cc @dlrobertson
  • Loading branch information
Centril authored Aug 13, 2019
2 parents 1b26851 + 34dcca2 commit 466312c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ impl<'a> Parser<'a> {

let args: Vec<_> = args.into_iter().filter_map(|x| x).collect();

if c_variadic && args.is_empty() {
if c_variadic && args.len() <= 1 {
self.span_err(sp,
"C-variadic function must be declared with at least one named argument");
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/c-variadic/variadic-ffi-no-fixed-args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern {
fn foo(...);
//~^ ERROR C-variadic function must be declared with at least one named argument
}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/c-variadic/variadic-ffi-no-fixed-args.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: C-variadic function must be declared with at least one named argument
--> $DIR/variadic-ffi-no-fixed-args.rs:2:11
|
LL | fn foo(...);
| ^

error: aborting due to previous error

0 comments on commit 466312c

Please sign in to comment.