Skip to content

Commit cdc12ed

Browse files
committed
Add a test for fn pointer calls in consts
1 parent 56649bb commit cdc12ed

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/test/ui/consts/const-fn-ptr.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const fn make_fn_ptr() -> fn() {
2+
|| {}
3+
}
4+
5+
static STAT: () = make_fn_ptr()();
6+
//~^ ERROR function pointer
7+
8+
const CONST: () = make_fn_ptr()();
9+
//~^ ERROR function pointer
10+
11+
const fn call_ptr() {
12+
make_fn_ptr()();
13+
//~^ ERROR function pointer
14+
}
15+
16+
fn main() {}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: function pointer calls are not allowed in statics
2+
--> $DIR/const-fn-ptr.rs:5:19
3+
|
4+
LL | static STAT: () = make_fn_ptr()();
5+
| ^^^^^^^^^^^^^^^
6+
7+
error: function pointer calls are not allowed in constants
8+
--> $DIR/const-fn-ptr.rs:8:19
9+
|
10+
LL | const CONST: () = make_fn_ptr()();
11+
| ^^^^^^^^^^^^^^^
12+
13+
error: function pointer calls are not allowed in constant functions
14+
--> $DIR/const-fn-ptr.rs:12:5
15+
|
16+
LL | make_fn_ptr()();
17+
| ^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
20+

0 commit comments

Comments
 (0)