Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error code E0743 for "C-variadic has been used on a non-foreign function" #65995

Merged
merged 2 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/libsyntax/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ Erroneous code example:
// `test_2018_feature` is
// included in the Rust 2018 edition
```

"##,

E0725: r##"
Expand All @@ -505,6 +504,20 @@ Delete the offending feature attribute, or add it to the list of allowed
features in the `-Z allow_features` flag.
"##,

E0743: r##"
C-variadic has been used on a non-foreign function.

Erroneous code example:

```compile_fail,E0743
fn foo2(x: u8, ...) {} // error!
```

Only foreign functions can use C-variadic (`...`). It is used to give an
undefined number of parameters to a given function (like `printf` in C). The
equivalent in Rust would be to use macros directly.
"##,

;

E0539, // incorrect meta item
Expand Down
7 changes: 5 additions & 2 deletions src/libsyntax/parse/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,11 @@ impl<'a> Parser<'a> {
self.eat(&token::DotDotDot);
TyKind::CVarArgs
} else {
return Err(self.fatal(
"only foreign functions are allowed to be C-variadic"
return Err(struct_span_fatal!(
self.sess.span_diagnostic,
self.token.span,
E0743,
"only foreign functions are allowed to be C-variadic",
));
}
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/invalid/invalid-variadic-function.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: only foreign functions are allowed to be C-variadic
error[E0743]: only foreign functions are allowed to be C-variadic
--> $DIR/invalid-variadic-function.rs:1:26
|
LL | extern "C" fn foo(x: u8, ...);
Expand All @@ -12,3 +12,4 @@ LL | extern "C" fn foo(x: u8, ...);

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0743`.
3 changes: 2 additions & 1 deletion src/test/ui/parser/variadic-ffi-3.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
error: only foreign functions are allowed to be C-variadic
error[E0743]: only foreign functions are allowed to be C-variadic
--> $DIR/variadic-ffi-3.rs:1:18
|
LL | fn foo(x: isize, ...) {
| ^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0743`.
3 changes: 2 additions & 1 deletion src/test/ui/parser/variadic-ffi-4.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
error: only foreign functions are allowed to be C-variadic
error[E0743]: only foreign functions are allowed to be C-variadic
--> $DIR/variadic-ffi-4.rs:1:29
|
LL | extern "C" fn foo(x: isize, ...) {
| ^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0743`.