Add tests for mutable borrows in const fns

This commit is contained in:
Christian Poveda 2019-11-21 08:45:34 -05:00
parent bb2a423894
commit 8b0f5acfcb
3 changed files with 34 additions and 0 deletions

View file

@ -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
}

View file

@ -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`.

View 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);
}