Parse default field values as Type::Verbatim
#1870
Open
+77
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #1774 (noting that a true fix will require 3.x and #1851)
#![feature(default_field_values)]Adapted from #1851. cc @estebank
This PR is an alternative to #1851 but avoiding the breaking-change. Instead, if a named field has a default value, the field's entire type and the default value is parsed as a
Type::Verbatim. Our users can then detect and support this case, by re-parsing the verbatim type into the type and default value expression.Semantically of course, the default value is not part of the type, but syntactically, the default value is in type position. Our handling of negative inherent impls has a similar shape.
The interaction with
unnamed_fieldswas a bit unclear to me, so I took my cue from #1851 (of allowing both features to be combined). Note that since rust-lang/rust#131045,unnamed_fieldsis not supported by upstream Rust.I chose not to implement the solution you proposed in #1851 (comment), both because the idiomatic implementation strategy was unclear to me, and because if I understand correctly, the proposed solution makes supporting
default_field_valuesin dependent macros unfeasible.Thanks for all your great work!