Skip to content

Commit

Permalink
Support parsing for const generic literals
Browse files Browse the repository at this point in the history
  • Loading branch information
jaybosamiya-ms committed Sep 23, 2024
1 parent 20cabe1 commit 55354cd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* Support parsing for const generic literals

# v0.4.1

* Minor fix to prevent panic on formatting files containing unbalanced parentheses in strings/chars/...
Expand Down
8 changes: 7 additions & 1 deletion src/verus.pest
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,13 @@ lifetime_arg = {
}

const_arg = {
expr
// Currently stable Rust only support literals as const args inside generic
// args. In general, it could be arbitrary expressions, but that causes
// headaches for parsing (in particular, we need to parse an `expr` that
// does _not_ have a `>` sign in it, but our `expr` parsing greedily eats
// any `>` that exists within it. Thus, for now, we simply restrict to
// literals.
literal
}

generic_args_binding = {
Expand Down
24 changes: 24 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2473,3 +2473,27 @@ fn fff() {
} // verus!
"###);
}

#[test]
fn verus_const_generics() {
// Regression test for https://github.com/verus-lang/verusfmt/issues/90
let file = r#"
verus! {
pub fn f<const N: u64>() -> u64 { N }
fn main() { f::<123>(); }
}
"#;
assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus! {
pub fn f<const N: u64>() -> u64 {
N
}
fn main() {
f::<123>();
}
} // verus!
"###);
}

0 comments on commit 55354cd

Please sign in to comment.