Skip to content

Commit

Permalink
silence non_upper_case_globals lint on __match_args__ (#4705)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt authored Nov 14, 2024
1 parent a42e53e commit f3eb624
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/4705.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `non_upper_case_globals` lint firing for generated `__match_args__` on complex enums.
6 changes: 4 additions & 2 deletions pyo3-macros-backend/src/pyclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,19 +1186,21 @@ fn impl_complex_enum_variant_match_args(
variant_cls_type: &syn::Type,
field_names: &mut Vec<Ident>,
) -> (MethodAndMethodDef, syn::ImplItemConst) {
let ident = format_ident!("__match_args__");
let match_args_const_impl: syn::ImplItemConst = {
let args_tp = field_names.iter().map(|_| {
quote! { &'static str }
});
parse_quote! {
const __match_args__: ( #(#args_tp,)* ) = (
#[allow(non_upper_case_globals)]
const #ident: ( #(#args_tp,)* ) = (
#(stringify!(#field_names),)*
);
}
};

let spec = ConstSpec {
rust_ident: format_ident!("__match_args__"),
rust_ident: ident,
attributes: ConstAttributes {
is_class_attr: true,
name: None,
Expand Down

0 comments on commit f3eb624

Please sign in to comment.