]> git.lizzy.rs Git - rust.git/blob - tests/ui/regions/regions-free-region-ordering-incorrect.rs
internally change regions to be covariant
[rust.git] / tests / ui / regions / regions-free-region-ordering-incorrect.rs
1 // Test that free regions ordering only goes one way. That is,
2 // we have `&'a Node<'b, T>`, which implies that `'a <= 'b`,
3 // but not `'b <= 'a`. Hence, returning `&self.val` (which has lifetime
4 // `'a`) where `'b` is expected yields an error.
5 //
6 // This test began its life as a test for issue #4325.
7
8 struct Node<'b, T: 'b> {
9     val: T,
10     next: Option<&'b Node<'b, T>>
11 }
12
13 impl<'b, T> Node<'b, T> {
14     fn get<'a>(&'a self) -> &'b T {
15         match self.next { //~ ERROR lifetime may not live long enough
16             Some(ref next) => next.get(),
17             None => &self.val
18         }
19     }
20 }
21
22 fn main() {}