Lifetime elision causes code to stop compiling
Now that !5 (merged) has been merged, contracts can better handle pre- and post-conditions on functions involving references, like this one:
#[requires(i < s.len())]
#[ensures(true)]
fn idx<'a>(s: &'a [u8], i: usize) -> &'a u8 {
&mut s[i]
}
The preceding example could be written more concisely by eliding the lifetime 'a, but at the moment this results in a lifetime inference error. contracts wraps the function body in a closure, and because closures do not support lifetime elision, the connection between the input and output lifetime is lost and the example fails to compile. Even if closures did support lifetime elision, we would still have problems around method receivers (e.g. &self): They are given higher priority by lifetime elision but must be transformed into a normal argument inside the closure.
AFAICS, The solution to this is to perform lifetime elision ourselves. This will likely be error-prone, since we only have access to the AST, not to any type information. However, it should be possible to do a limited version that handles 95% of cases. The remainder can always be manually annotated by the user.