Skip to content

foreign function invalid error message #31481

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

Closed
GuillaumeGomez opened this issue Feb 7, 2016 · 2 comments
Closed

foreign function invalid error message #31481

GuillaumeGomez opened this issue Feb 7, 2016 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@GuillaumeGomez
Copy link
Member

This code works:

extern "C" {
    fn foo(x: u8, ...);
}

While this one doesn't:

extern "C" fn foo(x: u8, ...); // error: only foreign functions are allowed to be variadic

I don't think this is the expected behavior.

@huonw
Copy link
Member

huonw commented Feb 7, 2016

What behaviour do you expect? Depending on exactly what you're hoping happens, I don't think this is a bug, since extern "C" fn foo(..) is defining a Rust function that uses the C ABI (i.e. is callable from C), not importing a C function called foo. That is, it only differs to fn foo(..) in low-level code-generation details, it still has all the normal Rust features/restrictions. This includes not working with variadic arguments.

Also, writing extern "C" fn foo(..); without a body isn't valid, e.g. if the ... is removed to allow compilation to progress, you instead get:

extern "C" fn foo(x: u8); // error: expected one of `->`, `where`, or `{`, found `;`

I suppose the error message could possibly be clearer and/or have a help or note.

@huonw huonw added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 7, 2016
@GuillaumeGomez GuillaumeGomez changed the title foreign function error foreign function invalid error message Feb 8, 2016
@GuillaumeGomez
Copy link
Member Author

GuillaumeGomez commented Feb 8, 2016

Since the original message came from a lack of knowledge, I changed the title to better reflect the "real" issue here.

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the A-parser Area: The lexing & parsing of Rust source code to an AST label Jun 12, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 24, 2017
kennytm added a commit to kennytm/rust that referenced this issue Feb 13, 2018
Continue parsing function after finding `...` arg

When encountering a variadic argument in a function definition that
doesn't accept it, if immediately after there's a closing paren,
continue parsing as normal. Otherwise keep current behavior of emitting
error and stopping.

Fix rust-lang#31481.
kennytm added a commit to kennytm/rust that referenced this issue Feb 14, 2018
Continue parsing function after finding `...` arg

When encountering a variadic argument in a function definition that
doesn't accept it, if immediately after there's a closing paren,
continue parsing as normal. Otherwise keep current behavior of emitting
error and stopping.

Fix rust-lang#31481.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants