Skip to content

Commit e31a136

Browse files
committed
Extend test for const_mut_refs feature
1 parent d92e9b7 commit e31a136

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

src/test/ui/consts/const-mut-refs/const_mut_refs.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,31 @@ struct Foo {
66
x: usize
77
}
88

9-
const fn bar(foo: &mut Foo) -> usize {
9+
const fn foo() -> Foo {
10+
Foo { x: 0 }
11+
}
12+
13+
impl Foo {
14+
const fn bar(&mut self) -> usize {
15+
self.x = 1;
16+
self.x
17+
}
18+
19+
}
20+
21+
const fn baz(foo: &mut Foo) -> usize {
1022
let x = &mut foo.x;
11-
*x = 1;
23+
*x = 2;
1224
*x
1325
}
1426

27+
const fn bazz(foo: &mut Foo) -> usize {
28+
foo.x = 3;
29+
foo.x
30+
}
31+
1532
fn main() {
16-
let _: [(); bar(&mut Foo { x: 0 })] = [(); 1];
33+
let _: [(); foo().bar()] = [(); 1];
34+
let _: [(); baz(&mut foo())] = [(); 2];
35+
let _: [(); bazz(&mut foo())] = [(); 3];
1736
}

0 commit comments

Comments
 (0)