Add a test for fn pointer calls in consts

This commit is contained in:
mbartlett21 2022-05-17 07:24:47 +00:00
parent 56649bb844
commit cdc12edb4c
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,16 @@
const fn make_fn_ptr() -> fn() {
|| {}
}
static STAT: () = make_fn_ptr()();
//~^ ERROR function pointer
const CONST: () = make_fn_ptr()();
//~^ ERROR function pointer
const fn call_ptr() {
make_fn_ptr()();
//~^ ERROR function pointer
}
fn main() {}

View File

@ -0,0 +1,20 @@
error: function pointer calls are not allowed in statics
--> $DIR/const-fn-ptr.rs:5:19
|
LL | static STAT: () = make_fn_ptr()();
| ^^^^^^^^^^^^^^^
error: function pointer calls are not allowed in constants
--> $DIR/const-fn-ptr.rs:8:19
|
LL | const CONST: () = make_fn_ptr()();
| ^^^^^^^^^^^^^^^
error: function pointer calls are not allowed in constant functions
--> $DIR/const-fn-ptr.rs:12:5
|
LL | make_fn_ptr()();
| ^^^^^^^^^^^^^^^
error: aborting due to 3 previous errors