about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-05-17 19:01:35 +0900
committerGitHub <noreply@github.com>2022-05-17 19:01:35 +0900
commit5fdc849bdc44b9170ee149770b590f5f0afb662f (patch)
treedbd71d04a095b330c43a368eb89ad7ff51a6da35 /src/test
parent519b6b4c77c396b6df4f4b9c20e008d4c31cbcf5 (diff)
parentcdc12edb4c18aadad2e24d1f988a30bcb17964bb (diff)
downloadrust-5fdc849bdc44b9170ee149770b590f5f0afb662f.tar.gz
rust-5fdc849bdc44b9170ee149770b590f5f0afb662f.zip
Rollup merge of #97102 - mbartlett21:fn-pointer-error, r=lcnr
Update function pointer call error message

It now uses the type of context. (fixes #97082)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/const-fn-ptr.rs16
-rw-r--r--src/test/ui/consts/const-fn-ptr.stderr20
-rw-r--r--src/test/ui/consts/issue-56164.stderr2
3 files changed, 37 insertions, 1 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
+
diff --git a/src/test/ui/consts/issue-56164.stderr b/src/test/ui/consts/issue-56164.stderr
index b997aff0e83..3b80b3486a8 100644
--- a/src/test/ui/consts/issue-56164.stderr
+++ b/src/test/ui/consts/issue-56164.stderr
@@ -7,7 +7,7 @@ LL | const fn foo() { (||{})() }
    = note: closures need an RFC before allowed to be called in constant functions
    = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
 
-error: function pointers are not allowed in const fn
+error: function pointer calls are not allowed in constant functions
   --> $DIR/issue-56164.rs:7:5
    |
 LL |     input()