From 7b9b5cc15336b42bf3655934bc4197c710afef02 Mon Sep 17 00:00:00 2001 From: Mivort Date: Tue, 4 Nov 2025 10:45:22 +0000 Subject: [PATCH] Prevent procedural macro hygiene issue with eager macros This PR adds a change which links together identifiers in `quote!` expansion. While in normal context, there's no issues with expansion of procedural macro `#[func]` attribute, Rust macro hygiene rules start to apply within the context of `eager2` crate. --- godot-macros/src/class/data_models/func.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/godot-macros/src/class/data_models/func.rs b/godot-macros/src/class/data_models/func.rs index e51cf545b..60e0d38ff 100644 --- a/godot-macros/src/class/data_models/func.rs +++ b/godot-macros/src/class/data_models/func.rs @@ -386,7 +386,9 @@ fn make_forwarding_closure( }; quote! { - |instance_ptr, params| { + // Identifiers need to share the span to avoid proc macro hygiene issues + // similar to https://github.com/godot-rust/gdext/pull/1397. + |instance_ptr, #param_ident| { let #params_tuple #sig_tuple_annotation = #param_ident; let storage = @@ -409,7 +411,9 @@ fn make_forwarding_closure( }; quote! { - |instance_ptr, params| { + // Identifiers need to share the span to avoid proc macro hygiene issues + // similar to https://github.com/godot-rust/gdext/pull/1397. + |instance_ptr, #param_ident| { // Not using `virtual_sig`, since virtual methods with `#[func(gd_self)]` are being moved out of the trait to inherent impl. let #params_tuple #sig_tuple_annotation = #param_ident; @@ -423,8 +427,11 @@ fn make_forwarding_closure( } ReceiverType::Static => { // No before-call needed, since static methods are not virtual. + // + // Identifiers need to share the span to avoid proc macro hygiene issues + // similar to https://github.com/godot-rust/gdext/pull/1397. quote! { - |_, params| { + |_, #param_ident| { let #params_tuple = #param_ident; #class_name::#method_name(#(#params),*) }