From 56649bb844ebf3d1861b3ee1d2616ccd22aab851 Mon Sep 17 00:00:00 2001 From: mbartlett21 Date: Tue, 17 May 2022 04:11:18 +0000 Subject: [PATCH] Update function pointer call error message It now uses the type of context. (issue 97082) --- compiler/rustc_const_eval/src/transform/check_consts/ops.rs | 5 ++++- src/test/ui/consts/issue-56164.stderr | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 122471b208d..4e71baa77b0 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -89,7 +89,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallIndirect { ccx: &ConstCx<'_, 'tcx>, span: Span, ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { - ccx.tcx.sess.struct_span_err(span, "function pointers are not allowed in const fn") + ccx.tcx.sess.struct_span_err( + span, + &format!("function pointer calls are not allowed in {}s", ccx.const_kind()), + ) } } 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()