Add tests for mutable borrows in const fns
This commit is contained in:
parent
bb2a423894
commit
8b0f5acfcb
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
foo(&mut 5);
|
||||
}
|
||||
|
||||
const fn foo(x: &mut i32) -> i32 { //~ ERROR mutable references in const fn are unstable
|
||||
*x + 1
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
error[E0723]: mutable references in const fn are unstable
|
||||
--> $DIR/feature-gate-const_fn_mut_refs.rs:5:14
|
||||
|
|
||||
LL | const fn foo(x: &mut i32) -> i32 {
|
||||
| ^
|
||||
|
|
||||
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
|
||||
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0723`.
|
15
src/test/ui/consts/const_fn_mut_refs.rs
Normal file
15
src/test/ui/consts/const_fn_mut_refs.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(const_fn_mut_refs)]
|
||||
|
||||
struct Foo {
|
||||
x: i32
|
||||
}
|
||||
|
||||
const fn bar(foo: &mut Foo) -> i32 {
|
||||
foo.x + 1
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(bar(&mut Foo{x: 0}), 1);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user