From e0c75f7f5ed368f07a2760e8e97b5e252f721e5a Mon Sep 17 00:00:00 2001 From: Evan Merlock Date: Wed, 20 Sep 2023 18:53:07 -0500 Subject: [PATCH] test(const_eval): add test cases for #114994 --- .../ui/consts/const-eval/issue-114994-fail.rs | 10 ++++++++++ .../consts/const-eval/issue-114994-fail.stderr | 12 ++++++++++++ tests/ui/consts/const-eval/issue-114994.rs | 18 ++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 tests/ui/consts/const-eval/issue-114994-fail.rs create mode 100644 tests/ui/consts/const-eval/issue-114994-fail.stderr create mode 100644 tests/ui/consts/const-eval/issue-114994.rs diff --git a/tests/ui/consts/const-eval/issue-114994-fail.rs b/tests/ui/consts/const-eval/issue-114994-fail.rs new file mode 100644 index 0000000000000..adb51fa09b796 --- /dev/null +++ b/tests/ui/consts/const-eval/issue-114994-fail.rs @@ -0,0 +1,10 @@ +// This checks that function pointer signatures that are referenced mutably +// but contain a &mut T parameter still fail in a constant context: see issue #114994. +// +// check-fail + +const fn use_mut_const_fn(_f: &mut fn(&mut String)) { //~ ERROR mutable references are not allowed in constant functions + () +} + +fn main() {} diff --git a/tests/ui/consts/const-eval/issue-114994-fail.stderr b/tests/ui/consts/const-eval/issue-114994-fail.stderr new file mode 100644 index 0000000000000..3c8ad57db2a2f --- /dev/null +++ b/tests/ui/consts/const-eval/issue-114994-fail.stderr @@ -0,0 +1,12 @@ +error[E0658]: mutable references are not allowed in constant functions + --> $DIR/issue-114994-fail.rs:6:27 + | +LL | const fn use_mut_const_fn(_f: &mut fn(&mut String)) { + | ^^ + | + = note: see issue #57349 for more information + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/consts/const-eval/issue-114994.rs b/tests/ui/consts/const-eval/issue-114994.rs new file mode 100644 index 0000000000000..a4cb2e61e5f6f --- /dev/null +++ b/tests/ui/consts/const-eval/issue-114994.rs @@ -0,0 +1,18 @@ +// This checks that function pointer signatures containing &mut T types +// work in a constant context: see issue #114994. +// +// check-pass + +const fn use_const_fn(_f: fn(&mut String)) { + () +} + +const fn get_some_fn() -> fn(&mut String) { + String::clear +} + +const fn some_const_fn() { + let _f: fn(&mut String) = String::clear; +} + +fn main() {}