Fix default with optional props (#4995)
* fix default with optional props * fix core macro tests
This commit is contained in:
1 parent
6e952f27a7
commit
6df20ef3f7
2 files changed
+6
-5
No files matched your search
@@ -238,9 +238,10 @@ mod field_info {
|
|||||||
|| !builder_attr.ignore_option && type_from_inside_option(&field.ty).is_some();
|
|| !builder_attr.ignore_option && type_from_inside_option(&field.ty).is_some();
|
||||||
if !builder_attr.strip_option && strip_option_auto {
|
if !builder_attr.strip_option && strip_option_auto {
|
||||||
builder_attr.strip_option = true;
|
builder_attr.strip_option = true;
|
||||||
builder_attr.default = Some(
|
// only change the default if it isn't manually set above
|
||||||
syn::parse(quote!(::core::default::Default::default()).into()).unwrap(),
|
builder_attr.default.get_or_insert_with(|| {
|
||||||
);
|
syn::parse(quote!(::core::default::Default::default()).into()).unwrap()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(FieldInfo {
|
Ok(FieldInfo {
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ mod test_default_into {
|
|||||||
pub str_default: String,
|
pub str_default: String,
|
||||||
|
|
||||||
// Test options
|
// Test options
|
||||||
#[props(into, default = Some("abc"))]
|
#[props(into, default = Some("abc".into()))]
|
||||||
pub opt_into_w_default_val: Option<String>,
|
pub opt_into_w_default_val: Option<String>,
|
||||||
|
|
||||||
#[props(into, default)]
|
#[props(into, default)]
|
||||||
pub opt_into_w_default: Option<String>,
|
pub opt_into_w_default: Option<String>,
|
||||||
|
|
||||||
#[props(default = Some("abc"))]
|
#[props(default = Some("abc".into()))]
|
||||||
pub opt_default: Option<String>,
|
pub opt_default: Option<String>,
|
||||||
|
|
||||||
// Test no default
|
// Test no default
|
||||||
|
|||||||
Reference in new issue
Block a user