Debian Codegraph @

src/internals/imp.rs

raw symbols SCIP
1 use superrust-analyzer cargo daft-derive 0.1.5 internals/::error_storerust-analyzer cargo daft-derive 0.1.5 internals/error_store/::{ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#, ErrorStorerust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorStore#};
2 use proc_macro2rust-analyzer cargo proc-macro2 1.0.93 crate/::{Spanrust-analyzer cargo proc-macro2 1.0.93 Span#, TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#};
3 use quoterust-analyzer cargo quote 1.0.38 crate/::{quoterust-analyzer cargo quote 1.0.38 quote!, quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!, ToTokensrust-analyzer cargo quote 1.0.38 to_tokens/ToTokens#};
4 use synrust-analyzer cargo syn 2.0.96 crate/::{
5 parse_quoterust-analyzer cargo syn 2.0.96 parse_quote/, parse_quote_spannedrust-analyzer cargo syn 2.0.96 parse_quote/parse_quote_spanned!, parse_strrust-analyzer cargo syn 2.0.96 parse_str()., spannedrust-analyzer cargo syn 2.0.96 spanned/::Spannedrust-analyzer cargo syn 2.0.96 spanned/Spanned#,
6 visitrust-analyzer cargo syn 2.0.96 gen/visit/::Visitrust-analyzer cargo syn 2.0.96 gen/visit/Visit#, Attributerust-analyzer cargo syn 2.0.96 attr/Attribute#, Datarust-analyzer cargo syn 2.0.96 derive/Data#, DataStructrust-analyzer cargo syn 2.0.96 derive/DataStruct#, DeriveInputrust-analyzer cargo syn 2.0.96 derive/DeriveInput#, Exprrust-analyzer cargo syn 2.0.96 expr/Expr#, Fieldrust-analyzer cargo syn 2.0.96 data/Field#,
7 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#, GenericParamrust-analyzer cargo syn 2.0.96 generics/GenericParam#, Genericsrust-analyzer cargo syn 2.0.96 generics/Generics#, Indexrust-analyzer cargo syn 2.0.96 expr/Index#, Lifetimerust-analyzer cargo syn 2.0.96 lifetime/Lifetime#, LifetimeParamrust-analyzer cargo syn 2.0.96 generics/LifetimeParam#, Pathrust-analyzer cargo syn 2.0.96 path/Path#,
8 Tokenrust-analyzer cargo syn 2.0.96 token/Token!, WhereClauserust-analyzer cargo syn 2.0.96 generics/WhereClause#, WherePredicaterust-analyzer cargo syn 2.0.96 generics/WherePredicate#,
9 };
10
11 pub struct DeriveDiffableOutputrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput# {
12 pub outrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#out.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#>,
13 pub errorsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#errors.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
14 }
15
16 impl ToTokensrust-analyzer cargo quote 1.0.38 to_tokens/ToTokens# for DeriveDiffableOutputrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput# {
17 fn to_tokensrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DeriveDiffableOutput][ToTokens]to_tokens().(&self, tokens: &mut TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#) {
18 tokens.extendrust-analyzer cargo proc-macro2 1.0.93 impl#[TokenStream][`Extend<Self>`]extend().(self.outrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#out..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().());
19 tokens.extendrust-analyzer cargo proc-macro2 1.0.93 impl#[TokenStream][`Extend<Self>`]extend().(self.errorsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#errors..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|error| error.to_compile_errorrust-analyzer cargo syn 2.0.96 error/impl#[Error]to_compile_error().()));
20 }
21 }
22
23 pub fn derive_diffablerust-analyzer cargo daft-derive 0.1.5 internals/imp/derive_diffable().(input: synrust-analyzer cargo syn 2.0.96 crate/::DeriveInputrust-analyzer cargo syn 2.0.96 derive/DeriveInput#) -> DeriveDiffableOutputrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput# {
24 let mut error_store = ErrorStorerust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorStore#::newrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorStore<T>`]new().();
25
26 match &input.datarust-analyzer cargo syn 2.0.96 derive/DeriveInput#data. {
27 Datarust-analyzer cargo syn 2.0.96 derive/Data#::Enumrust-analyzer cargo syn 2.0.96 derive/Data#Enum#(_) => {
28 // Implement all Enums as `Leaf`s
29 let out = make_leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_leaf().(&input, AttrPositionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#::Enumrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Enum#, error_store.sinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorStore<T>`]sink().());
30 DeriveDiffableOutputrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput# {
31 outrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#out.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(out),
32 errorsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#errors.: error_store.into_innerrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorStore<T>`]into_inner().(),
33 }
34 }
35 Datarust-analyzer cargo syn 2.0.96 derive/Data#::Structrust-analyzer cargo syn 2.0.96 derive/Data#Struct#(s) => {
36 // This might be None if there are errors.
37 let out = make_struct_implrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_struct_impl().(&input, s, error_store.sinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorStore<T>`]sink().());
38 DeriveDiffableOutputrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput# { outrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#out., errorsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#errors.: error_store.into_innerrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorStore<T>`]into_inner().() }
39 }
40
41 Datarust-analyzer cargo syn 2.0.96 derive/Data#::Unionrust-analyzer cargo syn 2.0.96 derive/Data#Union#(_) => {
42 // Implement all unions as `Leaf`s
43 let out =
44 make_leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_leaf().(&input, AttrPositionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#::Unionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Union#, error_store.sinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorStore<T>`]sink().());
45 DeriveDiffableOutputrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput# {
46 outrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#out.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(out),
47 errorsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DeriveDiffableOutput#errors.: error_store.into_innerrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorStore<T>`]into_inner().(),
48 }
49 }
50 }
51 }
52
53 // TODO: allow the crate name to be passed in as a macro argument
54 fn daft_craterust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_crate().() -> Pathrust-analyzer cargo syn 2.0.96 path/Path# {
55 parse_quoterust-analyzer cargo syn 2.0.96 parse_quote/parse_quote!! { ::daft }
56 }
57
58 fn daft_lifetimerust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_lifetime().() -> LifetimeParamrust-analyzer cargo syn 2.0.96 generics/LifetimeParam# {
59 // Use an underscore to avoid clashing with a user-defined `'daft` lifetime.
60 LifetimeParamrust-analyzer cargo syn 2.0.96 generics/LifetimeParam#::newrust-analyzer cargo syn 2.0.96 generics/impl#[LifetimeParam]new().(Lifetimerust-analyzer cargo syn 2.0.96 lifetime/Lifetime#::newrust-analyzer cargo syn 2.0.96 lifetime/impl#[Lifetime]new().("'__daft", Spanrust-analyzer cargo proc-macro2 1.0.93 Span#::call_siterust-analyzer cargo proc-macro2 1.0.93 impl#[Span]call_site().()))
61 }
62
63 // We need to add our lifetime parameter 'daft and ensure any other parameters
64 // live as long as `daft`
65 fn add_lifetime_to_genericsrust-analyzer cargo daft-derive 0.1.5 internals/imp/add_lifetime_to_generics().(
66 input: &DeriveInputrust-analyzer cargo syn 2.0.96 derive/DeriveInput#,
67 daft_lt: &LifetimeParamrust-analyzer cargo syn 2.0.96 generics/LifetimeParam#,
68 ) -> Genericsrust-analyzer cargo syn 2.0.96 generics/Generics# {
69 let mut new_generics = input.genericsrust-analyzer cargo syn 2.0.96 derive/DeriveInput#generics..clonerust-analyzer cargo syn 2.0.96 gen/clone/impl#[`crate::Generics`][Clone]clone().();
70 new_generics
71 .lifetimes_mutrust-analyzer cargo syn 2.0.96 generics/impl#[Generics]lifetimes_mut().()
72 .for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|lt| lt.boundsrust-analyzer cargo syn 2.0.96 generics/LifetimeParam#bounds..pushrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`]push().(daft_lt.lifetimerust-analyzer cargo syn 2.0.96 generics/LifetimeParam#lifetime..clonerust-analyzer cargo syn 2.0.96 lifetime/impl#[Lifetime][Clone]clone().()));
73 new_generics.type_params_mutrust-analyzer cargo syn 2.0.96 generics/impl#[Generics]type_params_mut().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|lt| {
74 lt.boundsrust-analyzer cargo syn 2.0.96 generics/TypeParam#bounds..pushrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`]push().(synrust-analyzer cargo syn 2.0.96 crate/::TypeParamBoundrust-analyzer cargo syn 2.0.96 generics/TypeParamBound#::Lifetimerust-analyzer cargo syn 2.0.96 generics/TypeParamBound#Lifetime#(daft_lt.lifetimerust-analyzer cargo syn 2.0.96 generics/LifetimeParam#lifetime..clonerust-analyzer cargo syn 2.0.96 lifetime/impl#[Lifetime][Clone]clone().()))
75 });
76
77 // Add the 'daft lifetime to the beginning of the parameter list -- the
78 // exact order is not hugely important, but doing this makes tests simpler
79 // (they can just check the first element).
80 new_generics.paramsrust-analyzer cargo syn 2.0.96 generics/Generics#params..insertrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`]insert().(0, GenericParamrust-analyzer cargo syn 2.0.96 generics/GenericParam#::fromrust-analyzer cargo syn 2.0.96 generics/impl#[GenericParam][`From<LifetimeParam>`]from().(daft_lt.clonerust-analyzer cargo syn 2.0.96 gen/clone/impl#[`crate::LifetimeParam`][Clone]clone().()));
81 new_generics
82 }
83
84 // Implement `Diffable` as a `Leaf`.
85 fn make_leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_leaf().(
86 input: &DeriveInputrust-analyzer cargo syn 2.0.96 derive/DeriveInput#,
87 position: AttrPositionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#,
88 errors: ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#<'_, synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
89 ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream# {
90 // The input should not have any daft attributes.
91 for attr in &input.attrsrust-analyzer cargo syn 2.0.96 derive/DeriveInput#attrs. {
92 if attr.pathrust-analyzer cargo syn 2.0.96 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("daft") {
93 let res = attr.parse_nested_metarust-analyzer cargo syn 2.0.96 attr/impl#[Attribute]parse_nested_meta().(|meta| {
94 if meta.pathrust-analyzer cargo syn 2.0.96 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("leaf") {
95 // Accept this for leaf structs, but not for anything else.
96 if position rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition][`PartialEq<Self>`]eq().==rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition][`PartialEq<Self>`]eq(). rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition][`PartialEq<Self>`]eq().AttrPositionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#::LeafStructrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStruct# {
97 return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(());
98 }
99
100 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
101 "this is unnecessary: the Diffable \
102 implementation {} is always a leaf",
103 position.as_purpose_strrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]as_purpose_str().(),
104 )));
105 } else {
106 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
107 "daft attributes are not allowed {}",
108 position.as_locative_strrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]as_locative_str().(),
109 )));
110 }
111
112 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
113 });
114 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) = res {
115 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(err);
116 }
117 }
118 }
119
120 // Variants should not have any daft attributes.
121 let mut v = BanDaftAttrsVisitorrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor# { positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position., errorsrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#errors.: errors.new_childrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]new_child().() };
122 v.visit_datarust-analyzer cargo syn 2.0.96 gen/visit/Visit#visit_data().(&input.datarust-analyzer cargo syn 2.0.96 derive/DeriveInput#data.);
123
124 // Even though errors might have occurred above, we *do* generate the
125 // implementation. That allows rust-analyzer to still understand that the
126 // `Diffable` impl exists.
127
128 let ident = &input.identrust-analyzer cargo syn 2.0.96 derive/DeriveInput#ident.;
129 let daft_crate = daft_craterust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_crate().();
130 let daft_lt = daft_lifetimerust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_lifetime().();
131
132 // The "where Self: #daft_lt" condition appears to be enough to satisfy
133 // Rust's borrow checker, so we don't need to add further constraints via
134 // `add_lifetime_to_generics`.
135 let (impl_gen, ty_gen, where_clause) = &input.genericsrust-analyzer cargo syn 2.0.96 derive/DeriveInput#generics..split_for_implrust-analyzer cargo syn 2.0.96 generics/impl#[Generics]split_for_impl().();
136
137 quoterust-analyzer cargo quote 1.0.38 quote!! {
138 impl #impl_gen #daft_crate::Diffable for #ident #ty_gen #where_clause
139 {
140 type Diff<#daft_lt> = #daft_crate::Leaf<&#daft_lt Self> where Self: #daft_lt;
141
142 fn diff<#daft_lt>(&#daft_lt self, other: &#daft_lt Self) -> Self::Diff<#daft_lt> {
143 #daft_crate::Leaf {before: self, after: other}
144 }
145 }
146 }
147 }
148
149 struct BanDaftAttrsVisitorrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#<'a> {
150 positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position.: AttrPositionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#,
151 errorsrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#errors.: ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#<'a, synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
152 }
153
154 impl Visitrust-analyzer cargo syn 2.0.96 gen/visit/Visit#<'_> for BanDaftAttrsVisitorrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#<'_> {
155 fn visit_attributerust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[`BanDaftAttrsVisitor<'_>`][`Visit<'_>`]visit_attribute().(&mut self, attr: &Attributerust-analyzer cargo syn 2.0.96 attr/Attribute#) {
156 if attr.pathrust-analyzer cargo syn 2.0.96 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("daft") {
157 self.errorsrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#errors..push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#::new_spannedrust-analyzer cargo syn 2.0.96 error/impl#[Error]new_spanned().(
158 attr,
159 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!(
160 "daft attributes are not allowed {}",
161 self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position..as_locative_strrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]as_locative_str().(),
162 ),
163 ));
164 }
165 }
166
167 fn visit_variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[`BanDaftAttrsVisitor<'_>`][`Visit<'_>`]visit_variant().(&mut self, v: &synrust-analyzer cargo syn 2.0.96 crate/::Variantrust-analyzer cargo syn 2.0.96 data/Variant#) {
168 let old_position = self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position.;
169 self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position. = self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position..visit_variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]visit_variant().();
170 synrust-analyzer cargo syn 2.0.96 crate/::visitrust-analyzer cargo syn 2.0.96 gen/visit/::visit_variantrust-analyzer cargo syn 2.0.96 gen/visit/visit_variant().(self, v);
171 self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position. = old_position;
172 }
173
174 fn visit_fieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[`BanDaftAttrsVisitor<'_>`][`Visit<'_>`]visit_field().(&mut self, f: &synrust-analyzer cargo syn 2.0.96 crate/::Fieldrust-analyzer cargo syn 2.0.96 data/Field#) {
175 let old_position = self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position.;
176 self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position. = self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position..visit_fieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]visit_field().();
177 synrust-analyzer cargo syn 2.0.96 crate/::visitrust-analyzer cargo syn 2.0.96 gen/visit/::visit_fieldrust-analyzer cargo syn 2.0.96 gen/visit/visit_field().(self, f);
178 self.positionrust-analyzer cargo daft-derive 0.1.5 internals/imp/BanDaftAttrsVisitor#position. = old_position;
179 }
180 }
181
182 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
183 enum AttrPositionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition# {
184 // Catch-all in case something unexpected happens with the visitor.
185 Generalrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#General#,
186 LeafStructrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStruct#,
187 LeafStructFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStructField#,
188 Enumrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Enum#,
189 Variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Variant#,
190 VariantFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#VariantField#,
191 Unionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Union#,
192 UnionFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#UnionField#,
193 }
194
195 impl AttrPositionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition# {
196 fn visit_variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]visit_variant().(self) -> Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition] {
197 match self {
198 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Enumrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Enum# => Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Variant#,
199 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Generalrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#General#
200 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStruct#
201 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStructField#
202 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Variant#
203 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::VariantFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#VariantField#
204 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Unionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Union#
205 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::UnionFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#UnionField# => Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Generalrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#General#,
206 }
207 }
208
209 fn visit_fieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]visit_field().(self) -> Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition] {
210 match self {
211 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStruct# => Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStructField#,
212 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Variant# => Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::VariantFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#VariantField#,
213 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Unionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Union# => Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::UnionFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#UnionField#,
214 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Generalrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#General#
215 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStructField#
216 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Enumrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Enum#
217 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::VariantFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#VariantField#
218 | Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::UnionFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#UnionField# => Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Generalrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#General#,
219 }
220 }
221
222 // purpose = prepositional phrase to indicate what something applies to,
223 // e.g. "the implementation for enums is always"
224 fn as_purpose_strrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]as_purpose_str().(self) -> &'static str {
225 match self {
226 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Generalrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#General# => "for this type",
227 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStruct# => "for structs annotated with #[daft(leaf)]",
228 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStructField# => {
229 "for fields on structs annotated with #[daft(leaf)]"
230 }
231 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Enumrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Enum# => "for enums",
232 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Variant# => "for enum variants",
233 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::VariantFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#VariantField# => "for enum variant fields",
234 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Unionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Union# => "for unions",
235 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::UnionFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#UnionField# => "for union fields",
236 }
237 }
238
239 // "locative" = indicating location: "not allowed on enums", etc.
240 fn as_locative_strrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]as_locative_str().(self) -> &'static str {
241 match self {
242 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Generalrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#General# => "here",
243 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStruct# => "on structs annotated with #[daft(leaf)]",
244 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::LeafStructFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStructField# => {
245 "on fields of structs annotated with #[daft(leaf)]"
246 }
247 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Enumrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Enum# => "on enums",
248 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Variantrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Variant# => "on enum variants",
249 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::VariantFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#VariantField# => "on enum variant fields",
250 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::Unionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#Union# => "on unions",
251 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[AttrPosition]::UnionFieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#UnionField# => "on union fields",
252 }
253 }
254 }
255
256 fn make_struct_implrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_struct_impl().(
257 input: &DeriveInputrust-analyzer cargo syn 2.0.96 derive/DeriveInput#,
258 s: &DataStructrust-analyzer cargo syn 2.0.96 derive/DataStruct#,
259 errors: ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#<'_, synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
260 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#> {
261 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(struct_config) =
262 StructConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructConfig#::parse_fromrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[StructConfig]parse_from().(&input.attrsrust-analyzer cargo syn 2.0.96 derive/DeriveInput#attrs., errors.new_childrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]new_child().())
263 else {
264 // An error occurred parsing the struct configuration -- don't generate
265 // anything.
266 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
267 };
268
269 match struct_config.moderust-analyzer cargo daft-derive 0.1.5 internals/imp/StructConfig#mode. {
270 StructModerust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#::Defaultrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#Default# => make_diff_structrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_diff_struct().(input, s, errors.new_childrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]new_child().())
271 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|(generated_struct, diff_fields)| {
272 let diff_impl = make_diff_implrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_diff_impl().(input, &diff_fields);
273 // Uncomment for some debugging
274 // eprintln!("{generated_struct}");
275 // eprintln!("{diff_impl}");
276 quoterust-analyzer cargo quote 1.0.38 quote!! {
277 #generated_struct
278 #diff_impl
279 }
280 }),
281 StructModerust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#::Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#Leaf# => {
282 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(make_leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_leaf().(input, AttrPositionrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#::LeafStructrust-analyzer cargo daft-derive 0.1.5 internals/imp/AttrPosition#LeafStruct#, errors.new_childrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]new_child().()))
283 }
284 }
285 }
286
287 /// Create the `Diff` struct
288 fn make_diff_structrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_diff_struct().(
289 input: &DeriveInputrust-analyzer cargo syn 2.0.96 derive/DeriveInput#,
290 s: &DataStructrust-analyzer cargo syn 2.0.96 derive/DataStruct#,
291 errors: ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#<'_, synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
292 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#, DiffFieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#)> {
293 // The name of the original type
294 let vis = &input.visrust-analyzer cargo syn 2.0.96 derive/DeriveInput#vis.;
295
296 // The name of the generated type
297 let name = parse_strrust-analyzer cargo syn 2.0.96 parse_str().::<Pathrust-analyzer cargo syn 2.0.96 path/Path#>(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}Diff", input.identrust-analyzer cargo syn 2.0.96 derive/DeriveInput#ident.)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
298
299 // Copy over the non-exhaustive attribute from the original struct. (Do we
300 // need to copy over other attributes?)
301 let non_exhaustive =
302 input.attrsrust-analyzer cargo syn 2.0.96 derive/DeriveInput#attrs..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]find().(|attr| attr.pathrust-analyzer cargo syn 2.0.96 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("non_exhaustive"));
303
304 let daft_lt = daft_lifetimerust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_lifetime().();
305
306 // We are creating a new type, so use only generics with our new lifetime
307 // and bounds.
308 //
309 // Most of the other generics users use `split_for_impl`, but that is geared
310 // specifically for trait implementations, not type definitions. For type
311 // definitions, we use the original `Generics`.
312 //
313 // The `ToTokens` implementation for `Generics` does not print the `where`
314 // clause, so we also include that separately.
315 let new_generics = add_lifetime_to_genericsrust-analyzer cargo daft-derive 0.1.5 internals/imp/add_lifetime_to_generics().(input, &daft_lt);
316 let where_clause = &new_generics.where_clauserust-analyzer cargo syn 2.0.96 generics/Generics#where_clause.;
317
318 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(diff_fields) =
319 DiffFieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#::newrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]new().(&s.fieldsrust-analyzer cargo syn 2.0.96 derive/DataStruct#fields., where_clause.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().(), errors.new_childrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]new_child().())
320 else {
321 // An error occurred parsing fields -- don't generate the diff struct.
322 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
323 };
324
325 // --- No more errors past this point ---
326
327 let struct_def = match &s.fieldsrust-analyzer cargo syn 2.0.96 derive/DataStruct#fields. {
328 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Namedrust-analyzer cargo syn 2.0.96 data/Fields#Named#(_) => quoterust-analyzer cargo quote 1.0.38 quote!! {
329 #non_exhaustive
330 #vis struct #name #new_generics #where_clause #diff_fields
331
332 },
333 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.96 data/Fields#Unnamed#(_) => quoterust-analyzer cargo quote 1.0.38 quote!! {
334 #non_exhaustive
335 #vis struct #name #new_generics #diff_fields #where_clause;
336 },
337 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Unitrust-analyzer cargo syn 2.0.96 data/Fields#Unit# => quoterust-analyzer cargo quote 1.0.38 quote!! {
338 // This is kinda silly
339 #non_exhaustive
340 #vis struct #name #new_generics {} #where_clause
341 },
342 };
343
344 // Generate PartialEq, Eq, and Debug implementations for the diff struct. We
345 // can't rely on `#[derive] because we want to put bounds on the
346 // Diffable::Diff types, not on the original types.
347 let (impl_gen, ty_gen, _) = &new_generics.split_for_implrust-analyzer cargo syn 2.0.96 generics/impl#[Generics]split_for_impl().();
348
349 let debug_impl = {
350 let where_clause = diff_fields.where_clause_with_trait_boundrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]where_clause_with_trait_bound().(
351 &parse_quoterust-analyzer cargo syn 2.0.96 parse_quote/parse_quote!! { ::core::fmt::Debug },
352 );
353 let members = diff_fields.fieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#fields..membersrust-analyzer cargo syn 2.0.96 data/impl#[Fields]members().();
354
355 let finish = if non_exhaustive.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() {
356 quoterust-analyzer cargo quote 1.0.38 quote!! { .finish_non_exhaustive() }
357 } else {
358 quoterust-analyzer cargo quote 1.0.38 quote!! { .finish() }
359 };
360
361 let debug_body = match &s.fieldsrust-analyzer cargo syn 2.0.96 derive/DataStruct#fields. {
362 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Namedrust-analyzer cargo syn 2.0.96 data/Fields#Named#(_) => {
363 quoterust-analyzer cargo quote 1.0.38 quote!! {
364 f.debug_struct(stringify!(#name))
365 #(
366 .field(stringify!(#members), &self.#members)
367 )*
368 #finish
369 }
370 }
371 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.96 data/Fields#Unnamed#(_) => quoterust-analyzer cargo quote 1.0.38 quote!! {
372 f.debug_tuple(stringify!(#name))
373 #(
374 .field(&self.#members)
375 )*
376 #finish
377 },
378 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Unitrust-analyzer cargo syn 2.0.96 data/Fields#Unit# => quoterust-analyzer cargo quote 1.0.38 quote!! {
379 f.debug_struct(stringify!(#name))
380 #finish
381 },
382 };
383 quoterust-analyzer cargo quote 1.0.38 quote!! {
384 impl #impl_gen ::core::fmt::Debug for #name #ty_gen #where_clause {
385 fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
386 #debug_body
387 }
388 }
389 }
390 };
391
392 let partial_eq_impl = {
393 let where_clause = diff_fields.where_clause_with_trait_boundrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]where_clause_with_trait_bound().(
394 &parse_quoterust-analyzer cargo syn 2.0.96 parse_quote/parse_quote!! { ::core::cmp::PartialEq },
395 );
396 let members = diff_fields.fieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#fields..membersrust-analyzer cargo syn 2.0.96 data/impl#[Fields]members().();
397
398 let partial_eq_body: Exprrust-analyzer cargo syn 2.0.96 expr/Expr# = parse_quoterust-analyzer cargo syn 2.0.96 parse_quote/parse_quote!! {
399 #(self.#members == other.#members) && *
400 };
401
402 quoterust-analyzer cargo quote 1.0.38 quote!! {
403 impl #impl_gen ::core::cmp::PartialEq for #name #ty_gen #where_clause {
404 fn eq(&self, other: &Self) -> bool {
405 #partial_eq_body
406 }
407 }
408 }
409 };
410
411 let eq_impl = {
412 let where_clause = diff_fields
413 .where_clause_with_trait_boundrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]where_clause_with_trait_bound().(&parse_quoterust-analyzer cargo syn 2.0.96 parse_quote/parse_quote!! { ::core::cmp::Eq });
414
415 quoterust-analyzer cargo quote 1.0.38 quote!! {
416 impl #impl_gen ::core::cmp::Eq for #name #ty_gen #where_clause {}
417 }
418 };
419
420 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((
421 quoterust-analyzer cargo quote 1.0.38 quote!! {
422 #struct_def
423 #debug_impl
424 #partial_eq_impl
425 #eq_impl
426 },
427 diff_fields,
428 ))
429 }
430
431 /// Impl `Diffable` for the original struct
432 fn make_diff_implrust-analyzer cargo daft-derive 0.1.5 internals/imp/make_diff_impl().(
433 input: &DeriveInputrust-analyzer cargo syn 2.0.96 derive/DeriveInput#,
434 diff_fields: &DiffFieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#,
435 ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream# {
436 // The name of the original type
437 let ident = &input.identrust-analyzer cargo syn 2.0.96 derive/DeriveInput#ident.;
438
439 // The name of the generated type
440 let name = parse_strrust-analyzer cargo syn 2.0.96 parse_str().::<Pathrust-analyzer cargo syn 2.0.96 path/Path#>(&formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}Diff", input.identrust-analyzer cargo syn 2.0.96 derive/DeriveInput#ident.)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
441 let diffs =
442 generate_field_diffsrust-analyzer cargo daft-derive 0.1.5 internals/imp/generate_field_diffs().(&diff_fields.fieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#fields., &diff_fields.field_configsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#field_configs.);
443
444 let daft_crate = daft_craterust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_crate().();
445 let daft_lt = daft_lifetimerust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_lifetime().();
446 let new_generics = add_lifetime_to_genericsrust-analyzer cargo daft-derive 0.1.5 internals/imp/add_lifetime_to_generics().(input, &daft_lt);
447
448 let (impl_gen, ty_gen, _) = &input.genericsrust-analyzer cargo syn 2.0.96 derive/DeriveInput#generics..split_for_implrust-analyzer cargo syn 2.0.96 generics/impl#[Generics]split_for_impl().();
449 let (_, new_ty_gen, where_clause) = &new_generics.split_for_implrust-analyzer cargo syn 2.0.96 generics/impl#[Generics]split_for_impl().();
450
451 quoterust-analyzer cargo quote 1.0.38 quote!! {
452 impl #impl_gen #daft_crate::Diffable for #ident #ty_gen
453 #where_clause
454 {
455 type Diff<#daft_lt> = #name #new_ty_gen where Self: #daft_lt;
456
457 fn diff<#daft_lt>(&#daft_lt self, other: &#daft_lt Self) -> #name #new_ty_gen {
458 Self::Diff {
459 #diffs
460 }
461 }
462 }
463 }
464 }
465
466 /// For a `Diff` struct generated by this derive macro, tracks the fields that
467 /// will be put into that struct.
468 ///
469 /// This also tracks the `where` clause.
470 ///
471 /// The goal of this wrapper is to provide helpers to iterate over the fields
472 /// and members.
473 struct DiffFieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields# {
474 fieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#fields.: Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#,
475 // Configuration for each field -- a vector with the same length as `self.fields`.
476 field_configsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#field_configs.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<FieldConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#>,
477 // The base where clause for the diff struct.
478 where_clauserust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#where_clause.: WhereClauserust-analyzer cargo syn 2.0.96 generics/WhereClause#,
479 }
480
481 impl DiffFieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields# {
482 /// None means there was an error parsing a config.
483 fn newrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]new().(
484 fields: &Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#,
485 where_clause: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&WhereClauserust-analyzer cargo syn 2.0.96 generics/WhereClause#>,
486 errors: ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#<'_, synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
487 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]> {
488 let (fields, field_configs) = match fields {
489 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Namedrust-analyzer cargo syn 2.0.96 data/Fields#Named#(fields) => {
490 let (named, configs) = fields
491 .namedrust-analyzer cargo syn 2.0.96 data/FieldsNamed#named.
492 .iterrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`]iter().()
493 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|field| {
494 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]::diff_fieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]diff_field().(field, errors.new_childrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]new_child().())
495 })
496 .unziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#unzip().();
497 (
498 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Namedrust-analyzer cargo syn 2.0.96 data/Fields#Named#(synrust-analyzer cargo syn 2.0.96 crate/::FieldsNamedrust-analyzer cargo syn 2.0.96 data/FieldsNamed# {
499 brace_tokenrust-analyzer cargo syn 2.0.96 data/FieldsNamed#brace_token.: fields.brace_tokenrust-analyzer cargo syn 2.0.96 data/FieldsNamed#brace_token.,
500 namedrust-analyzer cargo syn 2.0.96 data/FieldsNamed#named.,
501 }),
502 configs,
503 )
504 }
505 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.96 data/Fields#Unnamed#(fields) => {
506 let (unnamed, configs) = fields
507 .unnamedrust-analyzer cargo syn 2.0.96 data/FieldsUnnamed#unnamed.
508 .iterrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`]iter().()
509 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|field| {
510 Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]::diff_fieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]diff_field().(field, errors.new_childrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]new_child().())
511 })
512 .unziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#unzip().();
513 (
514 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Unnamedrust-analyzer cargo syn 2.0.96 data/Fields#Unnamed#(synrust-analyzer cargo syn 2.0.96 crate/::FieldsUnnamedrust-analyzer cargo syn 2.0.96 data/FieldsUnnamed# {
515 paren_tokenrust-analyzer cargo syn 2.0.96 data/FieldsUnnamed#paren_token.: fields.paren_tokenrust-analyzer cargo syn 2.0.96 data/FieldsUnnamed#paren_token.,
516 unnamedrust-analyzer cargo syn 2.0.96 data/FieldsUnnamed#unnamed.,
517 }),
518 configs,
519 )
520 }
521 Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Unitrust-analyzer cargo syn 2.0.96 data/Fields#Unit# => (Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#::Unitrust-analyzer cargo syn 2.0.96 data/Fields#Unit#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().()),
522 };
523
524 // Initialize an empty where clause if none was provided.
525 let where_clause =
526 where_clause.clonedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]cloned().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| WhereClauserust-analyzer cargo syn 2.0.96 generics/WhereClause# {
527 where_tokenrust-analyzer cargo syn 2.0.96 generics/WhereClause#where_token.: <Tokenrust-analyzer cargo syn 2.0.96 token/Token!![where]>::defaultrust-analyzer cargo syn 2.0.96 token/impl#[Where][Default]default().(),
528 predicatesrust-analyzer cargo syn 2.0.96 generics/WhereClause#predicates.: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`][Default]default().(),
529 });
530
531 if errors.has_critical_errorsrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]has_critical_errors().() {
532 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
533 } else {
534 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields] { fieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#fields., field_configsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#field_configs., where_clauserust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#where_clause. })
535 }
536 }
537
538 /// Return a field for a diff with the appropriate type.
539 ///
540 /// If the type is ignored, or if there's an error parsing configuration,
541 /// return None.
542 fn diff_fieldrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]diff_field().(
543 f: &Fieldrust-analyzer cargo syn 2.0.96 data/Field#,
544 errors: ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#<'_, synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
545 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(Fieldrust-analyzer cargo syn 2.0.96 data/Field#, FieldConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#)> {
546 let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(config) =
547 FieldConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#::parse_fromrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldConfig]parse_from().(&f.attrsrust-analyzer cargo syn 2.0.96 data/Field#attrs., errors.new_childrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]new_child().())
548 else {
549 // None means there's an error parsing a config -- return None here,
550 // we'll emit errors at the top level.
551 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
552 };
553 if config.moderust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#mode. rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq().==rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq(). rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq().FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Ignorerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Ignore# {
554 // Skip over this field if there's an ignore.
555 return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#;
556 }
557
558 // Always use the daft lifetime for the diff -- associations between the
559 // daft lifetime and existing parameters (both lifetime and type
560 // parameters) are created in `add_lifetime_to_generics`, e.g. `'a:
561 // '__daft`, or `T: '__daft`.
562 let lt = daft_lifetimerust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_lifetime().();
563 let daft_crate = daft_craterust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_crate().();
564 let ty = &f.tyrust-analyzer cargo syn 2.0.96 data/Field#ty.;
565 let mut f = f.clonerust-analyzer cargo syn 2.0.96 gen/clone/impl#[`crate::Field`][Clone]clone().();
566
567 f.tyrust-analyzer cargo syn 2.0.96 data/Field#ty. = if config.moderust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#mode. rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq().==rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq(). rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq().FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Leaf# {
568 parse_quote_spannedrust-analyzer cargo syn 2.0.96 parse_quote/parse_quote_spanned!! {f.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=>
569 #daft_crate::Leaf<&#lt #ty>
570 }
571 } else {
572 parse_quote_spannedrust-analyzer cargo syn 2.0.96 parse_quote/parse_quote_spanned!! {f.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=>
573 <#ty as #daft_crate::Diffable>::Diff<#lt>
574 }
575 };
576
577 // Drop all attributes for now. We may want to carry some over in the
578 // future.
579 f.attrsrust-analyzer cargo syn 2.0.96 data/Field#attrs. = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
580
581 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((f, config))
582 }
583
584 /// Returns an iterator over field types.
585 fn typesrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]types().(&self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &synrust-analyzer cargo syn 2.0.96 crate/::Typerust-analyzer cargo syn 2.0.96 ty/Type#> {
586 self.fieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#fields..iterrust-analyzer cargo syn 2.0.96 data/impl#[Fields]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|f| &f.tyrust-analyzer cargo syn 2.0.96 data/Field#ty.)
587 }
588
589 /// Returns an expanded where clause where the fields have had a trait bound
590 /// applied to them.
591 fn where_clause_with_trait_boundrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]where_clause_with_trait_bound().(
592 &self,
593 trait_bound: &synrust-analyzer cargo syn 2.0.96 crate/::TraitBoundrust-analyzer cargo syn 2.0.96 generics/TraitBound#,
594 ) -> WhereClauserust-analyzer cargo syn 2.0.96 generics/WhereClause# {
595 let predicates = self.typesrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields]types().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|ty| -> WherePredicaterust-analyzer cargo syn 2.0.96 generics/WherePredicate# {
596 parse_quote_spannedrust-analyzer cargo syn 2.0.96 parse_quote/parse_quote_spanned!! {ty.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=>
597 #ty: #trait_bound
598 }
599 });
600
601 let mut where_clause = self.where_clauserust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#where_clause..clonerust-analyzer cargo syn 2.0.96 gen/clone/impl#[`crate::WhereClause`][Clone]clone().();
602 where_clause.predicatesrust-analyzer cargo syn 2.0.96 generics/WhereClause#predicates..extendrust-analyzer cargo syn 2.0.96 punctuated/impl#[`Punctuated<T, P>`][`Extend<T>`]extend().(predicates);
603
604 where_clause
605 }
606 }
607
608 impl ToTokensrust-analyzer cargo quote 1.0.38 to_tokens/ToTokens# for DiffFieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields# {
609 fn to_tokensrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[DiffFields][ToTokens]to_tokens().(&self, tokens: &mut TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream#) {
610 self.fieldsrust-analyzer cargo daft-derive 0.1.5 internals/imp/DiffFields#fields..to_tokensrust-analyzer cargo syn 2.0.96 data/impl#[Fields][ToTokens]to_tokens().(tokens);
611 }
612 }
613
614 /// Generate a call to `diff` for each field of the original struct that isn't
615 /// ignored.
616 fn generate_field_diffsrust-analyzer cargo daft-derive 0.1.5 internals/imp/generate_field_diffs().(
617 fields: &Fieldsrust-analyzer cargo syn 2.0.96 data/Fields#,
618 // Should be the same length as `fields`.
619 field_configs: &[FieldConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#],
620 ) -> TokenStreamrust-analyzer cargo proc-macro2 1.0.93 TokenStream# {
621 let daft_crate = daft_craterust-analyzer cargo daft-derive 0.1.5 internals/imp/daft_crate().();
622 let field_diffs =
623 fields.iterrust-analyzer cargo syn 2.0.96 data/impl#[Fields]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(field_configs).enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, (f, config))| {
624 let field_name = match &f.identrust-analyzer cargo syn 2.0.96 data/Field#ident. {
625 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ident) => quoterust-analyzer cargo quote 1.0.38 quote!! { #ident },
626 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => {
627 let ident: Indexrust-analyzer cargo syn 2.0.96 expr/Index# = i.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
628 quoterust-analyzer cargo quote 1.0.38 quote!! { #ident }
629 }
630 };
631 if config.moderust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#mode. rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq().==rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq(). rust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldMode][`PartialEq<Self>`]eq().FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Leaf# {
632 quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!! {f.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=>
633 #field_name: #daft_crate::Leaf {
634 before: &self.#field_name,
635 after: &other.#field_name
636 }
637 }
638 } else {
639 quote_spannedrust-analyzer cargo quote 1.0.38 quote_spanned!! {f.spanrust-analyzer cargo syn 2.0.96 spanned/impl#[T][Spanned]span().()=>
640 #field_name: #daft_crate::Diffable::diff(
641 &self.#field_name,
642 &other.#field_name
643 )
644 }
645 }
646 });
647 quoterust-analyzer cargo quote 1.0.38 quote!! { #(#field_diffs),* }
648 }
649
650 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
651 struct StructConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructConfig# {
652 moderust-analyzer cargo daft-derive 0.1.5 internals/imp/StructConfig#mode.: StructModerust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#,
653 }
654
655 impl StructConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructConfig# {
656 fn parse_fromrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[StructConfig]parse_from().(
657 attrs: &[Attributerust-analyzer cargo syn 2.0.96 attr/Attribute#],
658 errors: ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#<'_, synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
659 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[StructConfig]> {
660 let mut mode = StructModerust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#::Defaultrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#Default#;
661
662 for attr in attrs {
663 {
664 if attr.pathrust-analyzer cargo syn 2.0.96 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("daft") {
665 let res = attr.parse_nested_metarust-analyzer cargo syn 2.0.96 attr/impl#[Attribute]parse_nested_meta().(|meta| {
666 if meta.pathrust-analyzer cargo syn 2.0.96 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("leaf") {
667 match mode {
668 StructModerust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#::Defaultrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#Default# => {
669 mode = StructModerust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#::Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#Leaf#;
670 }
671 StructModerust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#::Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#Leaf# => {
672 errors.push_warningrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_warning().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(
673 "#[daft(leaf)] specified multiple times",
674 ));
675 }
676 }
677 } else {
678 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(
679 "unknown attribute \
680 (supported attributes: leaf)",
681 ));
682 }
683
684 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
685 });
686
687 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) = res {
688 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(err);
689 }
690 }
691 }
692 }
693
694 if errors.has_critical_errorsrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]has_critical_errors().() {
695 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
696 } else {
697 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[StructConfig] { moderust-analyzer cargo daft-derive 0.1.5 internals/imp/StructConfig#mode. })
698 }
699 }
700 }
701
702 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
703 enum StructModerust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode# {
704 // The default mode: do a recursive diff for this struct.
705 Defaultrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#Default#,
706 // Use a `Leaf` for this struct.
707 Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/StructMode#Leaf#,
708 }
709
710 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
711 struct FieldConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig# {
712 moderust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#mode.: FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#,
713 }
714
715 impl FieldConfigrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig# {
716 fn parse_fromrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldConfig]parse_from().(
717 attrs: &[Attributerust-analyzer cargo syn 2.0.96 attr/Attribute#],
718 errors: ErrorSinkrust-analyzer cargo daft-derive 0.1.5 internals/error_store/ErrorSink#<'_, synrust-analyzer cargo syn 2.0.96 crate/::Errorrust-analyzer cargo syn 2.0.96 error/Error#>,
719 ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldConfig]> {
720 let mut mode = FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Defaultrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Default#;
721
722 for attr in attrs {
723 if attr.pathrust-analyzer cargo syn 2.0.96 attr/impl#[Attribute]path().().is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("daft") {
724 let res = attr.parse_nested_metarust-analyzer cargo syn 2.0.96 attr/impl#[Attribute]parse_nested_meta().(|meta| {
725 if meta.pathrust-analyzer cargo syn 2.0.96 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("leaf") {
726 // #[daft(leaf)]
727 match mode {
728 FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Defaultrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Default# => {
729 mode = FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Leaf#;
730 }
731 FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Leaf# => {
732 errors.push_warningrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_warning().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(
733 "#[daft(leaf)] specified multiple times",
734 ));
735 }
736 _ => {
737 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(
738 "#[daft(leaf)] conflicts with \
739 other attributes",
740 ));
741 }
742 }
743 } else if meta.pathrust-analyzer cargo syn 2.0.96 meta/ParseNestedMeta#path..is_identrust-analyzer cargo syn 2.0.96 path/impl#[Path]is_ident().("ignore") {
744 // #[daft(ignore)]
745 match mode {
746 FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Defaultrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Default# => {
747 mode = FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Ignorerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Ignore#;
748 }
749 FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#::Ignorerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Ignore# => {
750 errors.push_warningrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_warning().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(
751 "#[daft(ignore)] specified multiple times",
752 ));
753 }
754 _ => {
755 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(
756 "#[daft(ignore)] conflicts with \
757 other attributes",
758 ));
759 }
760 }
761 } else {
762 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(meta.errorrust-analyzer cargo syn 2.0.96 meta/impl#[`ParseNestedMeta<'a>`]error().(
763 "unknown attribute \
764 (supported attributes: leaf, ignore)",
765 ));
766 }
767
768 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
769 });
770 // We don't return an error from our callback, but syn might.
771 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) = res {
772 errors.push_criticalrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]push_critical().(err);
773 }
774 }
775 }
776
777 if errors.has_critical_errorsrust-analyzer cargo daft-derive 0.1.5 internals/error_store/impl#[`ErrorSink<'a, T>`]has_critical_errors().() {
778 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
779 } else {
780 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Selfrust-analyzer cargo daft-derive 0.1.5 internals/imp/impl#[FieldConfig] { moderust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldConfig#mode. })
781 }
782 }
783 }
784
785 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
786 enum FieldModerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode# {
787 // The default mode: do a recursive diff for this field.
788 Defaultrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Default#,
789 // Use a `Leaf` for this field.
790 Leafrust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Leaf#,
791 // Ignore this field.
792 Ignorerust-analyzer cargo daft-derive 0.1.5 internals/imp/FieldMode#Ignore#,
793 }