Skip to content

Commit

Permalink
Allow code that just has a verus!{
Browse files Browse the repository at this point in the history
Notice that there is a lack of space between `verus!` and `{`. This was
not an issue before, when we ran rustfmt before the main verusfmt
formatter. However, with #23, we changed the ordering to help with
prettier error reports. Nonetheless, without rustfmt jumping in and
adding in that space, the parser would not dive into anything that was a
`verus!{...`, and thus would not format anything.

Turns out, due to this exact thing, some tests in our test suite were
not even running; thus they started to fail once the issue was fixed.
I've fixed up these tests now (in the same commit)
  • Loading branch information
jaybosamiya committed Jan 18, 2024
1 parent e477694 commit 7c7f4a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/verus.pest
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ file = {

/// Region of code that doesn't contain any Verus macro use whatsoever
non_verus = @{
(!("verus!" ~ WHITESPACE ~ "{") ~ ANY)*
(!("verus!" ~ WHITESPACE* ~ "{") ~ ANY)*
}

/// An actual use of the `verus! { ... }` macro
Expand Down
34 changes: 19 additions & 15 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,25 @@ global layout S<u32> is size == 8, align == 4;
fn verus_let() {
let file = r#"
verus!{
pub fn test() {
let Some((key, val)) = cur else {
panic!() /* covered by while condition */
};
let Some((key, val)) = cur else { panic!() };
}
}
"#;

assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus!{
let Some((key, val)) = cur else {
panic!() /* covered by while condition */
};
verus! {
pub fn test() {
let Some((key, val)) = cur else { panic!() /* covered by while condition */ };
let Some((key, val)) = cur else { panic!() };
}
} // verus!
"###);
}

Expand Down Expand Up @@ -366,7 +369,7 @@ fn assert_by_test() {
reveal(f1); // reveal f1's definition just inside this block
};
assert(f1(3) > 3);
assert(forall|x: int| x < 10 implies x < 11) by {
assert forall|x: int| x < 10 implies x < 11 by {
reveal(f1);
};
}
Expand All @@ -375,11 +378,10 @@ fn assert_by_test() {
"#;

assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus!{
verus! {
pub fn test_function(x: bool, y: bool) -> u32
by (nonlinear_arith)
{
by (nonlinear_arith) {
assert(x) by (bit_vector);
assert(f1(3)) by {
reveal(f1);
Expand All @@ -403,12 +405,12 @@ fn assert_by_test() {
reveal(f1); // reveal f1's definition just inside this block
};
assert(f1(3) > 3);
assert(forall|x: int| x < 10 implies x < 11) by {
assert forall|x: int| x < 10 implies x < 11 by {
reveal(f1);
};
}
}
} // verus!
"###);
}

Expand All @@ -434,22 +436,24 @@ verus!{
"#;

assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus!{
verus! {
println!("{} {} {}",
println!("{} {} {}",
very_very_very_very_very_very_long_e1 + 42,
very_very_very_very_very_very_long_e2,
very_very_very_very_very_very_long_e3
);
unknown_macro1!("{} {} {}", very_very_very_very_very_very_long_e1, very_very_very_very_very_very_long_e2, very_very_very_very_very_very_long_e3);
unknown_macro2!("
unknown_macro1!("{} {} {}", very_very_very_very_very_very_long_e1, very_very_very_very_very_very_long_e2, very_very_very_very_very_very_long_e3);
unknown_macro2!("
intro h1;
simpl;
cong;
done;
");
}
} // verus!
"###);
}

Expand Down

0 comments on commit 7c7f4a8

Please sign in to comment.