about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Poveda <christianpoveda@protonmail.com>2019-11-21 08:45:34 -0500
committerChristian Poveda <christianpoveda@protonmail.com>2019-12-02 09:03:41 -0500
commit8b0f5acfcbc178680f3cbec737b13bf0da6c05bd (patch)
tree5105663217e58409d363ceda176aed78001c6cb6
parentbb2a4238946563ef87eed6fe7e833ca731fa4c79 (diff)
downloadrust-8b0f5acfcbc178680f3cbec737b13bf0da6c05bd.tar.gz
rust-8b0f5acfcbc178680f3cbec737b13bf0da6c05bd.zip
Add tests for mutable borrows in const fns
-rw-r--r--src/test/ui/consts/const-eval/feature-gate-const_fn_mut_refs.rs7
-rw-r--r--src/test/ui/consts/const-eval/feature-gate-const_fn_mut_refs.stderr12
-rw-r--r--src/test/ui/consts/const_fn_mut_refs.rs15
3 files changed, 34 insertions, 0 deletions
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 00000000000..2207599815e
--- /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 00000000000..26a61d38f8c
--- /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 00000000000..764c45b386b
--- /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);
+}