rust/tests/ui/regions/regions-free-region-ordering-incorrect.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

23 lines
614 B
Rust
Raw Normal View History

// Test that free regions ordering only goes one way. That is,
// we have `&'a Node<'b, T>`, which implies that `'a <= 'b`,
// but not `'b <= 'a`. Hence, returning `&self.val` (which has lifetime
// `'a`) where `'b` is expected yields an error.
//
// This test began its life as a test for issue #4325.
struct Node<'b, T: 'b> {
val: T,
next: Option<&'b Node<'b, T>>
2013-03-29 02:24:17 +00:00
}
impl<'b, T> Node<'b, T> {
fn get<'a>(&'a self) -> &'b T {
2022-04-01 17:13:25 +00:00
match self.next { //~ ERROR lifetime may not live long enough
Some(ref next) => next.get(),
2022-04-01 17:13:25 +00:00
None => &self.val
}
2013-03-29 02:24:17 +00:00
}
}
fn main() {}