Skip to content

Disallow omitting the ABI in extern declarations #697

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
wants to merge 2 commits into from
Closed
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
36 changes: 36 additions & 0 deletions text/0000-explicit-abi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
- Start Date: 2015-01-20
- RFC PR: (leave this empty)
- Rust Issue: (leave this empty)

# Summary

Disallow omitting the ABI in `extern` declarations, both for extern functions and for external blocks.

# Motivation

Some advantages of making the ABI explicit are:
- it would ensure a more uniform coding style (even in the main rust repo you can find both extern fn and extern "C" fn)
- it would make it easier to search for what ABIs are used in a codebase
- it would be more familiar to C++ programmers

Removing the default for both functions and blocks helps with ensuring consistency.

# Detailed design

Removing the default is simple, just a matter of making the token non-optional in the parser.

Updating exisiting code to take the change into account can be automated, as it is a straightforward search-and-replace.

# Drawbacks

It should be trivial to add the "C" ABI (the current default) wherever it is missing, but the change would still break existing code.

# Alternatives

Keeping the current default will not break code; it might lead to some inconsistent usage of the explicit "C" ABI, but this could be solved on a per-project basis using coding guidelines.

It would be possible to perform the change ony on extern functions or on external blocks, but this would make the grammar rules less consistent and more surprising for users.

# Unresolved questions

Should no-ABI empty `extern` blocks (occasionally used to link a library without explicitly accessing its functions) be allowed?