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

Attempt to handle references from macro_rules #30

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 12 additions & 2 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,18 @@ fn transform_sig(sig: &mut Signature, args: &RecursionArgs) {

for arg in &mut sig.inputs {
if let FnArg::Typed(pt) = arg {
if let Type::Reference(tr) = pt.ty.as_mut() {
ref_arguments.push(tr);
match pt.ty.as_mut() {
// rustc can give us a None-delimited group if this type comes from
// a macro_rules macro. I don't this can happen for code the user has written.
Type::Group(tg) => {
if let Type::Reference(tr) = &mut *tg.elem {
ref_arguments.push(tr);
}
}
Type::Reference(tr) => {
ref_arguments.push(tr);
}
_ => {}
}
} else if let FnArg::Receiver(recv) = arg {
if let Some((_, slt)) = &mut recv.reference {
Expand Down
26 changes: 26 additions & 0 deletions tests/macros_all_the_way_down.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use futures_executor::block_on;

macro_rules! recurse {
($name:ident, $param:ty) => {
#[::async_recursion::async_recursion]
async fn $name<F>(param: $param, f: &F)
where
F: Fn($param) + Sync + Send,
{
f(param);
}
};
}

recurse!(owned, usize);
recurse!(by_ref, &usize);
recurse!(by_ref_mut, &mut usize);

#[test]
fn async_in_macro() {
block_on(async move {
owned(5, &|_| ()).await;
by_ref(&5, &|_| ()).await;
by_ref_mut(&mut 5, &|_| ()).await;
});
}