Skip to content

Commit

Permalink
Fix default safe body for unnamed fields
Browse files Browse the repository at this point in the history
  • Loading branch information
adpaco-aws committed Jul 26, 2024
1 parent b05de12 commit 7cc466f
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions library/kani_macros/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,25 @@ fn safe_body_default_inner(_ident: &Ident, fields: &Fields) -> TokenStream {
quote! { true }
}
}
Fields::Unnamed(_) => quote! {},
Fields::Unit => quote! {},
Fields::Unnamed(ref fields) => {
let field_safe_calls: Vec<TokenStream> = fields
.unnamed
.iter()
.enumerate()
.map(|(idx, field)| {
let field_idx = Index::from(idx);
quote_spanned! {field.span()=>
#field_idx.is_safe()
}
})
.collect();
if !field_safe_calls.is_empty() {
quote! { #( #field_safe_calls )&&* }
} else {
quote! { true }
}
}
Fields::Unit => quote! { true },
}
}

Expand Down

0 comments on commit 7cc466f

Please sign in to comment.