Reimplement attribute parsing without darling#310
Reimplement attribute parsing without darling#310dtolnay wants to merge 1 commit intocolin-kiegel:masterfrom
darling#310Conversation
|
|
||
| error: Cannot set `error(validation_error = false)` when using `validate` | ||
| --> tests/compile-fail/build_fn_error.rs:10:45 | ||
| error: `error(validation_error = false)` cannot be set when using `validate` |
There was a problem hiding this comment.
if validate = "hello" is highlighted below then shouldn't this say something like "validate cannot be set if error(validation_error = false) is used"? :)
There was a problem hiding this comment.
Good call. I updated the PR rewording it to "error(validation_error = false) and validate cannot be used together" which is consistent with wording that is already used prior to this PR when dealing with the conflict between builder(default) and builder(field(build = "...")).
5bdc593 to
1733f00
Compare
|
Acknowledging receipt of PR. |
|
Rebased on #311 to fix nightly CI. |
This finally gave me the push needed to get
We'd previously discussed this in dtolnay/syn#1458, and my impression was that not accepting
With the introduction of Since those checks are part of the generated darling impl via the use of
I view these as a benefit, not a drawback. This may be personal preference, but I find it easier to reason over a set of structs that represent what was extracted from the
I would very much like to give users of this library and users of I'm not sold on the idea that abandoning I view |
|
Makes sense; I appreciate the counterpoints. |
This PR reimplements parsing using Syn's attribute parsing library, which lifts a few limitations previously imposed on derive_builder's implementation by
darling.Keywords in attributes:
darlingdoesn't make it possible to use keywords in a nested attribute, such asfield(type = "..."). I have added back support for that syntax in this PR (but also keptfield(ty = "...")as an alias for the same thing for backward compatibility).Attributes containing keywords can't be parsed with 0.20 TedDriggs/darling#238
Factoring commonality from different data structures: for this PR I have not gone overboard with refactoring, but I did move the trio of
public+private+vis = "..."to a single central place, as it was repeated across 5 different structs. This PR unlocks additional possibilities for factoring out common behavior, and there are pre-existing comments to the effect that this would be desirable.Add support for
flattenTedDriggs/darling#146Validation during parse: with
darling, structs are created in a potentially invalid state and then code needs to crawl them after the fact to perform validation. In this PR, structs do not get constructed in an invalid state; validation is integrated with the parsing. This also means various "DO NOT USE" fields go away in this PR.Passing state from outer contexts to inner: derive_builder has workarounds that exist because
darling's FromMeta needs to be able to fully construct the output with no context other than the input Meta. In this PR, parsing is handled top to bottom by free-form function calls; additional arguments can be passed through as it becomes useful. For example, one can parse attributes at the struct level and then pass data from those to the code that parses attributes at the field level.Compile time: this PR improves compile time of derive_builder by 35% on my machine (5.9 seconds to 3.8 seconds).