Skip to content

Commit a7d7f0b

Browse files
committed
Add tests for #[ffi_const] and #[ffi_pure] function attributes
Based on the work of gnzlbg <[email protected]>.
1 parent abc2364 commit a7d7f0b

12 files changed

+105
-0
lines changed

Diff for: src/test/codegen/ffi-const.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -C no-prepopulate-passes
2+
#![crate_type = "lib"]
3+
#![feature(ffi_const)]
4+
5+
pub fn bar() { unsafe { foo() } }
6+
7+
extern {
8+
// CHECK-LABEL: declare void @foo()
9+
// CHECK-SAME: [[ATTRS:#[0-9]+]]
10+
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readnone{{.*}} }
11+
#[ffi_const] pub fn foo();
12+
}

Diff for: src/test/codegen/ffi-pure.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: -C no-prepopulate-passes
2+
#![crate_type = "lib"]
3+
#![feature(ffi_pure)]
4+
5+
pub fn bar() { unsafe { foo() } }
6+
7+
extern {
8+
// CHECK-LABEL: declare void @foo()
9+
// CHECK-SAME: [[ATTRS:#[0-9]+]]
10+
// CHECK-DAG: attributes [[ATTRS]] = { {{.*}}readonly{{.*}} }
11+
#[ffi_pure] pub fn foo();
12+
}

Diff for: src/test/ui/feature-gates/feature-gate-ffi_const.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_type = "lib"]
2+
3+
extern {
4+
#[ffi_const] //~ ERROR the `#[ffi_const]` attribute is an experimental feature
5+
pub fn foo();
6+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: the `#[ffi_const]` attribute is an experimental feature
2+
--> $DIR/feature-gate-ffi_const.rs:4:5
3+
|
4+
LL | #[ffi_const]
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: see issue #58328 <https://github.com/rust-lang/rust/issues/58328> for more information
8+
= help: add `#![feature(ffi_const)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

Diff for: src/test/ui/feature-gates/feature-gate-ffi_pure.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![crate_type = "lib"]
2+
3+
extern {
4+
#[ffi_pure] //~ ERROR the `#[ffi_pure]` attribute is an experimental feature
5+
pub fn foo();
6+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0658]: the `#[ffi_pure]` attribute is an experimental feature
2+
--> $DIR/feature-gate-ffi_pure.rs:4:5
3+
|
4+
LL | #[ffi_pure]
5+
| ^^^^^^^^^^^
6+
|
7+
= note: see issue #58329 <https://github.com/rust-lang/rust/issues/58329> for more information
8+
= help: add `#![feature(ffi_pure)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0658`.

Diff for: src/test/ui/ffi_const.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![feature(ffi_const)]
2+
#![crate_type = "lib"]
3+
4+
#[ffi_const] //~ ERROR `#[ffi_const]` may only be used on foreign functions
5+
pub fn foo() {}

Diff for: src/test/ui/ffi_const.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error[E0756]: `#[ffi_const]` may only be used on foreign functions
2+
--> $DIR/ffi_const.rs:4:1
3+
|
4+
LL | #[ffi_const]
5+
| ^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

Diff for: src/test/ui/ffi_const2.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(ffi_const, ffi_pure)]
2+
3+
extern {
4+
#[ffi_pure] //~ ERROR `#[ffi_const]` function cannot be `#[ffi_pure]`
5+
#[ffi_const]
6+
pub fn baz();
7+
}
8+
9+
fn main() {
10+
unsafe { baz() };
11+
}

Diff for: src/test/ui/ffi_const2.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error[E0757]: `#[ffi_const]` function cannot be `#[ffi_pure]`
2+
--> $DIR/ffi_const2.rs:4:5
3+
|
4+
LL | #[ffi_pure]
5+
| ^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

Diff for: src/test/ui/ffi_pure.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![feature(ffi_pure)]
2+
#![crate_type = "lib"]
3+
4+
#[ffi_pure] //~ ERROR `#[ffi_pure]` may only be used on foreign functions
5+
pub fn foo() {}

Diff for: src/test/ui/ffi_pure.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error[E0755]: `#[ffi_pure]` may only be used on foreign functions
2+
--> $DIR/ffi_pure.rs:4:1
3+
|
4+
LL | #[ffi_pure]
5+
| ^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)