1
Fork 0

Add tests for #[ffi_const] and #[ffi_pure] function attributes

Based on the work of gnzlbg <gonzalobg88@gmail.com>.
This commit is contained in:
Matthias Schiffer 2020-04-14 00:21:19 +02:00
parent abc236414b
commit a7d7f0bbe9
12 changed files with 105 additions and 0 deletions

View file

@ -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();
}

View file

@ -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();
}

View file

@ -0,0 +1,6 @@
#![crate_type = "lib"]
extern {
#[ffi_const] //~ ERROR the `#[ffi_const]` attribute is an experimental feature
pub fn foo();
}

View file

@ -0,0 +1,12 @@
error[E0658]: the `#[ffi_const]` attribute is an experimental feature
--> $DIR/feature-gate-ffi_const.rs:4:5
|
LL | #[ffi_const]
| ^^^^^^^^^^^^
|
= note: see issue #58328 <https://github.com/rust-lang/rust/issues/58328> for more information
= 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`.

View file

@ -0,0 +1,6 @@
#![crate_type = "lib"]
extern {
#[ffi_pure] //~ ERROR the `#[ffi_pure]` attribute is an experimental feature
pub fn foo();
}

View file

@ -0,0 +1,12 @@
error[E0658]: the `#[ffi_pure]` attribute is an experimental feature
--> $DIR/feature-gate-ffi_pure.rs:4:5
|
LL | #[ffi_pure]
| ^^^^^^^^^^^
|
= note: see issue #58329 <https://github.com/rust-lang/rust/issues/58329> for more information
= 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`.

5
src/test/ui/ffi_const.rs Normal file
View file

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

View file

@ -0,0 +1,8 @@
error[E0756]: `#[ffi_const]` may only be used on foreign functions
--> $DIR/ffi_const.rs:4:1
|
LL | #[ffi_const]
| ^^^^^^^^^^^^
error: aborting due to previous error

11
src/test/ui/ffi_const2.rs Normal file
View file

@ -0,0 +1,11 @@
#![feature(ffi_const, ffi_pure)]
extern {
#[ffi_pure] //~ ERROR `#[ffi_const]` function cannot be `#[ffi_pure]`
#[ffi_const]
pub fn baz();
}
fn main() {
unsafe { baz() };
}

View file

@ -0,0 +1,8 @@
error[E0757]: `#[ffi_const]` function cannot be `#[ffi_pure]`
--> $DIR/ffi_const2.rs:4:5
|
LL | #[ffi_pure]
| ^^^^^^^^^^^
error: aborting due to previous error

5
src/test/ui/ffi_pure.rs Normal file
View file

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

View file

@ -0,0 +1,8 @@
error[E0755]: `#[ffi_pure]` may only be used on foreign functions
--> $DIR/ffi_pure.rs:4:1
|
LL | #[ffi_pure]
| ^^^^^^^^^^^
error: aborting due to previous error