Fixes Default Literals | Issue #368 - #3066
Open
IftekharUddin wants to merge 1 commit into
Open
IftekharUddin wants to merge 1 commit into
IftekharUddin wants to merge 1 commit into
Conversation
Author
|
hmmm i thought i checked all the tests, I'll look into that. |
Author
|
got tired, will pick it up later but I'm confused by the test. I'm like 70% sure the type mismatch file issue is that it needs to check that it doesn't auto convert? but this change in the default expression would, auto, convert? Too tired, i'm confusing myself. |
Adds a new field-level attribute that embeds an arbitrary Rust expression as the missing-field default during deserialization, eliminating the boilerplate of writing a helper function for simple literals and constructors. Type checking is delegated entirely to Rust; no implicit coercions are performed. - `Default::Expr(syn::Expr)` variant added to the internal default enum - Attribute parsed in `Field::from_ast`; conflicts with `default` and `default = "path"` are detected and reported with a clear diagnostic - `parse_lit_into_expr` uses `cx` for enriched error messages on malformed expressions - Code generation in `expr_is_missing` / `expr_is_missing_seq` emits the expression with `quote_spanned!` so type errors point to the attribute site - No `Default` bound is added for `default_expr`, matching the behavior of `default = "path"` - Runtime tests cover named structs, tuple structs, and the `skip_deserializing` interaction - UI compile-fail tests cover default conflicts (bare and path forms) and type mismatch; nightly required to bless type_mismatch.stderr
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Serde_Default_Expression.pdf
serde_default_expr_implementation_report.docx
Adds a new field-level attribute,
default_expr, that allows an arbitraryRust expression to be used as a missing-field default during deserialization,
without requiring a dedicated helper function.
Motivation
The existing
default = "path"form requires a named callable, forcingboilerplate for trivial defaults like literals or simple constructors.
default_expreliminates that overhead while keeping semantics explicitand avoiding overload of the existing
defaultattribute.Changes
symbol.rs: introduce theDEFAULT_EXPRsymbolattr.rs: parsedefault_exprassyn::Expr; extendDefaultenumwith
Expr(syn::Expr); enforce single-default-source conflict rulede.rs: emit expression directly in missing-field branches viaquote_spanned!; noDefaultbound added fordefault_exprde/struct_.rs: exhaustive match coverage for newDefault::ExprvariantTests
test_default_expr_struct,test_default_expr_tuple,test_skip_with_exprconflict.rs,conflict_path.rs,type_mismatch.rsMore in depth documents have been attached. It goes over the game plan and then the implementation that was followed.