-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add explicit_extern_abis
Feature and Enforce Explicit ABIs
#135340
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
23 changes: 23 additions & 0 deletions
23
src/doc/unstable-book/src/language-features/explicit-extern-abis.md
This file contains hidden or 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,23 @@ | ||
# `explicit_extern_abis` | ||
|
||
The tracking issue for this feature is: #134986 | ||
|
||
------ | ||
|
||
Disallow `extern` without an explicit ABI. We should write `extern "C"` | ||
(or another ABI) instead of just `extern`. | ||
|
||
By making the ABI explicit, it becomes much clearer that "C" is just one of the | ||
possible choices, rather than the "standard" way for external functions. | ||
Removing the default makes it easier to add a new ABI on equal footing as "C". | ||
|
||
```rust,editionfuture,compile_fail | ||
#![feature(explicit_extern_abis)] | ||
|
||
extern fn function1() {} // ERROR `extern` declarations without an explicit ABI | ||
// are disallowed | ||
|
||
extern "C" fn function2() {} // compiles | ||
|
||
extern "aapcs" fn function3() {} // compiles | ||
``` |
45 changes: 45 additions & 0 deletions
45
tests/ui/feature-gates/feature-gate-explicit-extern-abis.current.fixed
This file contains hidden or 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,45 @@ | ||
// The purpose of this feature gate is to make something into a hard error in a | ||
// future edition. Consequently, this test differs from most other feature gate | ||
// tests. Instead of verifying that an error occurs when the feature gate is | ||
// missing, it ensures that the hard error is only produced with the feature | ||
// gate is present in the `future` edition -- and otherwise that only a warning | ||
// is emitted. | ||
|
||
//@ revisions: current current_feature future future_feature | ||
|
||
//@ [current] run-rustfix | ||
//@ [current] check-pass | ||
|
||
//@ [current_feature] run-rustfix | ||
//@ [current_feature] check-pass | ||
|
||
//@ [future] edition: future | ||
//@ [future] compile-flags: -Z unstable-options | ||
//@ [future] run-rustfix | ||
//@ [future] check-pass | ||
|
||
//@ [future_feature] edition: future | ||
//@ [future_feature] compile-flags: -Z unstable-options | ||
|
||
#![cfg_attr(future_feature, feature(explicit_extern_abis))] | ||
#![cfg_attr(current_feature, feature(explicit_extern_abis))] | ||
|
||
extern "C" fn _foo() {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
unsafe extern "C" fn _bar() {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
unsafe extern "C" {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
tests/ui/feature-gates/feature-gate-explicit-extern-abis.current.stderr
This file contains hidden or 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,22 @@ | ||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:27:1 | ||
| | ||
LL | extern fn _foo() {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
| | ||
= note: `#[warn(missing_abi)]` on by default | ||
|
||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:33:8 | ||
| | ||
LL | unsafe extern fn _bar() {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
|
||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:39:8 | ||
| | ||
LL | unsafe extern {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
|
||
warning: 3 warnings emitted | ||
|
45 changes: 45 additions & 0 deletions
45
tests/ui/feature-gates/feature-gate-explicit-extern-abis.current_feature.fixed
This file contains hidden or 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,45 @@ | ||
// The purpose of this feature gate is to make something into a hard error in a | ||
// future edition. Consequently, this test differs from most other feature gate | ||
// tests. Instead of verifying that an error occurs when the feature gate is | ||
// missing, it ensures that the hard error is only produced with the feature | ||
// gate is present in the `future` edition -- and otherwise that only a warning | ||
// is emitted. | ||
|
||
//@ revisions: current current_feature future future_feature | ||
|
||
//@ [current] run-rustfix | ||
//@ [current] check-pass | ||
|
||
//@ [current_feature] run-rustfix | ||
//@ [current_feature] check-pass | ||
|
||
//@ [future] edition: future | ||
//@ [future] compile-flags: -Z unstable-options | ||
//@ [future] run-rustfix | ||
//@ [future] check-pass | ||
|
||
//@ [future_feature] edition: future | ||
//@ [future_feature] compile-flags: -Z unstable-options | ||
|
||
#![cfg_attr(future_feature, feature(explicit_extern_abis))] | ||
#![cfg_attr(current_feature, feature(explicit_extern_abis))] | ||
|
||
extern "C" fn _foo() {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
unsafe extern "C" fn _bar() {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
unsafe extern "C" {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
tests/ui/feature-gates/feature-gate-explicit-extern-abis.current_feature.stderr
This file contains hidden or 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,22 @@ | ||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:27:1 | ||
| | ||
LL | extern fn _foo() {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
| | ||
= note: `#[warn(missing_abi)]` on by default | ||
|
||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:33:8 | ||
| | ||
LL | unsafe extern fn _bar() {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
|
||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:39:8 | ||
| | ||
LL | unsafe extern {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
|
||
warning: 3 warnings emitted | ||
|
45 changes: 45 additions & 0 deletions
45
tests/ui/feature-gates/feature-gate-explicit-extern-abis.future.fixed
This file contains hidden or 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,45 @@ | ||
// The purpose of this feature gate is to make something into a hard error in a | ||
// future edition. Consequently, this test differs from most other feature gate | ||
// tests. Instead of verifying that an error occurs when the feature gate is | ||
// missing, it ensures that the hard error is only produced with the feature | ||
// gate is present in the `future` edition -- and otherwise that only a warning | ||
// is emitted. | ||
|
||
//@ revisions: current current_feature future future_feature | ||
|
||
//@ [current] run-rustfix | ||
//@ [current] check-pass | ||
|
||
//@ [current_feature] run-rustfix | ||
//@ [current_feature] check-pass | ||
|
||
//@ [future] edition: future | ||
//@ [future] compile-flags: -Z unstable-options | ||
//@ [future] run-rustfix | ||
//@ [future] check-pass | ||
|
||
//@ [future_feature] edition: future | ||
//@ [future_feature] compile-flags: -Z unstable-options | ||
|
||
#![cfg_attr(future_feature, feature(explicit_extern_abis))] | ||
#![cfg_attr(current_feature, feature(explicit_extern_abis))] | ||
|
||
extern "C" fn _foo() {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
unsafe extern "C" fn _bar() {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
unsafe extern "C" {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
tests/ui/feature-gates/feature-gate-explicit-extern-abis.future.stderr
This file contains hidden or 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,22 @@ | ||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:27:1 | ||
| | ||
LL | extern fn _foo() {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
| | ||
= note: `#[warn(missing_abi)]` on by default | ||
|
||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:33:8 | ||
| | ||
LL | unsafe extern fn _bar() {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
|
||
warning: `extern` declarations without an explicit ABI are deprecated | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:39:8 | ||
| | ||
LL | unsafe extern {} | ||
| ^^^^^^ help: explicitly specify the "C" ABI: `extern "C"` | ||
|
||
warning: 3 warnings emitted | ||
|
26 changes: 26 additions & 0 deletions
26
tests/ui/feature-gates/feature-gate-explicit-extern-abis.future_feature.stderr
This file contains hidden or 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,26 @@ | ||
error: `extern` declarations without an explicit ABI are disallowed | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:27:1 | ||
| | ||
LL | extern fn _foo() {} | ||
| ^^^^^^ help: specify an ABI: `extern "<abi>"` | ||
| | ||
= help: prior to Rust 2024, a default ABI was inferred | ||
|
||
error: `extern` declarations without an explicit ABI are disallowed | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:33:8 | ||
| | ||
LL | unsafe extern fn _bar() {} | ||
| ^^^^^^ help: specify an ABI: `extern "<abi>"` | ||
| | ||
= help: prior to Rust 2024, a default ABI was inferred | ||
|
||
error: `extern` declarations without an explicit ABI are disallowed | ||
--> $DIR/feature-gate-explicit-extern-abis.rs:39:8 | ||
| | ||
LL | unsafe extern {} | ||
| ^^^^^^ help: specify an ABI: `extern "<abi>"` | ||
| | ||
= help: prior to Rust 2024, a default ABI was inferred | ||
|
||
error: aborting due to 3 previous errors | ||
|
45 changes: 45 additions & 0 deletions
45
tests/ui/feature-gates/feature-gate-explicit-extern-abis.rs
This file contains hidden or 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,45 @@ | ||
// The purpose of this feature gate is to make something into a hard error in a | ||
// future edition. Consequently, this test differs from most other feature gate | ||
// tests. Instead of verifying that an error occurs when the feature gate is | ||
// missing, it ensures that the hard error is only produced with the feature | ||
// gate is present in the `future` edition -- and otherwise that only a warning | ||
// is emitted. | ||
|
||
//@ revisions: current current_feature future future_feature | ||
|
||
//@ [current] run-rustfix | ||
//@ [current] check-pass | ||
|
||
//@ [current_feature] run-rustfix | ||
//@ [current_feature] check-pass | ||
|
||
//@ [future] edition: future | ||
//@ [future] compile-flags: -Z unstable-options | ||
//@ [future] run-rustfix | ||
//@ [future] check-pass | ||
|
||
//@ [future_feature] edition: future | ||
//@ [future_feature] compile-flags: -Z unstable-options | ||
|
||
#![cfg_attr(future_feature, feature(explicit_extern_abis))] | ||
#![cfg_attr(current_feature, feature(explicit_extern_abis))] | ||
|
||
extern fn _foo() {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
unsafe extern fn _bar() {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
obeis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
unsafe extern {} | ||
//[current]~^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[current_feature]~^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future]~^^^ WARN `extern` declarations without an explicit ABI are deprecated | ||
//[future_feature]~^^^^ ERROR `extern` declarations without an explicit ABI are disallowed | ||
|
||
fn main() {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.