prusti-dev
prusti-dev copied to clipboard
Failing parsing of `... && if let ...`
Prusti fails to parse the following contract.
use prusti_contracts::*;
#[requires(
true &&
if let Some(_) = x { // <-- ERROR: expected `=`
true
} else {
true
}
)]
fn foo(x: &Option<i32>) { }
This example shows another issue when parsing &&
, predicate
accepts syntax that is not allowed in normal Rust code:
use prusti_contracts::*;
predicate!{
fn test_pred<T>(x: &Option<T>) -> bool {
match x {
_ => true,
} && true
}
}
fn test_fn<T>(x: &Option<T>) -> bool {
match x {
_ => true,
} && true
}
Prusti accepts test_pred
, but test_fn
fails to compile with:
mismatched types
expected `bool`, found `&&bool`
predicate_parsing.rs(11, 33): expected `bool` because of return type
predicate_parsing.rs(12, 5): parentheses are required to parse this as an expression: `(`, `)`
Adding brackets around the match
works in both cases:
predicate!{
fn test_pred_fixed<T>(x: &Option<T>) -> bool {
(match x {
_ => true,
}) && true
}
}
fn test_fn_fixed<T>(x: &Option<T>) -> bool {
(match x {
_ => true,
}) && true
}