From df79619e399cca20289550a53295c49911fdc5f9 Mon Sep 17 00:00:00 2001 From: Artem Romanenia Date: Wed, 4 Sep 2024 16:37:20 +0300 Subject: [PATCH] return preferred formatting manually --- o2o-impl/src/ast.rs | 7 +- o2o-impl/src/attr.rs | 112 ++++----- o2o-impl/src/expand.rs | 218 +++++++++--------- o2o-impl/src/tests.rs | 20 +- o2o-impl/src/validate.rs | 112 +++------ .../tests/10_multiple_child_attr_tests.rs | 20 +- .../10_multiple_child_attr_tests_fallible.rs | 20 +- o2o-tests/tests/14_parent_attr_tests.rs | 20 +- .../tests/14_parent_attr_tests_fallible.rs | 20 +- .../tests/15_multiple_parent_attr_tests.rs | 60 ++++- .../15_multiple_parent_attr_tests_fallible.rs | 60 ++++- o2o-tests/tests/17_generic_path_tests.rs | 10 +- .../tests/17_generic_path_tests_fallible.rs | 10 +- o2o-tests/tests/18_where_attr_tests.rs | 10 +- .../tests/18_where_attr_tests_fallible.rs | 10 +- o2o-tests/tests/19_deep_ghost_attr_tests.rs | 28 ++- .../19_deep_ghost_attr_tests_fallible.rs | 8 +- o2o-tests/tests/20_as_type_attr_tests.rs | 28 ++- .../tests/20_as_type_attr_tests_fallible.rs | 28 ++- ...ld_level_inline_at_expr_only_attr_tests.rs | 15 +- ...inline_at_expr_only_attr_tests_fallible.rs | 15 +- ...level_inline_tilde_expr_only_attr_tests.rs | 5 +- ...ine_tilde_expr_only_attr_tests_fallible.rs | 5 +- .../5_field_level_closure_only_attr_tests.rs | 10 +- ..._level_closure_only_attr_tests_fallible.rs | 10 +- ...field_level_ident_and_inline_expr_tests.rs | 5 +- ...el_ident_and_inline_expr_tests_fallible.rs | 5 +- ..._level_ident_and_inline_expr_more_tests.rs | 10 +- ...ent_and_inline_expr_more_tests_fallible.rs | 10 +- o2o-tests/tests/9_child_attr_tests.rs | 12 +- rustfmt.toml | 3 +- 31 files changed, 554 insertions(+), 352 deletions(-) diff --git a/o2o-impl/src/ast.rs b/o2o-impl/src/ast.rs index ab4a53c..4fdcdf3 100644 --- a/o2o-impl/src/ast.rs +++ b/o2o-impl/src/ast.rs @@ -74,7 +74,12 @@ impl<'a> Field { Ok(Field { attrs: attr::get_member_attrs(SynDataTypeMember::Field(node), bark)?, idx: i, - member: node.ident.clone().map(Member::Named).unwrap_or_else(|| Member::Unnamed(Index { index: i as u32, span: node.ty.span() })), + member: node.ident.clone().map(Member::Named).unwrap_or_else(|| { + Member::Unnamed(Index { + index: i as u32, + span: node.ty.span(), + }) + }), }) } } diff --git a/o2o-impl/src/attr.rs b/o2o-impl/src/attr.rs index 94a6a7d..9fa9209 100644 --- a/o2o-impl/src/attr.rs +++ b/o2o-impl/src/attr.rs @@ -25,9 +25,7 @@ impl Parse for OptionalParenthesizedTokenStream { let content; parenthesized!(content in input); Some(content.parse()?) - } else { - None - }, + } else { None }, }) } } @@ -197,19 +195,21 @@ impl<'a> DataTypeAttrs { } pub(crate) fn ghosts_attr(&'a self, container_ty: &'a TypePath, kind: &'a Kind) -> Option<&StructGhostAttrCore> { - self.ghosts_attrs - .iter() + self.ghosts_attrs.iter() .find(|x| x.applicable_to[kind] && x.attr.container_ty.is_some() && x.attr.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| self.ghosts_attrs.iter().find(|x| x.applicable_to[kind] && x.attr.container_ty.is_none())) - .map(|x| &x.attr) + .or_else(|| self.ghosts_attrs.iter().find(|x| x.applicable_to[kind] && x.attr.container_ty.is_none())).map(|x| &x.attr) } - pub(crate) fn where_attr(&'a self, container_ty: &TypePath) -> Option<&WhereAttr> { - self.where_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.where_attrs.iter().find(|x| x.container_ty.is_none())) + pub(crate) fn where_attr(&'a self, container_ty: &TypePath) -> Option<&WhereAttr>{ + self.where_attrs.iter() + .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.where_attrs.iter().find(|x| x.container_ty.is_none())) } - pub(crate) fn children_attr(&'a self, container_ty: &TypePath) -> Option<&ChildrenAttr> { - self.children_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.children_attrs.iter().find(|x| x.container_ty.is_none())) + pub(crate) fn children_attr(&'a self, container_ty: &TypePath) -> Option<&ChildrenAttr>{ + self.children_attrs.iter() + .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.children_attrs.iter().find(|x| x.container_ty.is_none())) } } @@ -305,15 +305,15 @@ impl<'a> MemberAttrs { } pub(crate) fn applicable_attr(&'a self, kind: &'a Kind, fallible: bool, container_ty: &TypePath) -> Option { - self.ghost(container_ty, kind).map(ApplicableAttr::Ghost).or_else(|| { - self.field_attr_core(kind, fallible, container_ty) + self.ghost(container_ty, kind) + .map(ApplicableAttr::Ghost) + .or_else(|| self.field_attr_core(kind, fallible, container_ty) .or_else(|| if fallible { self.field_attr_core(kind, false, container_ty) } else { None }) .or_else(|| if kind == &Kind::OwnedIntoExisting { self.field_attr_core(&Kind::OwnedInto, fallible, container_ty) } else { None }) .or_else(|| if kind == &Kind::OwnedIntoExisting && fallible { self.field_attr_core(&Kind::OwnedInto, false, container_ty) } else { None }) .or_else(|| if kind == &Kind::RefIntoExisting { self.field_attr_core(&Kind::RefInto, fallible, container_ty) } else { None }) .or_else(|| if kind == &Kind::RefIntoExisting && fallible { self.field_attr_core(&Kind::RefInto, false, container_ty) } else { None }) - .map(ApplicableAttr::Field) - }) + .map(ApplicableAttr::Field)) } pub(crate) fn applicable_field_attr(&'a self, kind: &'a Kind, fallible: bool, container_ty: &TypePath) -> Option<&'a MemberAttr> { @@ -322,28 +322,34 @@ impl<'a> MemberAttrs { .or_else(|| if kind == &Kind::RefIntoExisting { self.field_attr(&Kind::RefInto, fallible, container_ty) } else { None }) } - pub(crate) fn child(&'a self, container_ty: &TypePath) -> Option<&ChildAttr> { - self.child_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.child_attrs.iter().find(|x| x.container_ty.is_none())) + pub(crate) fn child(&'a self, container_ty: &TypePath) -> Option<&ChildAttr>{ + self.child_attrs.iter() + .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.child_attrs.iter().find(|x| x.container_ty.is_none())) } - pub(crate) fn ghost(&'a self, container_ty: &TypePath, kind: &'a Kind) -> Option<&FieldGhostAttrCore> { - self.ghost_attrs - .iter() + pub(crate) fn ghost(&'a self, container_ty: &TypePath, kind: &'a Kind) -> Option<&FieldGhostAttrCore>{ + self.ghost_attrs.iter() .find(|x| x.applicable_to[kind] && x.attr.container_ty.is_some() && x.attr.container_ty.as_ref().unwrap() == container_ty) - .or_else(|| self.ghost_attrs.iter().find(|x| x.applicable_to[kind] && x.attr.container_ty.is_none())) - .map(|x| &x.attr) + .or_else(|| self.ghost_attrs.iter().find(|x| x.applicable_to[kind] && x.attr.container_ty.is_none())).map(|x| &x.attr) } - pub(crate) fn lit(&'a self, container_ty: &TypePath) -> Option<&LitAttr> { - self.lit_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.lit_attrs.iter().find(|x| x.container_ty.is_none())) + pub(crate) fn lit(&'a self, container_ty: &TypePath) -> Option<&LitAttr>{ + self.lit_attrs.iter() + .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.lit_attrs.iter().find(|x| x.container_ty.is_none())) } - pub(crate) fn pat(&'a self, container_ty: &TypePath) -> Option<&PatAttr> { - self.pat_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.pat_attrs.iter().find(|x| x.container_ty.is_none())) + pub(crate) fn pat(&'a self, container_ty: &TypePath) -> Option<&PatAttr>{ + self.pat_attrs.iter() + .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.pat_attrs.iter().find(|x| x.container_ty.is_none())) } - pub(crate) fn type_hint(&'a self, container_ty: &TypePath) -> Option<&VariantTypeHintAttr> { - self.type_hint_attrs.iter().find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty).or_else(|| self.type_hint_attrs.iter().find(|x| x.container_ty.is_none())) + pub(crate) fn type_hint(&'a self, container_ty: &TypePath) -> Option<&VariantTypeHintAttr>{ + self.type_hint_attrs.iter() + .find(|x| x.container_ty.is_some() && x.container_ty.as_ref().unwrap() == container_ty) + .or_else(|| self.type_hint_attrs.iter().find(|x| x.container_ty.is_none())) } pub(crate) fn has_parent_attr(&'a self, container_ty: &TypePath) -> bool { @@ -515,32 +521,14 @@ impl Parse for TraitAttrCore { parenthesized!(content in input); let content_stream = content.parse::()?; quote!((#content_stream)).into() - } else { - input.parse::()?.into() - }; + } else { input.parse::()?.into() }; let type_hint = if ty.nameless_tuple { TypeHint::Tuple } else { try_parse_type_hint(input)? }; let err_ty = if input.peek(Token![,]) { input.parse::()?; Some(input.parse::()?.into()) - } else { - None - }; + } else { None }; - let mut attr = TraitAttrCore { - ty, - err_ty, - type_hint, - init_data: None, - update: None, - quick_return: None, - default_case: None, - repeat: None, - skip_repeat: false, - stop_repeat: false, - attribute: None, - impl_attribute: None, - inner_attribute: None, - }; + let mut attr = TraitAttrCore { ty, err_ty, type_hint, init_data: None, update: None, quick_return: None, default_case: None, repeat: None, skip_repeat: false, stop_repeat: false, attribute: None, impl_attribute: None, inner_attribute: None }; if !input.peek(Token![|]) { return Ok(attr); @@ -705,9 +693,7 @@ impl Parse for GhostData { }); input.parse::()?; child_path - } else { - None - }; + } else { None }; let ghost_ident = if input.peek2(Token![:]) { GhostIdent::Member(input.parse()?) } else if input.peek2(Brace) { @@ -881,9 +867,7 @@ impl Parse for AsAttr { input.parse::()?; let tokens = input.parse()?; (ident, tokens) - } else { - (None, input.parse()?) - }; + } else { (None, input.parse()?) }; Ok(AsAttr { container_ty, member: ident, tokens }) } @@ -983,7 +967,7 @@ pub(crate) fn get_data_type_attrs(input: &[Attribute]) -> Result<(DataTypeAttrs, } attrs.attrs.push(trait_attr) - } + }, DataTypeInstruction::Ghosts(attr) => attrs.ghosts_attrs.push(attr), DataTypeInstruction::Where(attr) => attrs.where_attrs.push(attr), DataTypeInstruction::Children(attr) => attrs.children_attrs.push(attr), @@ -1029,7 +1013,7 @@ pub(crate) fn get_member_attrs(input: SynDataTypeMember, bark: bool) -> Result add_as_type_attrs(f, attr, &mut attrs.attrs), SynDataTypeMember::Variant(_) => unreachable!("1"), }; - } + }, MemberInstruction::Lit(attr) => attrs.lit_attrs.push(attr), MemberInstruction::Pat(attr) => attrs.pat_attrs.push(attr), MemberInstruction::Repeat(repeat_for) => attrs.repeat = Some(repeat_for), @@ -1085,18 +1069,8 @@ fn parse_data_type_instruction(instr: &Ident, input: TokenStream, own_instr: boo "children" => Ok(DataTypeInstruction::Children(syn::parse2(input)?)), "where_clause" => Ok(DataTypeInstruction::Where(syn::parse2(input)?)), "ghost" if bark => Ok(DataTypeInstruction::Misnamed { instr: "ghost", span: instr.span(), guess_name: "ghosts", own: own_instr }), - "ghost_ref" if bark => Ok(DataTypeInstruction::Misnamed { - instr: "ghost_ref", - span: instr.span(), - guess_name: "ghosts_ref", - own: own_instr, - }), - "ghost_owned" if bark => Ok(DataTypeInstruction::Misnamed { - instr: "ghost_owned", - span: instr.span(), - guess_name: "ghosts_owned", - own: own_instr, - }), + "ghost_ref" if bark => Ok(DataTypeInstruction::Misnamed { instr: "ghost_ref", span: instr.span(), guess_name: "ghosts_ref", own: own_instr }), + "ghost_owned" if bark => Ok(DataTypeInstruction::Misnamed { instr: "ghost_owned", span: instr.span(), guess_name: "ghosts_owned", own: own_instr }), "child" if bark => Ok(DataTypeInstruction::Misnamed { instr: "child", span: instr.span(), guess_name: "children", own: own_instr }), "parent" if bark => Ok(DataTypeInstruction::Misplaced { instr: "parent", span: instr.span(), own: own_instr }), "as_type" if bark => Ok(DataTypeInstruction::Misplaced { instr: "as_type", span: instr.span(), own: own_instr }), diff --git a/o2o-impl/src/expand.rs b/o2o-impl/src/expand.rs index 2954334..3874689 100644 --- a/o2o-impl/src/expand.rs +++ b/o2o-impl/src/expand.rs @@ -22,13 +22,13 @@ pub fn derive(node: &DeriveInput) -> Result { let input = DataType::Struct(&input); validate(&input)?; Ok(data_type_impl(input)) - } + }, Data::Enum(data) => { let input = Enum::from_syn(node, data)?; let input = DataType::Enum(&input); validate(&input)?; Ok(data_type_impl(input)) - } + }, _ => Err(Error::new_spanned(node, "#[derive(o2o)] only supports structs and enums.")), } } @@ -334,7 +334,7 @@ fn struct_main_code_block(input: &Struct, ctx: &ImplContext) -> TokenStream { Kind::FromOwned | Kind::FromRef => { let dst = ctx.dst_ty; quote!(#dst #struct_init_block) - } + }, Kind::OwnedInto | Kind::RefInto => { let dst = if ctx.struct_attr.ty.nameless_tuple || ctx.has_post_init { TokenStream::new() @@ -349,7 +349,7 @@ fn struct_main_code_block(input: &Struct, ctx: &ImplContext) -> TokenStream { ctx.dst_ty.clone() }; quote!(#dst #struct_init_block) - } + }, Kind::OwnedIntoExisting | Kind::RefIntoExisting => struct_init_block, } } @@ -360,10 +360,10 @@ fn enum_main_code_block(input: &Enum, ctx: &ImplContext) -> TokenStream { match ctx.kind { Kind::FromOwned | Kind::FromRef => { quote!(match value #enum_init_block) - } + }, Kind::OwnedInto | Kind::RefInto => { quote!(match self #enum_init_block) - } + }, Kind::OwnedIntoExisting | Kind::RefIntoExisting => enum_init_block, } } @@ -388,29 +388,33 @@ fn struct_init_block<'a>(input: &'a Struct, ctx: &ImplContext) -> TokenStream { let mut fields: Vec<(usize, &str, FieldData)> = vec![]; - fields.extend( - input - .fields - .iter() - .map(|x| { - let path = x.attrs.child(&ctx.struct_attr.ty).map(|x| x.get_child_path_str(None)).unwrap_or(""); - unique_paths.insert(path); - make_tuple(path, FieldData::Field(x)) - }) - .collect::>(), - ); - - fields.extend(input.attrs.ghosts_attrs.iter().flat_map(|x| &x.attr.ghost_data).filter(|x| unique_paths.insert(x.get_child_path_str(None))).map(|x| { - let path: &str = x.get_child_path_str(None); - make_tuple(path, FieldData::GhostData(x)) - })); + fields.extend(input.fields.iter() + .map(|x| { + let path = x.attrs.child(&ctx.struct_attr.ty).map(|x| x.get_child_path_str(None)).unwrap_or(""); + unique_paths.insert(path); + make_tuple(path, FieldData::Field(x)) + }).collect::>()); + + fields.extend(input.attrs.ghosts_attrs.iter() + .flat_map(|x| &x.attr.ghost_data) + .filter(|x| unique_paths.insert(x.get_child_path_str(None))) + .map(|x| { + let path: &str = x.get_child_path_str(None); + make_tuple(path, FieldData::GhostData(x)) + })); fields.sort_by(|(ga, a, _), (gb, b, _)| ga.cmp(gb).then(a.cmp(b))); struct_init_block_inner(&mut fields.iter().peekable(), input, ctx, None) } -fn struct_init_block_inner(members: &mut Peekable>, input: &Struct, ctx: &ImplContext, field_ctx: Option<(&ChildPath, Option<&ChildData>, usize)>) -> TokenStream { +fn struct_init_block_inner( + members: &mut Peekable>, + input: &Struct, + ctx: &ImplContext, + field_ctx: Option<(&ChildPath, Option<&ChildData>, usize)> +) -> TokenStream +{ let type_hint = match field_ctx { Some(field_ctx) => match field_ctx.1 { Some(child_data) => child_data.type_hint, @@ -455,7 +459,7 @@ fn struct_init_block_inner(members: &mut Peekable }; fragments.push(fragment); idx += 1; - } + }, FieldData::GhostData(ghost_data) => { let child_path = &ghost_data.child_path.as_ref().unwrap(); let fragment = render_child_fragment(child_path, members, input, ctx, field_ctx, type_hint, TokenStream::new); @@ -502,9 +506,12 @@ fn struct_init_block_inner(members: &mut Peekable fn enum_init_block(input: &Enum, ctx: &ImplContext) -> TokenStream { let mut fields: Vec = vec![]; - fields.extend(input.variants.iter().map(VariantData::Variant).collect::>()); - - fields.extend(input.attrs.ghosts_attrs.iter().flat_map(|x| &x.attr.ghost_data).map(VariantData::GhostData)); + fields.extend(input.variants.iter() + .map(VariantData::Variant).collect::>()); + + fields.extend(input.attrs.ghosts_attrs.iter() + .flat_map(|x| &x.attr.ghost_data) + .map(VariantData::GhostData)); enum_init_block_inner(&mut fields.iter().peekable(), input, ctx) } @@ -556,11 +563,10 @@ fn enum_init_block_inner(members: &mut Peekable>, input: &Enum fn variant_destruct_block(input: &Struct, ctx: &ImplContext) -> TokenStream { let (mut idents, type_hint) = match (input.named_fields, ctx.kind, ctx.struct_attr.type_hint) { - (true, Kind::OwnedInto | Kind::RefInto | Kind::OwnedIntoExisting | Kind::RefIntoExisting, _) | (true, _, TypeHint::Struct | TypeHint::Unspecified) | (false, Kind::FromOwned | Kind::FromRef, TypeHint::Struct) => ( - input - .fields - .iter() - .filter(|x| !ctx.kind.is_from() || x.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_none()) + (true, Kind::OwnedInto | Kind::RefInto | Kind::OwnedIntoExisting | Kind::RefIntoExisting, _) | + (true, _, TypeHint::Struct | TypeHint::Unspecified) | + (false, Kind::FromOwned | Kind::FromRef, TypeHint::Struct) => ( + input.fields.iter().filter(|x| !ctx.kind.is_from() || x.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_none()) .map(|x| { let attr = x.attrs.applicable_attr(&ctx.kind, ctx.fallible, &ctx.struct_attr.ty); @@ -570,24 +576,17 @@ fn variant_destruct_block(input: &Struct, ctx: &ImplContext) -> TokenStream { } else if let Some(attr) = attr { let ident = attr.get_field_name_or(&x.member); quote!(#ident ,) - } else { - unreachable!("3") - } - }) - .collect(), + } else { unreachable!("3") } + }).collect(), TypeHint::Struct, ), (_, Kind::FromOwned | Kind::FromRef, TypeHint::Unit) => (vec![], TypeHint::Unit), _ => ( - input - .fields - .iter() - .filter(|x| !ctx.kind.is_from() || x.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_none()) + input.fields.iter().filter(|x| !ctx.kind.is_from() || x.attrs.ghost(&ctx.struct_attr.ty, &ctx.kind).is_none()) .map(|x| { let ident = format_ident!("f{}", x.idx); quote!(#ident ,) - }) - .collect(), + }).collect(), TypeHint::Tuple, ), }; @@ -611,7 +610,16 @@ fn variant_destruct_block(input: &Struct, ctx: &ImplContext) -> TokenStream { } } -fn render_child_fragment TokenStream>(child_path: &ChildPath, fields: &mut Peekable>, input: &Struct, ctx: &ImplContext, field_ctx: Option<(&ChildPath, Option<&ChildData>, usize)>, type_hint: TypeHint, render_line: F) -> TokenStream { +fn render_child_fragment TokenStream>( + child_path: &ChildPath, + fields: &mut Peekable>, + input: &Struct, + ctx: &ImplContext, + field_ctx: Option<(&ChildPath, Option<&ChildData>, usize)>, + type_hint: TypeHint, + render_line: F +) -> TokenStream +{ if let Some(field_ctx) = field_ctx { if field_ctx.2 < child_path.child_path_str.len() - 1 { match ctx.kind { @@ -685,7 +693,13 @@ fn render_parent(f: &Field, ctx: &ImplContext) -> TokenStream { } } -fn render_child(fields: &mut Peekable>, input: &Struct, ctx: &ImplContext, field_ctx: (&ChildPath, usize), hint: TypeHint) -> TokenStream { +fn render_child( + fields: &mut Peekable>, + input: &Struct, + ctx: &ImplContext, + field_ctx: (&ChildPath, usize), + hint: TypeHint) -> TokenStream +{ let child_path = field_ctx.0; let path = child_path.get_child_path_str(Some(field_ctx.1)); let child_name = child_path.child_path[field_ctx.1].to_token_stream(); @@ -702,7 +716,13 @@ fn render_child(fields: &mut Peekable>, input: &S } } -fn render_existing_child(fields: &mut Peekable>, input: &Struct, ctx: &ImplContext, field_ctx: (&ChildPath, usize)) -> TokenStream { +fn render_existing_child( + fields: &mut Peekable>, + input: &Struct, + ctx: &ImplContext, + field_ctx: (&ChildPath, usize) +) -> TokenStream +{ let child_attr = field_ctx.0; let path = child_attr.get_child_path_str(Some(field_ctx.1)); let children_attr = input.attrs.children_attr(&ctx.struct_attr.ty); @@ -710,7 +730,13 @@ fn render_existing_child(fields: &mut Peekable>, struct_init_block_inner(fields, input, ctx, Some((field_ctx.0, child_data, field_ctx.1))) } -fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) -> TokenStream { +fn render_struct_line( + f: &Field, + ctx: &ImplContext, + hint: TypeHint, + idx: usize +) -> TokenStream +{ let attr = f.attrs.applicable_attr(&ctx.kind, ctx.fallible, &ctx.struct_attr.ty); let get_field_path = |x: &Member| match f.attrs.child(&ctx.struct_attr.ty) { Some(child_attr) => { @@ -720,9 +746,7 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) None => x.to_token_stream(), }; - let obj = if ctx.impl_type.is_variant() { - TokenStream::new() - } else { + let obj = if ctx.impl_type.is_variant() { TokenStream::new() } else { match ctx.kind { Kind::OwnedInto => quote!(self.), Kind::RefInto => quote!(self.), @@ -734,25 +758,19 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) }; match (&f.member, attr, &ctx.kind, hint) { - (Named(ident), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Struct | TypeHint::Unspecified) => { - if ctx.has_post_init { - quote!(obj.#ident = #obj #ident;) - } else { - quote!(#ident: #obj #ident,) - } - } + (Named(ident), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Struct | TypeHint::Unspecified) => + if ctx.has_post_init { quote!(obj.#ident = #obj #ident;) } else { quote!(#ident: #obj #ident,) }, (Named(ident), None, Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Struct | TypeHint::Unspecified) => { let field_path = get_field_path(&f.member); quote!(other.#field_path = #obj #ident;) - } - (Named(ident), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple) => { - quote!(#obj #ident,) - } + }, + (Named(ident), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple) => + quote!(#obj #ident,), (Named(ident), None, Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Tuple) => { let index = Unnamed(Index { index: f.idx as u32, span: Span::call_site() }); quote!(other.#index = #obj #ident;) - } - (Named(ident), None, Kind::FromOwned | Kind::FromRef, TypeHint::Struct | TypeHint::Unspecified | TypeHint::Unit) => { + }, + (Named(ident), None, Kind::FromOwned | Kind::FromRef, TypeHint::Struct | TypeHint::Unspecified | TypeHint::Unit) => if f.attrs.has_parent_attr(&ctx.struct_attr.ty) { match (ctx.kind.is_ref(), ctx.fallible) { (true, true) => quote!(#ident: value.try_into()?,), @@ -763,27 +781,25 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) } else { let field_path = get_field_path(&f.member); quote!(#ident: #obj #field_path,) - } - } + }, (Named(ident), None, Kind::FromOwned | Kind::FromRef, TypeHint::Tuple) => { let index = Unnamed(Index { index: f.idx as u32, span: Span::call_site() }); let field_path = if ctx.impl_type.is_variant() { get_field_path(&Named(format_ident!("f{}", index))) } else { get_field_path(&index) }; quote!(#ident: #obj #field_path,) - } - (Unnamed(index), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple | TypeHint::Unspecified) => { + }, + (Unnamed(index), None, Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple | TypeHint::Unspecified) => if ctx.has_post_init { let index2 = Unnamed(Index { index: idx as u32, span: Span::call_site() }); quote!(obj.#index2 = #obj #index;) } else { let index = if ctx.impl_type.is_variant() { format_ident!("f{}", index.index).to_token_stream() } else { index.to_token_stream() }; quote!(#obj #index,) - } - } + }, (Unnamed(index), None, Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Tuple | TypeHint::Unspecified) => { let index2 = Unnamed(Index { index: f.idx as u32, span: Span::call_site() }); quote!(other.#index2 = #obj #index;) - } - (Unnamed(index), None, Kind::FromOwned | Kind::FromRef, TypeHint::Tuple | TypeHint::Unspecified | TypeHint::Unit) => { + }, + (Unnamed(index), None, Kind::FromOwned | Kind::FromRef, TypeHint::Tuple | TypeHint::Unspecified | TypeHint::Unit) => if f.attrs.has_parent_attr(&ctx.struct_attr.ty) { match (ctx.kind.is_ref(), ctx.fallible) { (true, true) => quote!(value.try_into()?,), @@ -794,9 +810,8 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) } else { let field_path = if ctx.impl_type.is_variant() { get_field_path(&Named(format_ident!("f{}", index.index))) } else { get_field_path(&f.member) }; quote!(#obj #field_path,) - } - } - (Unnamed(_), None, _, TypeHint::Struct) => { + }, + (Unnamed(_), None, _, TypeHint::Struct) => if f.attrs.has_parent_attr(&ctx.struct_attr.ty) { match (ctx.kind.is_ref(), ctx.fallible) { (true, true) => quote!(value.try_into()?,), @@ -806,50 +821,45 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) } } else { unreachable!("6") - } - } + }, (Named(ident), Some(attr), Kind::OwnedInto | Kind::RefInto, TypeHint::Struct | TypeHint::Unspecified) => { let field_name = attr.get_field_name_or(&f.member); let right_side = attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); - if ctx.has_post_init { - quote!(obj.#field_name = #right_side;) - } else { - quote!(#field_name: #right_side,) - } - } + if ctx.has_post_init { quote!(obj.#field_name = #right_side;) } else { quote!(#field_name: #right_side,) } + }, (Named(ident), Some(attr), Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Struct | TypeHint::Unspecified) => { let field_path = get_field_path(attr.get_field_name_or(&f.member)); let right_side = attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); quote!(other.#field_path = #right_side;) - } + }, (Named(ident), Some(attr), Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple) => { let right_side = attr.get_action_or(Some(get_field_path(&f.member)), ctx, || quote!(#obj #ident)); quote!(#right_side,) - } + }, (Named(ident), Some(attr), Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Tuple) => { let field_path = get_field_path(&Unnamed(Index { index: idx as u32, span: Span::call_site() })); let right_side = attr.get_action_or(Some(ident.to_token_stream()), ctx, || quote!(#obj #ident)); quote!(other.#field_path = #right_side;) - } + }, (Named(ident), Some(attr), Kind::FromOwned | Kind::FromRef, TypeHint::Struct | TypeHint::Unspecified | TypeHint::Unit) => { let right_side = attr.get_stuff(&obj, get_field_path, ctx, || &f.member); quote!(#ident: #right_side,) - } + }, (Named(ident), Some(attr), Kind::FromOwned | Kind::FromRef, TypeHint::Tuple) => { let or = Named(format_ident!("f{}", f.idx)); let right_side = attr.get_stuff(&obj, get_field_path, ctx, || if ctx.impl_type.is_variant() { &or } else { &f.member }); quote!(#ident: #right_side,) - } + }, (Unnamed(index), Some(attr), Kind::OwnedInto | Kind::RefInto, TypeHint::Tuple | TypeHint::Unspecified) => { let index = if ctx.impl_type.is_variant() { Some(format_ident!("f{}", index.index).to_token_stream()) } else { Some(index.to_token_stream()) }; let right_side = attr.get_action_or(index.clone(), ctx, || quote!(#obj #index)); quote!(#right_side,) - } + }, (Unnamed(index), Some(attr), Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Tuple | TypeHint::Unspecified) => { let field_path = get_field_path(attr.get_field_name_or(&f.member)); let right_side = attr.get_action_or(Some(index.to_token_stream()), ctx, || quote!(#obj #index)); quote!(other.#field_path = #right_side;) - } + }, (Unnamed(index), Some(attr), Kind::OwnedInto | Kind::RefInto, TypeHint::Struct) => { let field_name = attr.get_ident(); let or = if ctx.impl_type.is_variant() { format_ident!("f{}", index.index).to_token_stream() } else { index.to_token_stream() }; @@ -859,17 +869,17 @@ fn render_struct_line(f: &Field, ctx: &ImplContext, hint: TypeHint, idx: usize) } else { quote!(#field_name: #right_side,) } - } + }, (Unnamed(index), Some(attr), Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Struct) => { let field_path = get_field_path(attr.get_ident()); let right_side = attr.get_action_or(Some(index.to_token_stream()), ctx, || quote!(#obj #index)); quote!(other.#field_path = #right_side;) - } + }, (Unnamed(index), Some(attr), Kind::FromOwned | Kind::FromRef, _) => { let or = Named(format_ident!("f{}", index.index)); let right_side = attr.get_stuff(&obj, get_field_path, ctx, || if ctx.impl_type.is_variant() { &or } else { &f.member }); quote!(#right_side,) - } + }, (_, _, Kind::OwnedInto | Kind::RefInto | Kind::OwnedIntoExisting | Kind::RefIntoExisting, TypeHint::Unit) => TokenStream::new(), } } @@ -898,7 +908,11 @@ fn render_enum_line(v: &Variant, ctx: &ImplContext) -> TokenStream { let type_hint = var.map_or(TypeHint::Unspecified, |x| x.type_hint); struct_attr.type_hint = type_hint; - let new_ctx = ImplContext { struct_attr: &struct_attr, impl_type: ImplType::Variant, ..*ctx }; + let new_ctx = ImplContext { + struct_attr: &struct_attr, + impl_type: ImplType::Variant, + ..*ctx + }; let empty_fields = variant_struct.fields.is_empty(); let destr = if empty_fields && (!new_ctx.kind.is_from() || type_hint.maybe(TypeHint::Unit)) { @@ -920,30 +934,30 @@ fn render_enum_line(v: &Variant, ctx: &ImplContext) -> TokenStream { match (v.named_fields, attr, lit, pat, &ctx.kind) { (_, None, None, None, _) => { quote!(#src::#ident #destr => #dst::#ident #init,) - } + }, (_, Some(attr), None, None, Kind::FromOwned | Kind::FromRef) => { let member = Named(ident.clone()); let right_side = attr.get_action_or(Some(quote!(#ident)), ctx, || quote!(#dst::#ident #init)); let ident2 = attr.get_field_name_or(&member); quote!(#src::#ident2 #destr => #right_side,) - } + }, (_, Some(attr), None, None, Kind::OwnedInto | Kind::RefInto) => { let member = Named(ident.clone()); let right_side = attr.get_stuff("e!(#dst::), |x| quote!(#x #init), ctx, || &member); quote!(#src::#ident #destr => #right_side,) - } + }, (_, None, Some(lit), None, Kind::FromOwned | Kind::FromRef) => { let left_side = &lit.tokens; quote!(#left_side => #dst::#ident #init,) - } + }, (_, None, Some(lit), None, Kind::OwnedInto | Kind::RefInto) => { let right_side = &lit.tokens; quote!(#src::#ident #destr => #right_side,) - } + }, (_, None, None, Some(pat), Kind::FromOwned | Kind::FromRef) => { let left_side = &pat.tokens; quote!(#left_side => #dst::#ident #init,) - } + }, (_, Some(attr), None, Some(_), Kind::OwnedInto | Kind::RefInto) => { let right_side = attr.get_action_or(None, ctx, TokenStream::new); quote!(#src::#ident #destr => #right_side,) @@ -1293,8 +1307,7 @@ impl<'a> ApplicableAttr<'a> { fn get_stuff TokenStream, F2: Fn() -> &'a Member>(&self, obj: &TokenStream, field_path: F1, ctx: &ImplContext, or: F2) -> TokenStream { match self { ApplicableAttr::Field(field_attr) => match (&field_attr.member, &field_attr.action) { - (Some(ident), Some(action)) => { - if let Unnamed(index) = ident { + (Some(ident), Some(action)) => if let Unnamed(index) = ident { if ctx.impl_type.is_variant() { let ident = Named(format_ident!("f{}", index.index)); quote_action(action, Some(field_path(&ident)), ctx) @@ -1303,8 +1316,7 @@ impl<'a> ApplicableAttr<'a> { } } else { quote_action(action, Some(field_path(ident)), ctx) - } - } + }, (Some(ident), None) => { let field_path = field_path(ident); quote!(#obj #field_path) diff --git a/o2o-impl/src/tests.rs b/o2o-impl/src/tests.rs index 59284b3..728f00c 100644 --- a/o2o-impl/src/tests.rs +++ b/o2o-impl/src/tests.rs @@ -928,12 +928,8 @@ fn missing_children_instruction(code_fragment: TokenStream, errs: Vec<(&str, boo for (ty, should_contain) in errs { match should_contain { - true => { - assert!(errors.iter().any(|x| x.to_string() == format!("Missing #[children(...)] instruction for {}", ty))) - } - false => { - assert!(!errors.iter().any(|x| x.to_string() == format!("Missing #[children(...)] instruction for {}", ty))) - } + true => assert!(errors.iter().any(|x| x.to_string() == format!("Missing #[children(...)] instruction for {}", ty))), + false => assert!(!errors.iter().any(|x| x.to_string() == format!("Missing #[children(...)] instruction for {}", ty))) } } } @@ -1249,9 +1245,7 @@ fn incomplete_field_attr_instruction(code_fragment: TokenStream, errs: Vec<(&str assert_eq!(errs.len(), errors.len()); for (field, ty, or_action) in errs { - assert!(errors - .iter() - .any(|x| x.to_string() == format!("Member 0 should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", if or_action { " or an action" } else { "" }, field, ty))) + assert!(errors.iter().any(|x| x.to_string() == format!("Member 0 should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", if or_action { " or an action" } else { "" }, field, ty))) } } else { assert!(output.is_ok()) @@ -1450,9 +1444,7 @@ fn incomplete_variant_field_attr_instruction(code_fragment: TokenStream, err_ty: assert_eq!(errs.len(), errors.len()); for (idx, variant, field, ty, or_action) in errs { - assert!(errors - .iter() - .any(|x| x.to_string() == format!("Member {} of a variant {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", idx, variant, if or_action { " or an action" } else { "" }, field, ty))) + assert!(errors.iter().any(|x| x.to_string() == format!("Member {} of a variant {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", idx, variant, if or_action { " or an action" } else { "" }, field, ty))) } } else { assert!(output.is_ok()) @@ -1540,9 +1532,7 @@ fn incomplete_field_attr_instruction_2(code_fragment: TokenStream, errs: Vec<(&s assert_eq!(errs.len(), errors.len()); for (field, ty, or_action) in errs { - assert!(errors - .iter() - .any(|x| x.to_string() == format!("Member trait instruction #[{}(...)] for member 0 should specify corresponding field name of the {}{}", field, ty, if or_action { " or an action" } else { "" }))) + assert!(errors.iter().any(|x| x.to_string() == format!("Member trait instruction #[{}(...)] for member 0 should specify corresponding field name of the {}{}", field, ty, if or_action { " or an action" } else { "" }))) } } else { assert!(output.is_ok()) diff --git a/o2o-impl/src/validate.rs b/o2o-impl/src/validate.rs index 750ee50..89815f1 100644 --- a/o2o-impl/src/validate.rs +++ b/o2o-impl/src/validate.rs @@ -60,14 +60,14 @@ pub(crate) fn validate(input: &DataType) -> Result<()> { bark_at_member_attr(&member_attrs.ghosts_attrs.iter().filter(|x| !x.applicable_to[&Kind::OwnedInto] && x.applicable_to[&Kind::RefInto]).collect(), "ghosts_ref", |_| f.member.span(), &mut errors); validate_dedicated_member_attrs(&member_attrs.parent_attrs, |x| x.container_ty.as_ref(), Some("parent"), member_span, &type_paths, &mut errors); - } + }, DataTypeMember::Variant(v) => { bark_at_member_attr(&member_attrs.parent_attrs, "parent", |_| v.ident.span(), &mut errors); validate_dedicated_member_attrs(&member_attrs.lit_attrs, |x| x.container_ty.as_ref(), Some("literal"), member_span, &type_paths, &mut errors); validate_dedicated_member_attrs(&member_attrs.pat_attrs, |x| x.container_ty.as_ref(), Some("pattern"), member_span, &type_paths, &mut errors); validate_dedicated_member_attrs(&member_attrs.type_hint_attrs, |x| x.container_ty.as_ref(), Some("type_hint"), member_span, &type_paths, &mut errors); - } + }, } validate_member_error_instrs(input, member_attrs, &mut errors) @@ -76,12 +76,12 @@ pub(crate) fn validate(input: &DataType) -> Result<()> { match input { DataType::Struct(s) => { validate_fields(s, attrs, &type_paths, &mut errors); - } + }, DataType::Enum(e) => { for v in &e.variants { validate_variant_fields(v, attrs, &type_paths, &mut errors); } - } + }, } if errors.is_empty() { @@ -96,57 +96,34 @@ pub(crate) fn validate(input: &DataType) -> Result<()> { } fn validate_error_instrs(input: &DataType, attrs: &DataTypeAttrs, errors: &mut HashMap) { - let postfix = |own: bool| { - if !own { - " To turn this message off, use #[o2o(allow_unknown)]" - } else { - "" - } - }; + let postfix = |own: bool| if !own { " To turn this message off, use #[o2o(allow_unknown)]" } else { "" }; for err in &attrs.error_instrs { match (input, err) { - (DataType::Enum(_), DataTypeInstruction::Misnamed { instr: instr @ "child", span, guess_name: _, own }) | (DataType::Enum(_), DataTypeInstruction::Misplaced { instr: instr @ ("parent" | "as_type"), span, own }) => { + (DataType::Enum(_), DataTypeInstruction::Misnamed { instr: instr @ "child", span, guess_name: _, own }) | + (DataType::Enum(_), DataTypeInstruction::Misplaced { instr: instr @ ("parent" | "as_type"), span, own }) => { errors.insert(format!("Member instruction '{}' is not applicable to enums.{}", instr, postfix(*own)), *span); - } - (_, DataTypeInstruction::Misnamed { instr: _, span, guess_name, own }) => { - errors.insert(format!("Perhaps you meant '{}'?{}", guess_name, postfix(*own)), *span); - } - (_, DataTypeInstruction::Misplaced { instr, span, own }) => { - errors.insert(format!("Member instruction '{}' should be used on a member.{}", instr, postfix(*own)), *span); - } - (_, DataTypeInstruction::UnrecognizedWithError { instr, span }) => { - errors.insert(format!("Struct instruction '{}' is not supported.", instr), *span); - } - _ => unreachable!("13"), + }, + (_, DataTypeInstruction::Misnamed { instr: _, span, guess_name, own }) => { errors.insert(format!("Perhaps you meant '{}'?{}", guess_name, postfix(*own)), *span); }, + (_, DataTypeInstruction::Misplaced { instr, span, own }) => { errors.insert(format!("Member instruction '{}' should be used on a member.{}", instr, postfix(*own)), *span); }, + (_, DataTypeInstruction::UnrecognizedWithError { instr, span }) => { errors.insert(format!("Struct instruction '{}' is not supported.", instr), *span); }, + _ => unreachable!("13") } } } fn validate_member_error_instrs(input: &DataType, attrs: &MemberAttrs, errors: &mut HashMap) { - let postfix = |own: bool| { - if !own { - " To turn this message off, use #[o2o(allow_unknown)]" - } else { - "" - } - }; + let postfix = |own: bool| if !own { " To turn this message off, use #[o2o(allow_unknown)]" } else { "" }; for err in &attrs.error_instrs { match (input, err) { (DataType::Enum(_), MemberInstruction::Misnamed { instr: instr @ "children", span, guess_name: _, own }) => { errors.insert(format!("Struct instruction '{}' is not applicable to enums.{}", instr, postfix(*own)), *span); } - (_, MemberInstruction::Misnamed { instr: _, span, guess_name, own }) => { - errors.insert(format!("Perhaps you meant '{}'?{}", guess_name, postfix(*own)), *span); - } - (_, MemberInstruction::Misplaced { instr, span, own }) => { - errors.insert(format!("Struct instruction '{}' should be used on a struct.{}", instr, postfix(*own)), *span); - } - (_, MemberInstruction::UnrecognizedWithError { instr, span }) => { - errors.insert(format!("Member instruction '{}' is not supported.", instr), *span); - } - _ => unreachable!("14"), + (_, MemberInstruction::Misnamed { instr: _, span, guess_name, own }) => { errors.insert(format!("Perhaps you meant '{}'?{}", guess_name, postfix(*own)), *span); }, + (_, MemberInstruction::Misplaced { instr, span, own }) => { errors.insert(format!("Struct instruction '{}' should be used on a struct.{}", instr, postfix(*own)), *span); }, + (_, MemberInstruction::UnrecognizedWithError { instr, span }) => { errors.insert(format!("Member instruction '{}' is not supported.", instr), *span); }, + _ => unreachable!("14") } } } @@ -262,16 +239,14 @@ fn validate_dedicated_member_attrs Option<&TypePath>>(attrs: &Ve } fn validate_fields(input: &Struct, data_type_attrs: &DataTypeAttrs, type_paths: &HashSet<&TypePath>, errors: &mut HashMap) { - let into_type_paths = data_type_attrs - .iter_for_kind_core(&Kind::OwnedInto, false) + let into_type_paths = data_type_attrs.iter_for_kind_core(&Kind::OwnedInto, false) .chain(data_type_attrs.iter_for_kind_core(&Kind::RefInto, false)) .chain(data_type_attrs.iter_for_kind_core(&Kind::OwnedInto, true)) .chain(data_type_attrs.iter_for_kind_core(&Kind::RefInto, true)) .map(|x| &x.ty) .collect::>(); - let from_type_paths = data_type_attrs - .iter_for_kind_core(&Kind::FromOwned, false) + let from_type_paths = data_type_attrs.iter_for_kind_core(&Kind::FromOwned, false) .chain(data_type_attrs.iter_for_kind_core(&Kind::FromRef, false)) .chain(data_type_attrs.iter_for_kind_core(&Kind::FromOwned, true)) .chain(data_type_attrs.iter_for_kind_core(&Kind::FromRef, true)) @@ -289,13 +264,13 @@ fn validate_fields(input: &Struct, data_type_attrs: &DataTypeAttrs, type_paths: if from_type_paths.contains(tp) { errors.insert(format!("Member instruction #[ghost(...)] for member '{}' should provide default value for type {}", field.member.to_token_stream(), tp.path_str), field.member.span()); } - } + }, None => { let field_name_str = field.member.to_token_stream().to_string(); for tp in from_type_paths.iter() { errors.insert(format!("Member instruction #[ghost(...)] for member '{}' should provide default value for type {}", field_name_str, tp.path_str), field.member.span()); } - } + }, } } @@ -315,19 +290,15 @@ fn validate_fields(input: &Struct, data_type_attrs: &DataTypeAttrs, type_paths: if into_type_paths.contains(tp) { check_child_errors(child_attr, data_type_attrs, tp, errors) } - } - None => { - for tp in into_type_paths.iter() { - check_child_errors(child_attr, data_type_attrs, tp, errors) - } - } + }, + None => for tp in into_type_paths.iter() { + check_child_errors(child_attr, data_type_attrs, tp, errors) + }, } } if !input.named_fields { - let data_type_attrs: Vec<(&TraitAttrCore, Kind)> = data_type_attrs - .iter_for_kind_core(&Kind::OwnedInto, false) - .map(|x| (x, Kind::OwnedInto)) + let data_type_attrs: Vec<(&TraitAttrCore, Kind)> = data_type_attrs.iter_for_kind_core(&Kind::OwnedInto, false).map(|x| (x, Kind::OwnedInto)) .chain(data_type_attrs.iter_for_kind_core(&Kind::RefInto, false).map(|x| (x, Kind::RefInto))) .chain(data_type_attrs.iter_for_kind_core(&Kind::OwnedIntoExisting, false).map(|x| (x, Kind::OwnedIntoExisting))) .chain(data_type_attrs.iter_for_kind_core(&Kind::RefIntoExisting, false).map(|x| (x, Kind::RefIntoExisting))) @@ -357,16 +328,7 @@ fn validate_fields(input: &Struct, data_type_attrs: &DataTypeAttrs, type_paths: errors.insert(format!("Member trait instruction #[{}(...)] for member {} should specify corresponding field name of the {}", field_attr.original_instr, field.member.to_token_stream(), data_type_attr.ty.path_str), field.member.span()); } } else { - errors.insert( - format!( - "Member {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", - field.member.to_token_stream(), - if kind == Kind::FromOwned || kind == Kind::FromRef { " or an action" } else { "" }, - FallibleKind(kind, false), - data_type_attr.ty.path_str - ), - field.member.span(), - ); + errors.insert(format!("Member {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", field.member.to_token_stream(), if kind == Kind::FromOwned || kind == Kind::FromRef { " or an action" } else { "" }, FallibleKind(kind, false), data_type_attr.ty.path_str), field.member.span()); } } } @@ -376,9 +338,7 @@ fn validate_fields(input: &Struct, data_type_attrs: &DataTypeAttrs, type_paths: fn validate_variant_fields(input: &Variant, data_type_attrs: &DataTypeAttrs, _type_paths: &HashSet<&TypePath>, errors: &mut HashMap) { if !input.named_fields { - let data_type_attrs: Vec<(&TraitAttr, Kind)> = data_type_attrs - .iter_for_kind(&Kind::OwnedInto, false) - .map(|x| (x, Kind::OwnedInto)) + let data_type_attrs: Vec<(&TraitAttr, Kind)> = data_type_attrs.iter_for_kind(&Kind::OwnedInto, false).map(|x| (x, Kind::OwnedInto)) .chain(data_type_attrs.iter_for_kind(&Kind::RefInto, false).map(|x| (x, Kind::RefInto))) .chain(data_type_attrs.iter_for_kind(&Kind::OwnedIntoExisting, false).map(|x| (x, Kind::OwnedIntoExisting))) .chain(data_type_attrs.iter_for_kind(&Kind::RefIntoExisting, false).map(|x| (x, Kind::RefIntoExisting))) @@ -408,17 +368,7 @@ fn validate_variant_fields(input: &Variant, data_type_attrs: &DataTypeAttrs, _ty errors.insert(format!("Member trait instruction #[{}(...)] for member {} should specify corresponding field name of the {}", field_attr.original_instr, field.member.to_token_stream(), data_type_attr.core.ty.path_str), field.member.span()); } } else { - errors.insert( - format!( - "Member {} of a variant {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", - field.member.to_token_stream(), - input.ident, - if kind == Kind::FromOwned || kind == Kind::FromRef { " or an action" } else { "" }, - FallibleKind(kind, data_type_attr.fallible), - data_type_attr.core.ty.path_str - ), - field.member.span(), - ); + errors.insert(format!("Member {} of a variant {} should have member trait instruction with field name{}, that corresponds to #[{}({}...)] trait instruction", field.member.to_token_stream(), input.ident, if kind == Kind::FromOwned || kind == Kind::FromRef { " or an action" } else { "" }, FallibleKind(kind, data_type_attr.fallible), data_type_attr.core.ty.path_str), field.member.span()); } } } @@ -435,10 +385,10 @@ fn check_child_errors(child_attr: &ChildAttr, struct_attrs: &DataTypeAttrs, tp: if !children_attr.children.iter().any(|x| x.check_match(path)) { errors.insert(format!("Missing '{}: [Type Path]' instruction for type {}", path, tp.path_str), tp.span); } - } + }, None => { errors.insert(format!("Missing #[children(...)] instruction for {}", tp.path_str), tp.span); - } + }, } } } diff --git a/o2o-tests/tests/10_multiple_child_attr_tests.rs b/o2o-tests/tests/10_multiple_child_attr_tests.rs index bfd2390..8fd136f 100644 --- a/o2o-tests/tests/10_multiple_child_attr_tests.rs +++ b/o2o-tests/tests/10_multiple_child_attr_tests.rs @@ -156,7 +156,10 @@ fn named2unnamed() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -174,7 +177,10 @@ fn named2named_reverse() { fn named2unnamed_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -234,7 +240,10 @@ fn named2unnamed_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -252,7 +261,10 @@ fn named2named_reverse_ref() { fn named2unnamed_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; diff --git a/o2o-tests/tests/10_multiple_child_attr_tests_fallible.rs b/o2o-tests/tests/10_multiple_child_attr_tests_fallible.rs index e6bb785..dcda5f9 100644 --- a/o2o-tests/tests/10_multiple_child_attr_tests_fallible.rs +++ b/o2o-tests/tests/10_multiple_child_attr_tests_fallible.rs @@ -156,7 +156,10 @@ fn named2unnamed() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -174,7 +177,10 @@ fn named2named_reverse() { fn named2unnamed_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -234,7 +240,10 @@ fn named2unnamed_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -252,7 +261,10 @@ fn named2named_reverse_ref() { fn named2unnamed_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; diff --git a/o2o-tests/tests/14_parent_attr_tests.rs b/o2o-tests/tests/14_parent_attr_tests.rs index b09e403..d789ae6 100644 --- a/o2o-tests/tests/14_parent_attr_tests.rs +++ b/o2o-tests/tests/14_parent_attr_tests.rs @@ -96,7 +96,10 @@ fn named2named() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -135,7 +138,10 @@ fn named2named_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -209,7 +215,10 @@ fn unnamed2unnamed_reverse_ref() { fn existing_named2named() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -228,7 +237,10 @@ fn existing_named2named() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; diff --git a/o2o-tests/tests/14_parent_attr_tests_fallible.rs b/o2o-tests/tests/14_parent_attr_tests_fallible.rs index cb8b93b..b41d436 100644 --- a/o2o-tests/tests/14_parent_attr_tests_fallible.rs +++ b/o2o-tests/tests/14_parent_attr_tests_fallible.rs @@ -96,7 +96,10 @@ fn named2named() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -135,7 +138,10 @@ fn named2named_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -209,7 +215,10 @@ fn unnamed2unnamed_reverse_ref() { fn existing_named2named() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -228,7 +237,10 @@ fn existing_named2named() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; diff --git a/o2o-tests/tests/15_multiple_parent_attr_tests.rs b/o2o-tests/tests/15_multiple_parent_attr_tests.rs index 2a174f0..77166d0 100644 --- a/o2o-tests/tests/15_multiple_parent_attr_tests.rs +++ b/o2o-tests/tests/15_multiple_parent_attr_tests.rs @@ -169,7 +169,10 @@ fn named2unnamed() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -187,7 +190,10 @@ fn named2named_reverse() { fn named2unnamed_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -247,7 +253,10 @@ fn named2unnamed_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -265,7 +274,10 @@ fn named2named_reverse_ref() { fn named2unnamed_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -395,7 +407,10 @@ fn unnamed2named_reverse_ref() { fn named2named_2() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -413,7 +428,10 @@ fn named2named_2() { fn named2named_2_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -431,7 +449,10 @@ fn named2named_2_ref() { fn named2named_2_reverse() { let model = EntityModel { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -449,7 +470,10 @@ fn named2named_2_reverse() { fn named2named_2_ref_reverse() { let model = &EntityModel { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -467,7 +491,10 @@ fn named2named_2_ref_reverse() { fn existing_named2named() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -486,7 +513,10 @@ fn existing_named2named() { fn existing_named2unnamed() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -505,7 +535,10 @@ fn existing_named2unnamed() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -524,7 +557,10 @@ fn existing_named2named_ref() { fn existing_named2unnamed_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; diff --git a/o2o-tests/tests/15_multiple_parent_attr_tests_fallible.rs b/o2o-tests/tests/15_multiple_parent_attr_tests_fallible.rs index a66f7bb..ae91e24 100644 --- a/o2o-tests/tests/15_multiple_parent_attr_tests_fallible.rs +++ b/o2o-tests/tests/15_multiple_parent_attr_tests_fallible.rs @@ -169,7 +169,10 @@ fn named2unnamed() { fn named2named_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -187,7 +190,10 @@ fn named2named_reverse() { fn named2unnamed_reverse() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -247,7 +253,10 @@ fn named2unnamed_ref() { fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -265,7 +274,10 @@ fn named2named_reverse_ref() { fn named2unnamed_reverse_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -395,7 +407,10 @@ fn unnamed2named_reverse_ref() { fn named2named_2() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -413,7 +428,10 @@ fn named2named_2() { fn named2named_2_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -431,7 +449,10 @@ fn named2named_2_ref() { fn named2named_2_reverse() { let model = EntityModel { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -449,7 +470,10 @@ fn named2named_2_reverse() { fn named2named_2_ref_reverse() { let model = &EntityModel { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -467,7 +491,10 @@ fn named2named_2_ref_reverse() { fn existing_named2named() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -486,7 +513,10 @@ fn existing_named2named() { fn existing_named2unnamed() { let entity = Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -505,7 +535,10 @@ fn existing_named2unnamed() { fn existing_named2named_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; @@ -524,7 +557,10 @@ fn existing_named2named_ref() { fn existing_named2unnamed_ref() { let entity = &Entity { parent_int: 123, - base: BaseEntity { base: Base { base_int_2: 321, another_base_int: 456 }, base_entity_int: 654 }, + base: BaseEntity { + base: Base { base_int_2: 321, another_base_int: 456 }, + base_entity_int: 654, + }, child: Child { child_int: 789, another_child_int: 987 }, }; diff --git a/o2o-tests/tests/17_generic_path_tests.rs b/o2o-tests/tests/17_generic_path_tests.rs index 92bb2a5..699cd3d 100644 --- a/o2o-tests/tests/17_generic_path_tests.rs +++ b/o2o-tests/tests/17_generic_path_tests.rs @@ -78,7 +78,10 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.into(); @@ -120,7 +123,10 @@ fn named2named_different_name_and_type_ref() { #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = &Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.into(); diff --git a/o2o-tests/tests/17_generic_path_tests_fallible.rs b/o2o-tests/tests/17_generic_path_tests_fallible.rs index 78969aa..98793bc 100644 --- a/o2o-tests/tests/17_generic_path_tests_fallible.rs +++ b/o2o-tests/tests/17_generic_path_tests_fallible.rs @@ -78,7 +78,10 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.try_into().unwrap(); @@ -120,7 +123,10 @@ fn named2named_different_name_and_type_ref() { #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = &Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.try_into().unwrap(); diff --git a/o2o-tests/tests/18_where_attr_tests.rs b/o2o-tests/tests/18_where_attr_tests.rs index 647182a..859156d 100644 --- a/o2o-tests/tests/18_where_attr_tests.rs +++ b/o2o-tests/tests/18_where_attr_tests.rs @@ -82,7 +82,10 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.into(); @@ -124,7 +127,10 @@ fn named2named_different_name_and_type_ref() { #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = &Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.into(); diff --git a/o2o-tests/tests/18_where_attr_tests_fallible.rs b/o2o-tests/tests/18_where_attr_tests_fallible.rs index 82d4068..bf00596 100644 --- a/o2o-tests/tests/18_where_attr_tests_fallible.rs +++ b/o2o-tests/tests/18_where_attr_tests_fallible.rs @@ -82,7 +82,10 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.try_into().unwrap(); @@ -124,7 +127,10 @@ fn named2named_different_name_and_type_ref() { #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = &Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.try_into().unwrap(); diff --git a/o2o-tests/tests/19_deep_ghost_attr_tests.rs b/o2o-tests/tests/19_deep_ghost_attr_tests.rs index 3fc8f21..7068b07 100644 --- a/o2o-tests/tests/19_deep_ghost_attr_tests.rs +++ b/o2o-tests/tests/19_deep_ghost_attr_tests.rs @@ -135,7 +135,12 @@ fn named2named() { #[test] fn named2named_reverse() { - let car_dto = CarDto { number_of_doors: 2, number_of_seats: 4, brand: "Trabant".into(), year: 1960 }; + let car_dto = CarDto { + number_of_doors: 2, + number_of_seats: 4, + brand: "Trabant".into(), + year: 1960, + }; let car: Car = car_dto.into(); @@ -166,7 +171,12 @@ fn named2named_ref() { #[test] fn named2named_reverse_ref() { - let car_dto = &CarDto { number_of_doors: 2, number_of_seats: 4, brand: "Trabant".into(), year: 1960 }; + let car_dto = &CarDto { + number_of_doors: 2, + number_of_seats: 4, + brand: "Trabant".into(), + year: 1960, + }; let car: Car = car_dto.into(); @@ -179,7 +189,12 @@ fn named2named_reverse_ref() { #[test] fn existing_named2named() { - let car_dto = CarDto { number_of_doors: 2, number_of_seats: 4, brand: "Trabant".into(), year: 1960 }; + let car_dto = CarDto { + number_of_doors: 2, + number_of_seats: 4, + brand: "Trabant".into(), + year: 1960, + }; let mut car: Car = Default::default(); car_dto.into_existing(&mut car); @@ -193,7 +208,12 @@ fn existing_named2named() { #[test] fn existing_named2named_reverse() { - let car_dto = &CarDto { number_of_doors: 2, number_of_seats: 4, brand: "Trabant".into(), year: 1960 }; + let car_dto = &CarDto { + number_of_doors: 2, + number_of_seats: 4, + brand: "Trabant".into(), + year: 1960, + }; let mut car: Car = Default::default(); car_dto.into_existing(&mut car); diff --git a/o2o-tests/tests/19_deep_ghost_attr_tests_fallible.rs b/o2o-tests/tests/19_deep_ghost_attr_tests_fallible.rs index 0225d79..6b7e9d6 100644 --- a/o2o-tests/tests/19_deep_ghost_attr_tests_fallible.rs +++ b/o2o-tests/tests/19_deep_ghost_attr_tests_fallible.rs @@ -233,7 +233,9 @@ fn named2named_2() { division: Division { base: Base { id: 456, name: "TestDivision".try_into().unwrap() }, league_id: 789, - league: League { base: Base { id: 789, name: "TestLeague".try_into().unwrap() } }, + league: League { + base: Base { id: 789, name: "TestLeague".try_into().unwrap() }, + }, }, }; @@ -276,7 +278,9 @@ fn named2named_ref_2() { division: Division { base: Base { id: 456, name: "TestDivision".try_into().unwrap() }, league_id: 789, - league: League { base: Base { id: 789, name: "TestLeague".try_into().unwrap() } }, + league: League { + base: Base { id: 789, name: "TestLeague".try_into().unwrap() }, + }, }, }; diff --git a/o2o-tests/tests/20_as_type_attr_tests.rs b/o2o-tests/tests/20_as_type_attr_tests.rs index 15807e8..99d62c3 100644 --- a/o2o-tests/tests/20_as_type_attr_tests.rs +++ b/o2o-tests/tests/20_as_type_attr_tests.rs @@ -68,7 +68,12 @@ fn named2named_different_types() { #[test] fn named2named_different_types_reverse() { - let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0, another_float: 654.0 }; + let named = NamedStruct { + some_int: 123, + another_int: 321, + some_float: 456.0, + another_float: 654.0, + }; let dto: NamedStructDto = named.into(); @@ -76,7 +81,12 @@ fn named2named_different_types_reverse() { assert_eq!(321, dto.different_int); assert_eq!(456.0, dto.some_float); - let model = NamedStructModel { some_int: 123, different_int: 127, some_float: 456.0, another_float: 654.0 }; + let model = NamedStructModel { + some_int: 123, + different_int: 127, + some_float: 456.0, + another_float: 654.0, + }; let dto: NamedStructDto = model.into(); @@ -112,7 +122,12 @@ fn named2named_different_types_ref() { #[test] fn named2named_different_types_reverse_ref() { - let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0, another_float: 654.0 }; + let named = &NamedStruct { + some_int: 123, + another_int: 321, + some_float: 456.0, + another_float: 654.0, + }; let dto: NamedStructDto = named.into(); @@ -121,7 +136,12 @@ fn named2named_different_types_reverse_ref() { assert_eq!(named.some_float, dto.some_float as f32); assert_eq!(named.another_float, dto.different_float as f64); - let model = &NamedStructModel { some_int: 123, different_int: 127, some_float: 456.0, another_float: 654.0 }; + let model = &NamedStructModel { + some_int: 123, + different_int: 127, + some_float: 456.0, + another_float: 654.0, + }; let dto: NamedStructDto = model.into(); diff --git a/o2o-tests/tests/20_as_type_attr_tests_fallible.rs b/o2o-tests/tests/20_as_type_attr_tests_fallible.rs index 5213b0c..6921eec 100644 --- a/o2o-tests/tests/20_as_type_attr_tests_fallible.rs +++ b/o2o-tests/tests/20_as_type_attr_tests_fallible.rs @@ -68,7 +68,12 @@ fn named2named_different_types() { #[test] fn named2named_different_types_reverse() { - let named = NamedStruct { some_int: 123, another_int: 321, some_float: 456.0, another_float: 654.0 }; + let named = NamedStruct { + some_int: 123, + another_int: 321, + some_float: 456.0, + another_float: 654.0, + }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -76,7 +81,12 @@ fn named2named_different_types_reverse() { assert_eq!(321, dto.different_int); assert_eq!(456.0, dto.some_float); - let model = NamedStructModel { some_int: 123, different_int: 127, some_float: 456.0, another_float: 654.0 }; + let model = NamedStructModel { + some_int: 123, + different_int: 127, + some_float: 456.0, + another_float: 654.0, + }; let dto: NamedStructDto = model.try_into().unwrap(); @@ -112,7 +122,12 @@ fn named2named_different_types_ref() { #[test] fn named2named_different_types_reverse_ref() { - let named = &NamedStruct { some_int: 123, another_int: 321, some_float: 456.0, another_float: 654.0 }; + let named = &NamedStruct { + some_int: 123, + another_int: 321, + some_float: 456.0, + another_float: 654.0, + }; let dto: NamedStructDto = named.try_into().unwrap(); @@ -121,7 +136,12 @@ fn named2named_different_types_reverse_ref() { assert_eq!(named.some_float, dto.some_float as f32); assert_eq!(named.another_float, dto.different_float as f64); - let model = &NamedStructModel { some_int: 123, different_int: 127, some_float: 456.0, another_float: 654.0 }; + let model = &NamedStructModel { + some_int: 123, + different_int: 127, + some_float: 456.0, + another_float: 654.0, + }; let dto: NamedStructDto = model.try_into().unwrap(); diff --git a/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests.rs b/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests.rs index 959c2c9..5a459fc 100644 --- a/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests.rs +++ b/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests.rs @@ -149,7 +149,10 @@ fn named2unnamed_ref() { #[test] fn named2named_uneven() { - let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto2 = p.into(); @@ -160,7 +163,10 @@ fn named2named_uneven() { #[test] fn named2named_uneven_ref() { - let parent = &Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let parent = &Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto2 = parent.into(); @@ -245,7 +251,10 @@ fn named2named_different_types_reverse_ref() { #[test] fn named2named_child() { - let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto = p.into(); diff --git a/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests_fallible.rs b/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests_fallible.rs index 1127bac..c8b44cf 100644 --- a/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests_fallible.rs +++ b/o2o-tests/tests/3_field_level_inline_at_expr_only_attr_tests_fallible.rs @@ -149,7 +149,10 @@ fn named2unnamed_ref() { #[test] fn named2named_uneven() { - let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto2 = p.try_into().unwrap(); @@ -160,7 +163,10 @@ fn named2named_uneven() { #[test] fn named2named_uneven_ref() { - let parent = &Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let parent = &Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto2 = parent.try_into().unwrap(); @@ -245,7 +251,10 @@ fn named2named_different_types_reverse_ref() { #[test] fn named2named_child() { - let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto = p.try_into().unwrap(); diff --git a/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests.rs b/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests.rs index d00a41f..47d9bd3 100644 --- a/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests.rs +++ b/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests.rs @@ -160,7 +160,10 @@ fn named2named_different_types_reverse_ref() { #[test] fn named2named_child() { - let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto = p.into(); diff --git a/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests_fallible.rs b/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests_fallible.rs index 29cb8ca..f05f566 100644 --- a/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests_fallible.rs +++ b/o2o-tests/tests/4_field_level_inline_tilde_expr_only_attr_tests_fallible.rs @@ -160,7 +160,10 @@ fn named2named_different_types_reverse_ref() { #[test] fn named2named_child() { - let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto = p.try_into().unwrap(); diff --git a/o2o-tests/tests/5_field_level_closure_only_attr_tests.rs b/o2o-tests/tests/5_field_level_closure_only_attr_tests.rs index d5b8e81..8d9b8ad 100644 --- a/o2o-tests/tests/5_field_level_closure_only_attr_tests.rs +++ b/o2o-tests/tests/5_field_level_closure_only_attr_tests.rs @@ -32,7 +32,10 @@ struct ChildDto { #[test] fn named2named_child() { - let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto = p.into(); @@ -57,7 +60,10 @@ fn named2named_child_reverse() { #[test] fn named2named_child_ref() { - let p = &Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = &Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto = p.into(); diff --git a/o2o-tests/tests/5_field_level_closure_only_attr_tests_fallible.rs b/o2o-tests/tests/5_field_level_closure_only_attr_tests_fallible.rs index cbfc3e1..313016f 100644 --- a/o2o-tests/tests/5_field_level_closure_only_attr_tests_fallible.rs +++ b/o2o-tests/tests/5_field_level_closure_only_attr_tests_fallible.rs @@ -32,7 +32,10 @@ struct ChildDto { #[test] fn named2named_child() { - let p = Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto = p.try_into().unwrap(); @@ -57,7 +60,10 @@ fn named2named_child_reverse() { #[test] fn named2named_child_ref() { - let p = &Parent { parent_int: 123, child: Child { child_int: 321, another_child_int: 456 } }; + let p = &Parent { + parent_int: 123, + child: Child { child_int: 321, another_child_int: 456 }, + }; let dto: ParentDto = p.try_into().unwrap(); diff --git a/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests.rs b/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests.rs index 016a871..0232a2c 100644 --- a/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests.rs +++ b/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests.rs @@ -70,7 +70,10 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.into(); diff --git a/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests_fallible.rs b/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests_fallible.rs index 27fd19d..72485df 100644 --- a/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests_fallible.rs +++ b/o2o-tests/tests/6_field_level_ident_and_inline_expr_tests_fallible.rs @@ -70,7 +70,10 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.try_into().unwrap(); diff --git a/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests.rs b/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests.rs index 4faca78..a326cb5 100644 --- a/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests.rs +++ b/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests.rs @@ -71,7 +71,10 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.into(); @@ -113,7 +116,10 @@ fn named2named_different_name_and_type_ref() { #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = &Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.into(); diff --git a/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests_fallible.rs b/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests_fallible.rs index c820992..743fc60 100644 --- a/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests_fallible.rs +++ b/o2o-tests/tests/7_field_level_ident_and_inline_expr_more_tests_fallible.rs @@ -71,7 +71,10 @@ fn named2named_different_name_and_type() { #[test] fn named2named_different_name_and_type_reverse() { - let p = Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.try_into().unwrap(); @@ -113,7 +116,10 @@ fn named2named_different_name_and_type_ref() { #[test] fn named2named_different_name_and_type_reverse_ref() { - let p = &Parent { parent_int: 987, child: Child { child_int: 456, another_child_int: 123 } }; + let p = &Parent { + parent_int: 987, + child: Child { child_int: 456, another_child_int: 123 }, + }; let dto: ParentDto = p.try_into().unwrap(); diff --git a/o2o-tests/tests/9_child_attr_tests.rs b/o2o-tests/tests/9_child_attr_tests.rs index b72cd17..e99b6b3 100644 --- a/o2o-tests/tests/9_child_attr_tests.rs +++ b/o2o-tests/tests/9_child_attr_tests.rs @@ -97,7 +97,11 @@ fn named2named_reverse() { let entity = Entity { parent_int: 123, base: BaseEntity { - base: Base { base_int_2: 321, another_base_int: 456, some_string: "Test".into() }, + base: Base { + base_int_2: 321, + another_base_int: 456, + some_string: "Test".into(), + }, base_entity_int: 654, }, child: Child { child_int: 789, another_child_int: 987 }, @@ -142,7 +146,11 @@ fn named2named_reverse_ref() { let entity = &Entity { parent_int: 123, base: BaseEntity { - base: Base { base_int_2: 321, another_base_int: 456, some_string: "Test".into() }, + base: Base { + base_int_2: 321, + another_base_int: 456, + some_string: "Test".into(), + }, base_entity_int: 654, }, child: Child { child_int: 789, another_child_int: 987 }, diff --git a/rustfmt.toml b/rustfmt.toml index d2904cf..2dced28 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -2,4 +2,5 @@ max_width = 300 struct_lit_width = 75 array_width = 100 chain_width = 200 -fn_call_width = 250 \ No newline at end of file +fn_call_width = 250 +match_block_trailing_comma = true \ No newline at end of file