2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2013-04-03 12:24:30 +00:00
|
|
|
// Test lifetimes are linked properly when we create dependent region pointers.
|
|
|
|
// Issue #3148.
|
|
|
|
|
2015-02-10 21:52:00 +00:00
|
|
|
#![feature(box_patterns)]
|
2014-03-05 23:28:08 +00:00
|
|
|
|
2013-01-25 00:24:45 +00:00
|
|
|
struct A {
|
|
|
|
value: B
|
|
|
|
}
|
|
|
|
|
|
|
|
struct B {
|
2015-03-26 00:06:52 +00:00
|
|
|
v1: isize,
|
|
|
|
v2: [isize; 3],
|
|
|
|
v3: Vec<isize> ,
|
2013-01-25 00:24:45 +00:00
|
|
|
v4: C,
|
2014-05-06 01:56:44 +00:00
|
|
|
v5: Box<C>,
|
2013-01-25 00:24:45 +00:00
|
|
|
v6: Option<C>
|
|
|
|
}
|
|
|
|
|
2015-03-30 13:38:27 +00:00
|
|
|
#[derive(Copy, Clone)]
|
2013-01-25 00:24:45 +00:00
|
|
|
struct C {
|
2015-03-26 00:06:52 +00:00
|
|
|
f: isize
|
2013-01-25 00:24:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v1(a: &A) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
// Region inferencer must deduce that &v < L2 < L1
|
|
|
|
let foo = &a.value; // L1
|
|
|
|
&foo.v1 // L2
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v2(a: &A, i: usize) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
let foo = &a.value;
|
|
|
|
&foo.v2[i]
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v3(a: &A, i: usize) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
let foo = &a.value;
|
2014-10-15 06:05:01 +00:00
|
|
|
&foo.v3[i]
|
2013-01-25 00:24:45 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v4(a: &A, _i: usize) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
let foo = &a.value;
|
|
|
|
&foo.v4.f
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v5(a: &A, _i: usize) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
let foo = &a.value;
|
|
|
|
&foo.v5.f
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v6_a(a: &A, _i: usize) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
match a.value.v6 {
|
|
|
|
Some(ref v) => &v.f,
|
2014-10-09 19:17:22 +00:00
|
|
|
None => panic!()
|
2013-01-25 00:24:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v6_b(a: &A, _i: usize) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
match *a {
|
2013-11-28 20:22:53 +00:00
|
|
|
A { value: B { v6: Some(ref v), .. } } => &v.f,
|
2014-10-09 19:17:22 +00:00
|
|
|
_ => panic!()
|
2013-01-25 00:24:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v6_c(a: &A, _i: usize) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
match a {
|
2013-11-28 20:22:53 +00:00
|
|
|
&A { value: B { v6: Some(ref v), .. } } => &v.f,
|
2014-10-09 19:17:22 +00:00
|
|
|
_ => panic!()
|
2013-01-25 00:24:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:06:52 +00:00
|
|
|
fn get_v5_ref(a: &A, _i: usize) -> &isize {
|
2013-01-25 00:24:45 +00:00
|
|
|
match &a.value {
|
2014-05-06 01:56:44 +00:00
|
|
|
&B {v5: box C {f: ref v}, ..} => v
|
2013-01-25 00:24:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2013-01-25 00:24:45 +00:00
|
|
|
let a = A {value: B {v1: 22,
|
|
|
|
v2: [23, 24, 25],
|
2016-10-29 21:54:04 +00:00
|
|
|
v3: vec![26, 27, 28],
|
2013-01-25 00:24:45 +00:00
|
|
|
v4: C { f: 29 },
|
2021-08-25 00:39:40 +00:00
|
|
|
v5: Box::new(C { f: 30 }),
|
2013-01-25 00:24:45 +00:00
|
|
|
v6: Some(C { f: 31 })}};
|
|
|
|
|
|
|
|
let p = get_v1(&a);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*p, a.value.v1);
|
2013-01-25 00:24:45 +00:00
|
|
|
|
|
|
|
let p = get_v2(&a, 1);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*p, a.value.v2[1]);
|
2013-01-25 00:24:45 +00:00
|
|
|
|
|
|
|
let p = get_v3(&a, 1);
|
2014-10-15 06:05:01 +00:00
|
|
|
assert_eq!(*p, a.value.v3[1]);
|
2013-01-25 00:24:45 +00:00
|
|
|
|
|
|
|
let p = get_v4(&a, 1);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*p, a.value.v4.f);
|
2013-01-25 00:24:45 +00:00
|
|
|
|
|
|
|
let p = get_v5(&a, 1);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*p, a.value.v5.f);
|
2013-01-25 00:24:45 +00:00
|
|
|
|
|
|
|
let p = get_v6_a(&a, 1);
|
2013-08-03 23:59:24 +00:00
|
|
|
assert_eq!(*p, a.value.v6.unwrap().f);
|
2013-01-25 00:24:45 +00:00
|
|
|
|
|
|
|
let p = get_v6_b(&a, 1);
|
2013-08-03 23:59:24 +00:00
|
|
|
assert_eq!(*p, a.value.v6.unwrap().f);
|
2013-01-25 00:24:45 +00:00
|
|
|
|
|
|
|
let p = get_v6_c(&a, 1);
|
2013-08-03 23:59:24 +00:00
|
|
|
assert_eq!(*p, a.value.v6.unwrap().f);
|
2013-01-25 03:33:48 +00:00
|
|
|
|
|
|
|
let p = get_v5_ref(&a, 1);
|
2013-05-19 02:02:45 +00:00
|
|
|
assert_eq!(*p, a.value.v5.f);
|
2013-01-25 00:24:45 +00:00
|
|
|
}
|