Skip to content

quickcheck!: accept mut bindings in property arguments - #354

Open
chiliec wants to merge 1 commit into
BurntSushi:masterfrom
chiliec:macro-mut-args
Open

quickcheck!: accept mut bindings in property arguments#354
chiliec wants to merge 1 commit into
BurntSushi:masterfrom
chiliec:macro-mut-args

Conversation

@chiliec

@chiliec chiliec commented Sep 8, 2026

Copy link
Copy Markdown

Fixes #269

The quickcheck! macro matched each property argument as $arg_name:ident : $arg_ty:ty, so a mut binding like fn prop(mut xs: Vec<usize>) -> bool failed with no rules expected the token xs``.

Fix: match one or more idents before the colon ($($arg_name:ident)+ : $arg_ty:ty) and forward them verbatim into the generated prop fn. Plain ident: ty arguments expand exactly as before; the fn(...) cast still uses only the types. (A pat_param fragment isn't an option here — macro_rules doesn't allow : after it.)

Tests: added prop_macro_mut_arg(mut xs: Vec<usize>) to the existing quickcheck! { ... } block in src/tests.rs.

Validation (rustc 1.98.1, local):

  • With the test but the old macro: cargo test --lib prop_macroerror: no rules expected xs`` (reproduces the issue).
  • With the fix: cargo test → 70 passed (lib) + 4 passed (quickcheck_macros), 0 failed.
  • cargo fmt --check clean.

The macro matched each argument as `ident : ty`, so
`fn prop(mut xs: Vec<u8>) -> bool` failed with
"no rules expected the token `xs`". Match one or more idents before
the colon and forward them verbatim into the generated `prop` fn.

Fixes BurntSushi#269
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.

Add support for mut bindings in function arguments

1 participant