Skip to content

Fix parse errors - #202

Open
Marsman1996 wants to merge 4 commits into
verus-lang:mainfrom
Marsman1996:fix-parse-error
Open

Marsman1996 wants to merge 4 commits into
verus-lang:mainfrom
Marsman1996:fix-parse-error

Conversation

@Marsman1996

@Marsman1996 Marsman1996 commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

While formatting VOSTD code, we found several parse errors.

This PR fixes the following cases:

  1. returns clause with a struct literal
  2. numbered record fields
  3. commented-out generic type bounds

returns_clause

PoC

verus! {
fn clone(self) -> DmaCoherent
    returns
        DmaCoherent { inner: self.inner },
{
    self
}
}

Error Message

Error:   × Failed to parse
   ╭─[./out/returns_struct_literal_poc.rs:4:28]
 3 │     returns
 4 │         DmaCoherent { inner: self.inner },
   ·                            ┬
   ·                            ╰── here
 5 │ {
   ╰────
  help: Expected one of: COMMENT, at_str, bang_str, colons_str,
        dot_str, dot_dot_str, dot_dot_eq_str, lbracket_str,
        question_str, rarrow_str, semi_str, as_str, matches_str,
        generic_arg_list, has_or_nothas, is_or_notis, assignment_ops,
        bin_expr_ops_normal, record_expr_field_list, arg_list

Record Field

PoC

verus! {
pub struct PageTableEntry(pub usize);

impl Clone for PageTableEntry {
    fn clone(&self) -> Self {
        Self { 0: self.0 }
    }
}
}

Error Message

Error:   × Failed to parse
   ╭─[./out/numbered_record_field_poc.rs:6:17]
 5 │     fn clone(&self) -> Self {
 6 │         Self { 0: self.0 }
   ·                 ┬
   ·                 ╰── here
 7 │     }
   ╰────
  help: Expected one of: COMMENT, at_str, dot_str, dot_dot_str,
        dot_dot_eq_str, lbracket_str, question_str, rarrow_str,
        as_str, matches_str, has_or_nothas, is_or_notis,
        bin_expr_ops_normal, struct_update_base, arg_list

Commented-Out Generic Type Bound

PoC

verus! {
impl<T: /* ?Sized*/ > MutexGuard<T> {
}
}

Error Message

Error:   × Failed to parse
   ╭─[./out/commented_type_bound_poc.rs:2:21]
 1 │ verus! {
 2 │ impl<T: /* ?Sized*/ > MutexGuard<T> {
   ·                     ┬
   ·                     ╰── here
 3 │ }
   ╰────
  help: Expected one of: COMMENT, type_bound

Formatted Code after Fixing

verus! {

impl<T /* ?Sized*/> MutexGuard<T> {

}

} // verus!

I refer to the behavior of rustfmt, which will format

impl<T: /* ?Sized*/ > MutexGuard<T> {
}

into

impl<T /* ?Sized*/> MutexGuard<T> {}

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

@Marsman1996

Copy link
Copy Markdown
Contributor Author

Block Expression Method

PoC

verus! {
fn test() {
    {#[verus_spec(with => tracked_state)] acquire_lock()}.then(|| true)
}
}

Error Message

Error:   × Failed to parse
   ╭─[./out/block_expr_method_suffix_poc.rs:3:58]
 2 │ fn test() {
 3 │     {#[verus_spec(with => tracked_state)] acquire_lock()}.then(|| true)
   ·                                                          ┬
   ·                                                          ╰── here
 4 │ }
   ╰────
  help: Expected one of: MULTI_NEWLINE, COMMENT, semi_str, stmt, expr

Formatted Code after Fixing

verus! {

fn test() {
    {
        #[verus_spec(with => tracked_state)]
        acquire_lock()
    }.then(|| true)
}

} // verus!

I initially considered following rustfmt's behavior, which formats:

fn test() {
    {#[verus_spec(with => tracked_state)] acquire_lock()}.then(|| true)
}

into

fn test() {
    {
        #[verus_spec(with => tracked_state)]
        acquire_lock()
    }
    .then(|| true)
}

However, supporting this formatting style would require additional parsing logic and significantly more time.
See https://github.com/verus-lang/verusfmt/actions/runs/26689277267/job/78662742967

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant