Skip to content

Commit

Permalink
Support parsing for const generic literals (#92)
Browse files Browse the repository at this point in the history
Fixes #90
  • Loading branch information
jaybosamiya-ms authored Sep 24, 2024
2 parents da59e94 + 15f6920 commit b642edc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Improved handling of comments around clauses/stanzas
- Each comment now maintains loyalty to the clause the user picked it to stay with, rather than automatically migrating to the previous clause in the presence of `assert ... by { ... }`-style constructs
* Support parsing for const generic literals

# v0.4.1

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
30 changes: 30 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2533,3 +2533,33 @@ pub fn foo() {
} // 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 }
pub fn g<const N: u64, const O: u64>() -> u64 { N }
fn main() { f::<123>(); g::<123, 456>(); }
}
"#;
assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus! {
pub fn f<const N: u64>() -> u64 {
N
}
pub fn g<const N: u64, const O: u64>() -> u64 {
N
}
fn main() {
f::<123>();
g::<123, 456>();
}
} // verus!
"###);
}

0 comments on commit b642edc

Please sign in to comment.