Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: impl block expansion for check_rep #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions rep_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub fn derive_check_rep(input: proc_macro::TokenStream) -> proc_macro::TokenStre
/// A macro that auto-inserts calls to `check_rep`
///
/// This macro can be applied to an `impl` block to inserts calls to `check_rep` only in methods that satisfy the following.
/// - Visiblity is `pub`
/// - Visibility is `pub`
/// - Parameters include `&mut self`
///
/// You may also apply it to a method in an `impl` block regardless of the method's signature.
Expand All @@ -317,10 +317,12 @@ pub fn check_rep(_attr: proc_macro::TokenStream, item: proc_macro::TokenStream)
let mut new_impl_item_method = impl_item_method.clone();

if let Visibility::Public(_) = new_impl_item_method.vis {
if new_impl_item_method.sig.inputs.iter().fold(false, |_, input| if let FnArg::Receiver(receiver) = input {
receiver.mutability.is_some()
} else {
false
if new_impl_item_method.sig.inputs.iter().any(|input| {
if let FnArg::Receiver(receiver) = input {
receiver.mutability.is_some()
} else {
false
}
}) {
// insert calls to check rep at start and end of method
impl_item_method.block.stmts.insert(0, syn::parse::<Stmt>(quote! {
Expand Down