]> git.lizzy.rs Git - rust.git/blob - src/test/ui/match/match-ref-mut-stability.rs
Auto merge of #106349 - LeSeulArtichaut:dyn-star-tracking-issue, r=jackh726
[rust.git] / src / test / ui / match / match-ref-mut-stability.rs
1 // Check that `ref mut` variables don't change address between the match guard
2 // and the arm expression.
3
4 // run-pass
5
6 // Test that z always point to the same temporary.
7 fn referent_stability() {
8     let p;
9     match 0 {
10         ref mut z if { p = z as *const _; true } => assert_eq!(p, z as *const _),
11         _ => unreachable!(),
12     };
13 }
14
15 // Test that z is always effectively the same variable.
16 fn variable_stability() {
17     let p;
18     match 0 {
19         ref mut z if { p = &z as *const _; true } => assert_eq!(p, &z as *const _),
20         _ => unreachable!(),
21     };
22 }
23
24 // Test that a borrow of *z can cross from the guard to the arm.
25 fn persist_borrow() {
26     let r;
27     match 0 {
28         ref mut z if { r = z as &_; true } => assert_eq!(*r, 0),
29         _ => unreachable!(),
30     }
31 }
32
33 fn main() {
34     referent_stability();
35     variable_stability();
36     persist_borrow();
37 }