mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 01:34:21 +00:00
test(const_eval): add test cases for #114994
- add new testcase for TypeVisitor on const-eval mutable ref check
This commit is contained in:
parent
fd1ccbc68d
commit
d975ae5027
14
tests/ui/consts/const-eval/issue-114994-fail.rs
Normal file
14
tests/ui/consts/const-eval/issue-114994-fail.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// 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
|
||||
()
|
||||
}
|
||||
|
||||
const fn use_mut_const_tuple_fn(_f: (fn(), &mut u32)) { //~ ERROR mutable references are not allowed in constant functions
|
||||
|
||||
}
|
||||
|
||||
fn main() {}
|
21
tests/ui/consts/const-eval/issue-114994-fail.stderr
Normal file
21
tests/ui/consts/const-eval/issue-114994-fail.stderr
Normal file
@ -0,0 +1,21 @@
|
||||
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[E0658]: mutable references are not allowed in constant functions
|
||||
--> $DIR/issue-114994-fail.rs:10:33
|
||||
|
|
||||
LL | const fn use_mut_const_tuple_fn(_f: (fn(), &mut u32)) {
|
||||
| ^^
|
||||
|
|
||||
= 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 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
18
tests/ui/consts/const-eval/issue-114994.rs
Normal file
18
tests/ui/consts/const-eval/issue-114994.rs
Normal file
@ -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() {}
|
Loading…
Reference in New Issue
Block a user