-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom strategies in attribute macro #478
Conversation
fn strip_strategy(mut pat_ty: PatType) -> Argument { | ||
let (strategies, others) = pat_ty.attrs.into_iter().partition(is_strategy); | ||
|
||
pat_ty.attrs = others; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attrs must always be empty here because we validate in validate_parameter_attrs
that only strategy = <expr>
attrs exist right?
- if we handle the extra attrs here, why do we disallow other attrs?
- does disallowing them mean
#[property_test]
doesn't compose well with other proc macros?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll double check. I'd like to compose with other macros as much as is feasible, so other attributes should be left alone. I think validate is being overly aggressive here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the more I think about it, I'm not sure what we could meaningfully do with the attributes, since they're going into our own struct - the output from proptest is a zero-arg function, so maybe it doesn't make sense here?
I think for now, disallowing other attributes is safer from a backwards compatibility point of view - we don't lock ourselves into supporting something that is difficult later
|
||
mod arbitrary; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think this file has been committed yet -- which also exposes gaps in our CI which likely isn't building this new crate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good spot - let's get this in CI
This got closed when i switched branch from master to main. I'll re-open against the main branch. |
This adds the ability to add custom strategies to parameters of a
#[property_test]
function:This adds a second code path to codegen:
Arbitrary
impl with fully spelled out types (i.e. no boxing)Strategy
, since macros run before typechecking. So we just fallback toBoxedStrategy<Self>
I've tried to retain span info, so error messages should appear at the correct place if you do things like add 2 strategies to a field, or use invalid syntax. For other stuff (e.g. passing non-strategies) we rely on rustc