File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 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+ #![ feature( nll, bind_by_move_pattern_guards) ]
7+
8+ // Test that z always point to the same temporary.
9+ fn referent_stability ( ) {
10+ let p;
11+ match 0 {
12+ ref mut z if { p = z as * const _ ; true } => assert_eq ! ( p, z as * const _) ,
13+ _ => unreachable ! ( ) ,
14+ } ;
15+ }
16+
17+ // Test that z is always effectively the same variable.
18+ fn variable_stability ( ) {
19+ let p;
20+ match 0 {
21+ ref mut z if { p = & z as * const _ ; true } => assert_eq ! ( p, & z as * const _) ,
22+ _ => unreachable ! ( ) ,
23+ } ;
24+ }
25+
26+ // Test that a borrow of *z can cross from the guard to the arm.
27+ fn persist_borrow ( ) {
28+ let r;
29+ match 0 {
30+ ref mut z if { r = z as & _ ; true } => assert_eq ! ( * r, 0 ) ,
31+ _ => unreachable ! ( ) ,
32+ }
33+ }
34+
35+ fn main ( ) {
36+ referent_stability ( ) ;
37+ variable_stability ( ) ;
38+ persist_borrow ( ) ;
39+ }
You can’t perform that action at this time.
0 commit comments