Skip to content

Commit 8ed9b1b

Browse files
committed
Add explicit_extern_abis unstable feature
also add `explicit-extern-abis` feature section to the unstable book.
1 parent cdd8af2 commit 8ed9b1b

File tree

5 files changed

+40
-0
lines changed

5 files changed

+40
-0
lines changed

Diff for: compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,8 @@ declare_features! (
478478
(incomplete, ergonomic_clones, "CURRENT_RUSTC_VERSION", Some(132290)),
479479
/// Allows exhaustive pattern matching on types that contain uninhabited types.
480480
(unstable, exhaustive_patterns, "1.13.0", Some(51085)),
481+
/// Disallows `extern` without an explicit ABI.
482+
(unstable, explicit_extern_abis, "CURRENT_RUSTC_VERSION", Some(134986)),
481483
/// Allows explicit tail calls via `become` expression.
482484
(incomplete, explicit_tail_calls, "1.72.0", Some(112788)),
483485
/// Allows using `aapcs`, `efiapi`, `sysv64` and `win64` as calling conventions

Diff for: compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,7 @@ symbols! {
881881
expf16,
882882
expf32,
883883
expf64,
884+
explicit_extern_abis,
884885
explicit_generic_args_with_impl_trait,
885886
explicit_tail_calls,
886887
export_name,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# `explicit_extern_abis`
2+
3+
The tracking issue for this feature is: #134986
4+
5+
------
6+
7+
Disallow `extern` without an explicit ABI. We should write `extern "C"`
8+
(or another ABI) instead of just `extern`.
9+
10+
By making the ABI explicit, it becomes much clearer that "C" is just one of the
11+
possible choices, rather than the "standard" way for external functions.
12+
Removing the default makes it easier to add a new ABI on equal footing as "C".
13+
14+
```rust,editionfuture,compile_fail
15+
#![feature(explicit_extern_abis)]
16+
17+
extern fn function1() {} // ERROR extern declarations without an explicit ABI
18+
// are disallowed
19+
20+
extern "C" fn function2() {} // compiles
21+
22+
extern "aapcs" fn function3() {} // compiles
23+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(explicit_extern_abis)]
2+
3+
extern fn foo() {}
4+
//~^ ERROR extern declarations without an explicit ABI are disallowed
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: extern declarations without an explicit ABI are disallowed
2+
--> $DIR/feature-gate-explicit-extern-abis.rs:3:1
3+
|
4+
LL | extern fn foo() {}
5+
| ^^^^^^
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)