Skip to content

Conversation

@cameron1024
Copy link
Member

@cameron1024 cameron1024 commented Sep 4, 2025

Closes #592

Note for reviewers: 1750 lines of diff comes from the inclusion of a new snapshot file. It's otherwise quite a small PR.

The generated struct will now use the name of an argument if the pattern of the argument is an identifier. For example, given this failing test:

#[property_test] fn test_name(x: i32, #[strategy = "[0-9]*"] s: String) { assert_eq!(x.to_string(), s); }

We now get an error like:

Test failed: assertion `left == right` failed left: "0" right: "1". minimal failing input: TestNameArgs = TestNameArgs { x: 0, s: "1", } 

There are two possible improvements (that I can think of off the top of my head right now) here:

  • we could extend this to cover any pattern that binds only a
    single parameter, for example, we could capture this argument as s:
#[property_test] fn foo((Ok(s) | Err(s)): Result<i32, i32>) {}
  • we could do some sort of name mangling for more common pattern types, for
    example (a, b): (i32, i32) could correspond to a struct field
    tuple_of_a_b: (i32, i32).

Of these, the second option is a lot easier to implement, though it could get nasty with nested patterns (e.g. tuple_of_tuple_of_tuple_of...).

For now I'm going to get this minimal implementation in though.

Copy link
Contributor

@rexmas rexmas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome!

@cameron1024 cameron1024 merged commit ea4ddeb into main Sep 8, 2025
11 checks passed
@cameron1024 cameron1024 deleted the attr-macro-preserve-arg-names branch September 8, 2025 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants