1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use should_it_compile::should_not_compile;
should_not_compile!({
prefix!({
use maybe_borrow::prelude::*;
});
mod pairs {
fn distinct_lifetimes() {
// should fail because a and b have different lifetimes
fn inner(mut a: &mut i32, mut b: &mut i32) {
maybe_borrow!(for<'x> |a, b| -> () {
if a == b {
return_borrowed!(());
}
})
}
}
fn lifetimes_with_common_supertype() {
// should fail because 'a and 'b are distinct despite both outliving 'c
fn inner<'a: 'c, 'b: 'c, 'c>(mut a: &'a mut i32, mut b: &'b mut i32) {
maybe_borrow!(for<'x> |a, b| -> () {
if (*a < *b) {
return_borrowed!(())
}
})
}
}
fn lifetimes_with_common_supertype_and_borrowed_return() {
// should fail because 'a and 'b are distinct despite both outliving 'c
fn inner<'a: 'c, 'b: 'c, 'c>(mut a: &'a mut i32, mut b: &'b mut i32) -> &'c mut i32 {
maybe_borrow!(for<'x> |a, b| -> &'x mut i32 {
if (*a < *b) {
return_borrowed!(a)
}
});
b
}
}
}
});