]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-mut-refs/const_mut_refs.rs
Rollup merge of #67094 - RalfJung:fields, r=Mark-Simulacrum
[rust.git] / src / test / ui / consts / const-mut-refs / const_mut_refs.rs
1 // run-pass
2
3 #![feature(const_mut_refs)]
4
5 struct Foo {
6     x: usize
7 }
8
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 {
22     let x = &mut foo.x;
23     *x = 2;
24     *x
25 }
26
27 const fn bazz(foo: &mut Foo) -> usize {
28     foo.x = 3;
29     foo.x
30 }
31
32 fn main() {
33     let _: [(); foo().bar()] = [(); 1];
34     let _: [(); baz(&mut foo())] = [(); 2];
35     let _: [(); bazz(&mut foo())] = [(); 3];
36 }