-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also fix error the code description.
- Loading branch information
Showing
4 changed files
with
53 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
C-variadic has been used on a non-foreign function. | ||
The C-variadic type `...` has been nested inside another type. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0743 | ||
fn foo2(x: u8, ...) {} // error! | ||
#![feature(c_variadic)] | ||
fn foo2(x: u8, y: &...) {} // 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. | ||
Only foreign functions can use the C-variadic type (`...`). | ||
In such functions, `...` may only occur non-nested. | ||
That is, `y: &'a ...` is not allowed. | ||
|
||
A C-variadic type 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
fn f1<'a>(x: u8, y: &'a ...) {} | ||
//~^ ERROR C-variadic type `...` may not be nested inside another type | ||
|
||
fn f2<'a>(x: u8, y: Vec<&'a ...>) {} | ||
//~^ ERROR C-variadic type `...` may not be nested inside another type | ||
|
||
fn main() { | ||
let _recovery_witness: () = 0; //~ ERROR mismatched types | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/parser/variadic-ffi-nested-syntactic-fail.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0743]: C-variadic type `...` may not be nested inside another type | ||
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:1:25 | ||
| | ||
LL | fn f1<'a>(x: u8, y: &'a ...) {} | ||
| ^^^ | ||
|
||
error[E0743]: C-variadic type `...` may not be nested inside another type | ||
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:4:29 | ||
| | ||
LL | fn f2<'a>(x: u8, y: Vec<&'a ...>) {} | ||
| ^^^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/variadic-ffi-nested-syntactic-fail.rs:8:33 | ||
| | ||
LL | let _recovery_witness: () = 0; | ||
| -- ^ expected `()`, found integer | ||
| | | ||
| expected due to this | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0743. | ||
For more information about an error, try `rustc --explain E0308`. |