diff options
| author | mbartlett21 <mjmouse9999@gmail.com> | 2022-05-17 07:24:47 +0000 |
|---|---|---|
| committer | mbartlett21 <mjmouse9999@gmail.com> | 2022-05-17 07:24:47 +0000 |
| commit | cdc12edb4c18aadad2e24d1f988a30bcb17964bb (patch) | |
| tree | 1d82174010bbfde3de4a2ccf188a6970a3ed6e50 /src/test/ui/consts | |
| parent | 56649bb844ebf3d1861b3ee1d2616ccd22aab851 (diff) | |
| download | rust-cdc12edb4c18aadad2e24d1f988a30bcb17964bb.tar.gz rust-cdc12edb4c18aadad2e24d1f988a30bcb17964bb.zip | |
Add a test for fn pointer calls in consts
Diffstat (limited to 'src/test/ui/consts')
| -rw-r--r-- | src/test/ui/consts/const-fn-ptr.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/consts/const-fn-ptr.stderr | 20 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-fn-ptr.rs b/src/test/ui/consts/const-fn-ptr.rs new file mode 100644 index 00000000000..b1befdf06af --- /dev/null +++ b/src/test/ui/consts/const-fn-ptr.rs @@ -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() {} diff --git a/src/test/ui/consts/const-fn-ptr.stderr b/src/test/ui/consts/const-fn-ptr.stderr new file mode 100644 index 00000000000..84b02a25ec8 --- /dev/null +++ b/src/test/ui/consts/const-fn-ptr.stderr @@ -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 + |
