mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
Add a test for fn pointer calls in consts
This commit is contained in:
parent
56649bb844
commit
cdc12edb4c
16
src/test/ui/consts/const-fn-ptr.rs
Normal file
16
src/test/ui/consts/const-fn-ptr.rs
Normal 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() {}
|
20
src/test/ui/consts/const-fn-ptr.stderr
Normal file
20
src/test/ui/consts/const-fn-ptr.stderr
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user