@@ -47,15 +47,10 @@ impl MacroSelectionConfig {
47
47
pub fn extend_idents ( & mut self , iter : impl IntoIterator < Item = syn:: Ident > ) {
48
48
self . idents . extend ( iter) ;
49
49
}
50
-
51
- pub ( crate ) fn idents ( & self ) -> & [ syn:: Ident ] {
52
- & self . idents
53
- }
54
50
}
55
51
56
52
pub ( crate ) type EnumExcludeConfig = MacroSelectionConfig ;
57
53
pub ( crate ) type VariantExcludeConfig = MacroSelectionConfig ;
58
- pub ( crate ) type VariantIncludeConfig = MacroSelectionConfig ;
59
54
60
55
#[ derive( Clone , Default ) ]
61
56
pub ( crate ) struct EncapsulateEnumConfig {
@@ -84,56 +79,26 @@ pub(crate) struct VariantConfig {
84
79
// #[enumcapsulate(exclude(…))]
85
80
pub exclude : Option < VariantExcludeConfig > ,
86
81
87
- // #[enumcapsulate(include(…))]
88
- pub include : Option < VariantIncludeConfig > ,
89
-
90
82
// #[enumcapsulate(field(…))]
91
83
pub field : Option < VariantFieldConfig > ,
92
84
}
93
85
94
86
impl VariantConfig {
95
- pub fn is_excluded ( & self , name : & str ) -> bool {
96
- if self . is_included_explicitly ( name) {
97
- return false ;
98
- }
99
-
100
- if self . is_excluded_explicitly ( name) {
101
- return true ;
102
- }
103
-
104
- false
87
+ #[ allow( dead_code) ]
88
+ pub fn is_included ( & self , name : & str ) -> bool {
89
+ !self . is_excluded ( name)
105
90
}
106
91
107
- pub fn is_excluded_explicitly ( & self , name : & str ) -> bool {
92
+ pub fn is_excluded ( & self , name : & str ) -> bool {
108
93
let Some ( excluded) = & self . exclude else {
109
94
return false ;
110
95
} ;
111
96
112
97
if excluded. is_empty ( ) {
113
- if let Some ( included) = & self . include {
114
- return !included. contains ( name) ;
115
- } else {
116
- return true ;
117
- }
118
- }
119
-
120
- excluded. contains ( name)
121
- }
122
-
123
- pub fn is_included_explicitly ( & self , name : & str ) -> bool {
124
- let Some ( included) = & self . include else {
125
- return false ;
126
- } ;
127
-
128
- if included. is_empty ( ) {
129
- if let Some ( excluded) = & self . exclude {
130
- return !excluded. contains ( name) ;
131
- } else {
132
- return true ;
133
- }
98
+ true
99
+ } else {
100
+ excluded. contains ( name)
134
101
}
135
-
136
- included. contains ( name)
137
102
}
138
103
}
139
104
@@ -205,19 +170,9 @@ pub(crate) fn config_for_variant(variant: &syn::Variant) -> Result<VariantConfig
205
170
206
171
let mut exclude = config. exclude . take ( ) . unwrap_or_default ( ) ;
207
172
208
- let opposite = config. include . as_ref ( ) ;
209
- exclude. extend_idents ( macro_selection_config_for_variant ( & meta, opposite) ?. idents ) ;
173
+ exclude. extend_idents ( macro_selection_config_for_variant ( & meta) ?. idents ) ;
210
174
211
175
config. exclude = Some ( exclude) ;
212
- } else if meta. path . is_ident ( attr:: INCLUDE ) {
213
- // #[enumcapsulate(include(…))]
214
-
215
- let mut include = config. include . take ( ) . unwrap_or_default ( ) ;
216
-
217
- let opposite: Option < & MacroSelectionConfig > = config. exclude . as_ref ( ) ;
218
- include. extend_idents ( macro_selection_config_for_variant ( & meta, opposite) ?. idents ) ;
219
-
220
- config. include = Some ( include) ;
221
176
} else if meta. path . is_ident ( attr:: FIELD ) {
222
177
// #[enumcapsulate(field(…))]
223
178
meta. parse_nested_meta ( |meta| {
@@ -311,16 +266,12 @@ pub(crate) fn macro_selection_config_for_enum(
311
266
312
267
pub ( crate ) fn macro_selection_config_for_variant (
313
268
meta : & syn:: meta:: ParseNestedMeta < ' _ > ,
314
- opposite : Option < & MacroSelectionConfig > ,
315
269
) -> Result < MacroSelectionConfig , syn:: Error > {
316
270
let idents = parse_idents_from_meta_list ( meta) ?;
317
271
318
272
let recognized = RECOGNIZED_VARIANT_LEVEL_MACROS ;
319
273
ensure_only_recognized_ident_names ( & idents, recognized) ?;
320
274
321
- let conflict_list = opposite. map ( |config| config. idents ( ) ) . unwrap_or ( & [ ] ) ;
322
- ensure_no_conflicting_idents ( & idents, conflict_list) ?;
323
-
324
275
Ok ( MacroSelectionConfig { idents } )
325
276
}
326
277
@@ -350,32 +301,6 @@ pub(crate) fn ensure_only_recognized_ident_names(
350
301
Ok ( ( ) )
351
302
}
352
303
353
- pub ( crate ) fn ensure_no_conflicting_idents (
354
- idents : & [ syn:: Ident ] ,
355
- conflicting : & [ syn:: Ident ] ,
356
- ) -> Result < ( ) , syn:: Error > {
357
- let mut error: Option < syn:: Error > = None ;
358
-
359
- let conflicting = idents
360
- . iter ( )
361
- . filter ( |& ident| conflicting. iter ( ) . any ( |conflicting| ident == conflicting) ) ;
362
-
363
- for ident in conflicting {
364
- let ident_err = syn:: Error :: new_spanned ( ident, "conflicting macro derive" ) ;
365
- if let Some ( error) = error. as_mut ( ) {
366
- error. combine ( ident_err) ;
367
- } else {
368
- error = Some ( ident_err)
369
- }
370
- }
371
-
372
- if let Some ( err) = error {
373
- return Err ( err) ;
374
- }
375
-
376
- Ok ( ( ) )
377
- }
378
-
379
304
pub ( crate ) fn parse_idents_from_meta_list (
380
305
meta : & syn:: meta:: ParseNestedMeta < ' _ > ,
381
306
) -> Result < Vec < syn:: Ident > , syn:: Error > {
0 commit comments