Skip to content

Commit 8b0f5ac

Browse files
committed
Add tests for mutable borrows in const fns
1 parent bb2a423 commit 8b0f5ac

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
foo(&mut 5);
3+
}
4+
5+
const fn foo(x: &mut i32) -> i32 { //~ ERROR mutable references in const fn are unstable
6+
*x + 1
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0723]: mutable references in const fn are unstable
2+
--> $DIR/feature-gate-const_fn_mut_refs.rs:5:14
3+
|
4+
LL | const fn foo(x: &mut i32) -> i32 {
5+
| ^
6+
|
7+
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
8+
= help: add `#![feature(const_fn)]` to the crate attributes to enable
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0723`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-pass
2+
3+
#![feature(const_fn_mut_refs)]
4+
5+
struct Foo {
6+
x: i32
7+
}
8+
9+
const fn bar(foo: &mut Foo) -> i32 {
10+
foo.x + 1
11+
}
12+
13+
fn main() {
14+
assert_eq!(bar(&mut Foo{x: 0}), 1);
15+
}

0 commit comments

Comments
 (0)