-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Experimentally add ffi_const
and ffi_pure
extern fn attributes
#58327
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
Closed
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d8344ff
Add ffi_const and ffi_pure extern fn attributes
gnzlbg bf149c0
Use the term foreign function in errors
gnzlbg 945cbe4
Use pattern to match attributes
gnzlbg 736c437
Fix attribute check
gnzlbg 3adeddd
Fix tidy
gnzlbg effaf14
Update doc of `ffi_const`
Centril 26eb8b0
Document in unstable book; check that const functions are not pure, r…
gnzlbg c11a27f
Fix tests
gnzlbg d663711
Tidy book
gnzlbg a3d0f3c
Fix typos
gnzlbg 3770725
Do not emit incorrect IR on error
gnzlbg 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// compile-flags: -C no-prepopulate-passes | ||
#![crate_type = "lib"] | ||
#![feature(ffi_const)] | ||
|
||
pub fn bar() { unsafe { foo() } } | ||
|
||
extern { | ||
// CHECK-LABEL: declare void @foo() | ||
// CHECK-SAME: [[ATTRS:#[0-9]+]] | ||
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readnone{{.*}} } | ||
#[ffi_const] pub fn foo(); | ||
} |
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,12 @@ | ||
// compile-flags: -C no-prepopulate-passes | ||
#![crate_type = "lib"] | ||
#![feature(ffi_pure)] | ||
|
||
pub fn bar() { unsafe { foo() } } | ||
|
||
extern { | ||
// CHECK-LABEL: declare void @foo() | ||
// CHECK-SAME: [[ATTRS:#[0-9]+]] | ||
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readonly{{.*}} } | ||
#[ffi_pure] pub fn foo(); | ||
} |
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,7 @@ | ||
// ignore-tidy-linelength | ||
#![crate_type = "lib"] | ||
|
||
extern { | ||
#[ffi_const] //~ ERROR the `#[ffi_const]` attribute is an experimental feature (see issue #58328) | ||
pub fn foo(); | ||
} |
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,11 @@ | ||
error[E0658]: the `#[ffi_const]` attribute is an experimental feature (see issue #58328) | ||
--> $DIR/feature-gate-ffi_const.rs:5:5 | ||
| | ||
LL | #[ffi_const] //~ ERROR the `#[ffi_const]` attribute is an experimental feature (see issue #58328) | ||
| ^^^^^^^^^^^^ | ||
| | ||
= help: add #![feature(ffi_const)] to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,7 @@ | ||
// ignore-tidy-linelength | ||
#![crate_type = "lib"] | ||
|
||
extern { | ||
#[ffi_pure] //~ ERROR the `#[ffi_pure]` attribute is an experimental feature (see issue #58329) | ||
pub fn foo(); | ||
} |
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,11 @@ | ||
error[E0658]: the `#[ffi_pure]` attribute is an experimental feature (see issue #58329) | ||
--> $DIR/feature-gate-ffi_pure.rs:5:5 | ||
| | ||
LL | #[ffi_pure] //~ ERROR the `#[ffi_pure]` attribute is an experimental feature (see issue #58329) | ||
| ^^^^^^^^^^^ | ||
| | ||
= help: add #![feature(ffi_pure)] to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
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,6 @@ | ||
// ignore-tidy-linelength | ||
#![feature(ffi_const)] | ||
#![crate_type = "lib"] | ||
|
||
#[ffi_const] //~ ERROR `#[ffi_const]` may only be used on foreign functions [E0725] | ||
pub fn foo() {} |
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,9 @@ | ||
error[E0725]: `#[ffi_const]` may only be used on foreign functions | ||
--> $DIR/ffi_const.rs:5:1 | ||
| | ||
LL | #[ffi_const] //~ ERROR `#[ffi_const]` may only be used on foreign functions [E0725] | ||
| ^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0725`. |
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,6 @@ | ||
// ignore-tidy-linelength | ||
#![feature(ffi_pure)] | ||
#![crate_type = "lib"] | ||
|
||
#[ffi_pure] //~ ERROR `#[ffi_pure]` may only be used on foreign functions [E0724] | ||
pub fn foo() {} |
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,9 @@ | ||
error[E0724]: `#[ffi_pure]` may only be used on foreign functions | ||
--> $DIR/ffi_pure.rs:5:1 | ||
| | ||
LL | #[ffi_pure] //~ ERROR `#[ffi_pure]` may only be used on foreign functions [E0724] | ||
| ^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0724`. |
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.