diff --git a/src/test/ui/consts/const-eval/feature-gate-const_fn_mut_refs.rs b/src/test/ui/consts/const-eval/feature-gate-const_fn_mut_refs.rs new file mode 100644 index 000000000000..2207599815ee --- /dev/null +++ b/src/test/ui/consts/const-eval/feature-gate-const_fn_mut_refs.rs @@ -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 +} diff --git a/src/test/ui/consts/const-eval/feature-gate-const_fn_mut_refs.stderr b/src/test/ui/consts/const-eval/feature-gate-const_fn_mut_refs.stderr new file mode 100644 index 000000000000..26a61d38f8c3 --- /dev/null +++ b/src/test/ui/consts/const-eval/feature-gate-const_fn_mut_refs.stderr @@ -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`. diff --git a/src/test/ui/consts/const_fn_mut_refs.rs b/src/test/ui/consts/const_fn_mut_refs.rs new file mode 100644 index 000000000000..764c45b386b0 --- /dev/null +++ b/src/test/ui/consts/const_fn_mut_refs.rs @@ -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); +}