1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // Test lifetimes are linked properly when we create dependent region pointers.
14 #![allow(unknown_features)]
15 #![feature(box_syntax)]
36 fn get_v1(a: &A) -> &int {
37 // Region inferencer must deduce that &v < L2 < L1
38 let foo = &a.value; // L1
42 fn get_v2(a: &A, i: uint) -> &int {
47 fn get_v3(a: &A, i: uint) -> &int {
52 fn get_v4(a: &A, _i: uint) -> &int {
57 fn get_v5(a: &A, _i: uint) -> &int {
62 fn get_v6_a(a: &A, _i: uint) -> &int {
69 fn get_v6_b(a: &A, _i: uint) -> &int {
71 A { value: B { v6: Some(ref v), .. } } => &v.f,
76 fn get_v6_c(a: &A, _i: uint) -> &int {
78 &A { value: B { v6: Some(ref v), .. } } => &v.f,
83 fn get_v5_ref(a: &A, _i: uint) -> &int {
85 &B {v5: box C {f: ref v}, ..} => v
90 let a = A {value: B {v1: 22,
95 v6: Some(C { f: 31 })}};
98 assert_eq!(*p, a.value.v1);
100 let p = get_v2(&a, 1);
101 assert_eq!(*p, a.value.v2[1]);
103 let p = get_v3(&a, 1);
104 assert_eq!(*p, a.value.v3[1]);
106 let p = get_v4(&a, 1);
107 assert_eq!(*p, a.value.v4.f);
109 let p = get_v5(&a, 1);
110 assert_eq!(*p, a.value.v5.f);
112 let p = get_v6_a(&a, 1);
113 assert_eq!(*p, a.value.v6.unwrap().f);
115 let p = get_v6_b(&a, 1);
116 assert_eq!(*p, a.value.v6.unwrap().f);
118 let p = get_v6_c(&a, 1);
119 assert_eq!(*p, a.value.v6.unwrap().f);
121 let p = get_v5_ref(&a, 1);
122 assert_eq!(*p, a.value.v5.f);