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.
31 fn get_v1<'v>(a: &'v A) -> &'v int {
32 // Region inferencer must deduce that &v < L2 < L1
33 let foo = &a.value; // L1
37 fn get_v2<'v>(a: &'v A, i: uint) -> &'v int {
42 fn get_v3<'v>(a: &'v A, i: uint) -> &'v int {
47 fn get_v4<'v>(a: &'v A, _i: uint) -> &'v int {
52 fn get_v5<'v>(a: &'v A, _i: uint) -> &'v int {
57 fn get_v6_a<'v>(a: &'v A, _i: uint) -> &'v int {
64 fn get_v6_b<'v>(a: &'v A, _i: uint) -> &'v int {
66 A { value: B { v6: Some(ref v), .. } } => &v.f,
71 fn get_v6_c<'v>(a: &'v A, _i: uint) -> &'v int {
73 &A { value: B { v6: Some(ref v), .. } } => &v.f,
78 fn get_v5_ref<'v>(a: &'v A, _i: uint) -> &'v int {
80 &B {v5: ~C {f: ref v}, ..} => v
85 let a = A {value: B {v1: 22,
90 v6: Some(C { f: 31 })}};
93 assert_eq!(*p, a.value.v1);
95 let p = get_v2(&a, 1);
96 assert_eq!(*p, a.value.v2[1]);
98 let p = get_v3(&a, 1);
99 assert_eq!(*p, a.value.v3[1]);
101 let p = get_v4(&a, 1);
102 assert_eq!(*p, a.value.v4.f);
104 let p = get_v5(&a, 1);
105 assert_eq!(*p, a.value.v5.f);
107 let p = get_v6_a(&a, 1);
108 assert_eq!(*p, a.value.v6.unwrap().f);
110 let p = get_v6_b(&a, 1);
111 assert_eq!(*p, a.value.v6.unwrap().f);
113 let p = get_v6_c(&a, 1);
114 assert_eq!(*p, a.value.v6.unwrap().f);
116 let p = get_v5_ref(&a, 1);
117 assert_eq!(*p, a.value.v5.f);