Skip to content

Commit

Permalink
Fix panic from code path not checking cx
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Sep 5, 2024
1 parent f05bbd8 commit 12925b4
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,25 @@ use serde_derive_internals::{
};
use syn::{parse_macro_input, Data, DataStruct, DeriveInput, Fields};

fn column_names(data: &DataStruct, cx: Ctxt, container: &Container) -> TokenStream {
fn column_names(data: &DataStruct, cx: &Ctxt, container: &Container) -> TokenStream {
match &data.fields {
Fields::Named(fields) => {
let rename_rule = container.rename_all_rules().deserialize;
let column_names_iter = fields
.named
.iter()
.enumerate()
.map(|(index, field)| Field::from_ast(&cx, index, field, None, &SerdeDefault::None))
.map(|(index, field)| Field::from_ast(cx, index, field, None, &SerdeDefault::None))
.filter(|field| !field.skip_serializing() && !field.skip_deserializing())
.map(|field| {
rename_rule
.apply_to_field(field.name().serialize_name())
.to_string()
});

let tokens = quote! {
quote! {
&[#( #column_names_iter,)*]
};

// TODO: do something more clever?
let _ = cx.check();
tokens
}
}
Fields::Unnamed(_) => {
quote! { &[] }
Expand All @@ -49,10 +45,13 @@ pub fn row(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
let name = input.ident;

let column_names = match &input.data {
Data::Struct(data) => column_names(data, cx, &container),
Data::Struct(data) => column_names(data, &cx, &container),
Data::Enum(_) | Data::Union(_) => panic!("`Row` can be derived only for structs"),
};

// TODO: do something more clever?
let _ = cx.check().expect("derive context error");

let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();

// TODO: replace `clickhouse` with `::clickhouse` here.
Expand Down

0 comments on commit 12925b4

Please sign in to comment.