]> git.lizzy.rs Git - rust.git/blob - tests/ui/regions/regions-lub-ref-ref-rc.rs
internally change regions to be covariant
[rust.git] / tests / ui / regions / regions-lub-ref-ref-rc.rs
1 // run-pass
2 #![allow(dead_code)]
3 // Test a corner case of LUB coercion. In this case, one arm of the
4 // match requires a deref coercion and the other doesn't, and there
5 // is an extra `&` on the `rc`. We want to be sure that the lifetime
6 // assigned to this `&rc` value is not `'a` but something smaller.  In
7 // other words, the type from `rc` is `&'a Rc<String>` and the type
8 // from `&rc` should be `&'x &'a Rc<String>`, where `'x` is something
9 // small.
10
11 use std::rc::Rc;
12
13 #[derive(Clone)]
14 enum Cached<'mir> {
15     Ref(&'mir String),
16     Owned(Rc<String>),
17 }
18
19 impl<'mir> Cached<'mir> {
20     fn get_ref<'a>(&'a self) -> &'a String {
21         match *self {
22             Cached::Ref(r) => r,
23             Cached::Owned(ref rc) => &rc,
24         }
25     }
26 }
27
28 fn main() { }