| 1 | mod modelsrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/; |
| 2 | |
| 3 | use modelsrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/::{FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/field_attribute/FieldAttributeBuilder#, TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/TypeAttributeBuilder#}; |
| 4 | use quoterust-analyzer cargo quote 1.0.47 crate/::quoterust-analyzer cargo quote 1.0.47 quote!; |
| 5 | use synrust-analyzer cargo syn 2.0.119 crate/::{Datarust-analyzer cargo syn 2.0.119 derive/Data#, DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#, Metarust-analyzer cargo syn 2.0.119 attr/Meta#}; |
| 6 | |
| 7 | use superrust-analyzer cargo educe 0.6.0 trait_handlers/::TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler#; |
| 8 | use craterust-analyzer cargo educe 0.6.0 crate/::Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#; |
| 9 | |
| 10 | pub(craterust-analyzer cargo educe 0.6.0 crate/) struct CopyHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/copy/CopyHandler#; |
| 11 | |
| 12 | impl TraitHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/TraitHandler# for CopyHandlerrust-analyzer cargo educe 0.6.0 trait_handlers/copy/CopyHandler# { |
| 13 | #[inline] |
| 14 | fn trait_meta_handlerrust-analyzer cargo educe 0.6.0 trait_handlers/copy/impl#[CopyHandler][TraitHandler]trait_meta_handler().( |
| 15 | ast: &DeriveInputrust-analyzer cargo syn 2.0.119 derive/DeriveInput#, |
| 16 | token_stream: &mut proc_macro2rust-analyzer cargo proc-macro2 1.0.107 crate/::TokenStreamrust-analyzer cargo proc-macro2 1.0.107 TokenStream#, |
| 17 | traits: &[Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#], |
| 18 | meta: &Metarust-analyzer cargo syn 2.0.119 attr/Meta#, |
| 19 | ) -> synrust-analyzer cargo syn 2.0.119 crate/::Resultrust-analyzer cargo syn 2.0.119 error/Result#<()> { |
| 20 | #[cfg(feature = "Clone")] |
| 21 | let contains_clone = traits.containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]contains().(&Traitrust-analyzer cargo educe 0.6.0 supported_traits/Trait#::Clonerust-analyzer cargo educe 0.6.0 supported_traits/Trait#Clone#); |
| 22 | |
| 23 | #[cfg(not(feature = "Clone"))] |
| 24 | let contains_clone = false; |
| 25 | |
| 26 | let type_attribute = TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/TypeAttributeBuilder# { |
| 27 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/TypeAttributeBuilder#enable_flag.: true, |
| 28 | enable_boundrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/TypeAttributeBuilder#enable_bound.: !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().contains_clone, |
| 29 | } |
| 30 | .build_from_copy_metarust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/impl#[TypeAttributeBuilder]build_from_copy_meta().(meta)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 31 | |
| 32 | let mut field_types = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]; |
| 33 | |
| 34 | // if `contains_clone` is true, the implementation is handled by the `Clone` attribute, and field attributes is also handled by the `Clone` attribute |
| 35 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().contains_clone { |
| 36 | match &ast.datarust-analyzer cargo syn 2.0.119 derive/DeriveInput#data. { |
| 37 | Datarust-analyzer cargo syn 2.0.119 derive/Data#::Structrust-analyzer cargo syn 2.0.119 derive/Data#Struct#(data) => { |
| 38 | for field in data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataStruct#fields..iterrust-analyzer cargo syn 2.0.119 data/impl#[Fields]iter().() { |
| 39 | field_types.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(&field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty.); |
| 40 | let _ = |
| 41 | FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/field_attribute/FieldAttributeBuilder#.build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/field_attribute/impl#[FieldAttributeBuilder]build_from_attributes().(&field.attrsrust-analyzer cargo syn 2.0.119 data/Field#attrs., traits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 42 | } |
| 43 | }, |
| 44 | Datarust-analyzer cargo syn 2.0.119 derive/Data#::Enumrust-analyzer cargo syn 2.0.119 derive/Data#Enum#(data) => { |
| 45 | for variant in data.variantsrust-analyzer cargo syn 2.0.119 derive/DataEnum#variants..iterrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]iter().() { |
| 46 | let _ = TypeAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/TypeAttributeBuilder# { |
| 47 | enable_flagrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/TypeAttributeBuilder#enable_flag.: false, enable_boundrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/TypeAttributeBuilder#enable_bound.: false |
| 48 | } |
| 49 | .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/impl#[TypeAttributeBuilder]build_from_attributes().(&variant.attrsrust-analyzer cargo syn 2.0.119 data/Variant#attrs., traits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 50 | |
| 51 | for field in variant.fieldsrust-analyzer cargo syn 2.0.119 data/Variant#fields..iterrust-analyzer cargo syn 2.0.119 data/impl#[Fields]iter().() { |
| 52 | field_types.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(&field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty.); |
| 53 | let _ = FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/field_attribute/FieldAttributeBuilder# |
| 54 | .build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/field_attribute/impl#[FieldAttributeBuilder]build_from_attributes().(&field.attrsrust-analyzer cargo syn 2.0.119 data/Field#attrs., traits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 55 | } |
| 56 | } |
| 57 | }, |
| 58 | Datarust-analyzer cargo syn 2.0.119 derive/Data#::Unionrust-analyzer cargo syn 2.0.119 derive/Data#Union#(data) => { |
| 59 | for field in data.fieldsrust-analyzer cargo syn 2.0.119 derive/DataUnion#fields..namedrust-analyzer cargo syn 2.0.119 data/FieldsNamed#named..iterrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]iter().() { |
| 60 | field_types.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(&field.tyrust-analyzer cargo syn 2.0.119 data/Field#ty.); |
| 61 | let _ = |
| 62 | FieldAttributeBuilderrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/field_attribute/FieldAttributeBuilder#.build_from_attributesrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/field_attribute/impl#[FieldAttributeBuilder]build_from_attributes().(&field.attrsrust-analyzer cargo syn 2.0.119 data/Field#attrs., traits)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 63 | } |
| 64 | }, |
| 65 | } |
| 66 | |
| 67 | let ident = &ast.identrust-analyzer cargo syn 2.0.119 derive/DeriveInput#ident.; |
| 68 | |
| 69 | let bound = |
| 70 | type_attribute.boundrust-analyzer cargo educe 0.6.0 trait_handlers/copy/models/type_attribute/TypeAttribute#bound..into_where_predicates_by_generic_parameters_check_typesrust-analyzer cargo educe 0.6.0 common/bound/impl#[Bound]into_where_predicates_by_generic_parameters_check_types().( |
| 71 | &ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..paramsrust-analyzer cargo syn 2.0.119 generics/Generics#params., |
| 72 | &synrust-analyzer cargo syn 2.0.119 crate/::parse2rust-analyzer cargo syn 2.0.119 parse2().(quoterust-analyzer cargo quote 1.0.47 quote!!(::core::marker::Copy)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 73 | &field_types, |
| 74 | &[quoterust-analyzer cargo quote 1.0.47 quote!! {::core::clone::Clone}], |
| 75 | ); |
| 76 | |
| 77 | let mut generics = ast.genericsrust-analyzer cargo syn 2.0.119 derive/DeriveInput#generics..clonerust-analyzer cargo syn 2.0.119 gen/clone/impl#[`crate::Generics`][Clone]clone().(); |
| 78 | let where_clause = generics.make_where_clauserust-analyzer cargo syn 2.0.119 generics/impl#[Generics]make_where_clause().(); |
| 79 | |
| 80 | for where_predicate in bound { |
| 81 | where_clause.predicatesrust-analyzer cargo syn 2.0.119 generics/WhereClause#predicates..pushrust-analyzer cargo syn 2.0.119 punctuated/impl#[`Punctuated<T, P>`]push().(where_predicate); |
| 82 | } |
| 83 | |
| 84 | let (impl_generics, ty_generics, where_clause) = generics.split_for_implrust-analyzer cargo syn 2.0.119 generics/impl#[Generics]split_for_impl().(); |
| 85 | |
| 86 | token_stream.extendrust-analyzer cargo proc-macro2 1.0.107 impl#[TokenStream][`Extend<TokenTree>`]extend().(quoterust-analyzer cargo quote 1.0.47 quote!! { |
| 87 | impl #impl_generics ::core::marker::Copy for #ident #ty_generics #where_clause { |
| 88 | } |
| 89 | }); |
| 90 | } |
| 91 | |
| 92 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 93 | } |
| 94 | } |