Skip to content

Commit 0682fc0

Browse files
authored
Rollup merge of rust-lang#65995 - GuillaumeGomez:add-err-code-E0743, r=estebank
Add error code E0743 for "C-variadic has been used on a non-foreign function" Fixes rust-lang#65967
2 parents 07b6b70 + fcbf77e commit 0682fc0

File tree

5 files changed

+25
-6
lines changed

5 files changed

+25
-6
lines changed

src/libsyntax/error_codes.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ Erroneous code example:
487487
// `test_2018_feature` is
488488
// included in the Rust 2018 edition
489489
```
490-
491490
"##,
492491

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

507+
E0743: r##"
508+
C-variadic has been used on a non-foreign function.
509+
510+
Erroneous code example:
511+
512+
```compile_fail,E0743
513+
fn foo2(x: u8, ...) {} // error!
514+
```
515+
516+
Only foreign functions can use C-variadic (`...`). It is used to give an
517+
undefined number of parameters to a given function (like `printf` in C). The
518+
equivalent in Rust would be to use macros directly.
519+
"##,
520+
508521
;
509522

510523
E0539, // incorrect meta item

src/libsyntax/parse/parser/ty.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,11 @@ impl<'a> Parser<'a> {
197197
self.eat(&token::DotDotDot);
198198
TyKind::CVarArgs
199199
} else {
200-
return Err(self.fatal(
201-
"only foreign functions are allowed to be C-variadic"
200+
return Err(struct_span_fatal!(
201+
self.sess.span_diagnostic,
202+
self.token.span,
203+
E0743,
204+
"only foreign functions are allowed to be C-variadic",
202205
));
203206
}
204207
} else {

src/test/ui/invalid/invalid-variadic-function.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: only foreign functions are allowed to be C-variadic
1+
error[E0743]: only foreign functions are allowed to be C-variadic
22
--> $DIR/invalid-variadic-function.rs:1:26
33
|
44
LL | extern "C" fn foo(x: u8, ...);
@@ -12,3 +12,4 @@ LL | extern "C" fn foo(x: u8, ...);
1212

1313
error: aborting due to 2 previous errors
1414

15+
For more information about this error, try `rustc --explain E0743`.
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
error: only foreign functions are allowed to be C-variadic
1+
error[E0743]: only foreign functions are allowed to be C-variadic
22
--> $DIR/variadic-ffi-3.rs:1:18
33
|
44
LL | fn foo(x: isize, ...) {
55
| ^^^
66

77
error: aborting due to previous error
88

9+
For more information about this error, try `rustc --explain E0743`.
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
error: only foreign functions are allowed to be C-variadic
1+
error[E0743]: only foreign functions are allowed to be C-variadic
22
--> $DIR/variadic-ffi-4.rs:1:29
33
|
44
LL | extern "C" fn foo(x: isize, ...) {
55
| ^^^
66

77
error: aborting due to previous error
88

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

0 commit comments

Comments
 (0)