2013-06-19 11:32:56 -05:00
|
|
|
// Test that free regions ordering only goes one way. That is,
|
2013-12-10 01:16:18 -06:00
|
|
|
// we have `&'a Node<'b, T>`, which implies that `'a <= 'b`,
|
2018-11-26 20:59:49 -06:00
|
|
|
// but not `'b <= 'a`. Hence, returning `&self.val` (which has lifetime
|
2013-12-10 01:16:18 -06:00
|
|
|
// `'a`) where `'b` is expected yields an error.
|
2013-06-19 11:32:56 -05:00
|
|
|
//
|
|
|
|
// This test began its life as a test for issue #4325.
|
|
|
|
|
2022-04-19 05:56:18 -05:00
|
|
|
// revisions: base nll
|
|
|
|
// ignore-compare-mode-nll
|
|
|
|
//[nll] compile-flags: -Z borrowck=mir
|
|
|
|
|
2018-11-26 20:59:49 -06:00
|
|
|
struct Node<'b, T: 'b> {
|
|
|
|
val: T,
|
|
|
|
next: Option<&'b Node<'b, T>>
|
2013-03-28 21:24:17 -05:00
|
|
|
}
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
impl<'b, T> Node<'b, T> {
|
2018-11-26 20:59:49 -06:00
|
|
|
fn get<'a>(&'a self) -> &'b T {
|
2022-04-19 05:56:18 -05:00
|
|
|
match self.next { //[nll]~ ERROR lifetime may not live long enough
|
2018-11-26 20:59:49 -06:00
|
|
|
Some(ref next) => next.get(),
|
2022-04-19 05:56:18 -05:00
|
|
|
None => &self.val //[base]~ ERROR cannot infer
|
2018-11-26 20:59:49 -06:00
|
|
|
}
|
2013-03-28 21:24:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|