Skip to content

Commit d975ae5

Browse files
committed
test(const_eval): add test cases for rust-lang#114994
- add new testcase for TypeVisitor on const-eval mutable ref check
1 parent fd1ccbc commit d975ae5

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// This checks that function pointer signatures that are referenced mutably
2+
// but contain a &mut T parameter still fail in a constant context: see issue #114994.
3+
//
4+
// check-fail
5+
6+
const fn use_mut_const_fn(_f: &mut fn(&mut String)) { //~ ERROR mutable references are not allowed in constant functions
7+
()
8+
}
9+
10+
const fn use_mut_const_tuple_fn(_f: (fn(), &mut u32)) { //~ ERROR mutable references are not allowed in constant functions
11+
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0658]: mutable references are not allowed in constant functions
2+
--> $DIR/issue-114994-fail.rs:6:27
3+
|
4+
LL | const fn use_mut_const_fn(_f: &mut fn(&mut String)) {
5+
| ^^
6+
|
7+
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
8+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
9+
10+
error[E0658]: mutable references are not allowed in constant functions
11+
--> $DIR/issue-114994-fail.rs:10:33
12+
|
13+
LL | const fn use_mut_const_tuple_fn(_f: (fn(), &mut u32)) {
14+
| ^^
15+
|
16+
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
17+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0658`.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This checks that function pointer signatures containing &mut T types
2+
// work in a constant context: see issue #114994.
3+
//
4+
// check-pass
5+
6+
const fn use_const_fn(_f: fn(&mut String)) {
7+
()
8+
}
9+
10+
const fn get_some_fn() -> fn(&mut String) {
11+
String::clear
12+
}
13+
14+
const fn some_const_fn() {
15+
let _f: fn(&mut String) = String::clear;
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)