Skip to content

Commit c702fbe

Browse files
committed
Fix bug where catch_all is not the last element
1 parent 4d6c725 commit c702fbe

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

crates/macros/src/newtype_oparg.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,22 @@ pub(super) fn handle_enum(item: ItemEnum) -> syn::Result<proc_macro2::TokenStrea
162162
variants,
163163
} = item.clone();
164164

165-
let mut variants_info = variants
165+
let (mut catch_all_variants, variants_info): (Vec<_>, Vec<_>) = variants
166166
.iter()
167167
.cloned()
168168
.map(VariantInfo::try_from)
169-
.collect::<syn::Result<Vec<_>>>()?;
170-
171-
let catch_all = variants_info.pop_if(|info| info.catch_all);
169+
.collect::<syn::Result<Vec<_>>>()?
170+
.into_iter()
171+
.partition(|vinfo| vinfo.catch_all);
172172

173173
// Ensure a no multiple `#[oparg(catch_all)]`
174-
if catch_all.is_some() && variants_info.iter().any(|vinfo| vinfo.catch_all) {
174+
let catch_all = catch_all_variants.pop();
175+
if !catch_all_variants.is_empty() {
175176
return Err(Error::new(
176177
item.span(),
177178
"Cannot define more than one `#[oparg(catch_all)]`",
178179
));
179-
};
180+
}
180181

181182
let variants_def = variants.iter().cloned().map(|mut variant| {
182183
// Don't assign value. Enables more optimizations by the compiler.

0 commit comments

Comments
 (0)