Skip to content

Commit

Permalink
test(const_eval): add test cases for #114994
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanMerlock committed Sep 21, 2023
1 parent fb906c4 commit e0c75f7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/ui/consts/const-eval/issue-114994-fail.rs
Original file line number Diff line number Diff line change
@@ -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() {}
12 changes: 12 additions & 0 deletions tests/ui/consts/const-eval/issue-114994-fail.stderr
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/rust-lang/rust/issues/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`.
18 changes: 18 additions & 0 deletions tests/ui/consts/const-eval/issue-114994.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit e0c75f7

Please sign in to comment.