Skip to content

Commit

Permalink
Support generic argument binding
Browse files Browse the repository at this point in the history
Useful for associated type constraints, such as `trait Foo<T>: Bar<V = Baz<T>>`
  • Loading branch information
jaybosamiya committed Apr 23, 2024
1 parent ef62085 commit e4a7207
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Unreleased

* Support generic argument binding
- Useful for associated type constraints, such as `trait Foo<T>: Bar<V = Baz<T>>`

# v0.3.0

* Support attributes on `broadcast group` items
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ fn to_doc<'a>(
Rule::assoc_type_arg => unsupported(pair),
Rule::lifetime_arg => map_to_doc(ctx, arena, pair),
Rule::const_arg => unsupported(pair),
Rule::generic_args_binding => map_to_doc(ctx, arena, pair),
Rule::macro_call => s,
Rule::macro_call_stmt => s,
Rule::punctuation => map_to_doc(ctx, arena, pair),
Expand Down
7 changes: 6 additions & 1 deletion src/verus.pest
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ generic_arg_list_with_colons = {
}

generic_arg = {
type_arg
generic_args_binding
| type_arg
| assoc_type_arg
| lifetime_arg
| const_arg
Expand All @@ -477,6 +478,10 @@ const_arg = {
expr
}

generic_args_binding = {
identifier ~ eq_str ~ type
}

// TODO: Special handling for the calc! and state_machine! macros?
macro_call = {
attr* ~ path ~ bang_str ~ !"=" ~ token_tree
Expand Down
19 changes: 19 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2094,3 +2094,22 @@ proof fn b()
} // verus!
"###);
}

#[test]
fn verus_generic_arg_binding() {
let file = r###"
verus! {
pub trait Foo<T>: View<V = Seq<T>> {
}
} // verus!
"###;
assert_snapshot!(parse_and_format(file).unwrap(), @r###"
verus! {
pub trait Foo<T>: View<V = Seq<T>> {
}
} // verus!
"###);
}

0 comments on commit e4a7207

Please sign in to comment.