From e843405ecfee06ea158fb0070d4c70c2f228c82c Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Fri, 22 May 2026 09:56:04 +0800 Subject: Refactor renderer to use injected resources directly --- mingling_macros/src/renderer.rs | 8 +++----- mingling_macros/src/res_injection.rs | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'mingling_macros') diff --git a/mingling_macros/src/renderer.rs b/mingling_macros/src/renderer.rs index db04c19..7f85a60 100644 --- a/mingling_macros/src/renderer.rs +++ b/mingling_macros/src/renderer.rs @@ -115,16 +115,14 @@ pub fn renderer_attr(attr: TokenStream, item: TokenStream) -> TokenStream { quote! { #(#fn_body_stmts)* } }; - // Build the original function with resource injection (no `.into()` — signature is exactly as user wrote) + // Build the original function with resource injection - use the resource bindings directly + // from the function parameters rather than re-fetching from context. let original_fn_body = if has_resources { - let wrapped_body = - wrap_body_with_mut_resources(&fn_body_stmts, &mut_resources, program_type); quote! { let mut dummy_r = ::mingling::RenderResult::default(); { let __renderer_inner_result = &mut dummy_r; - #(#immut_resource_stmts)* - #wrapped_body + #(#fn_body_stmts)* } #result_return } diff --git a/mingling_macros/src/res_injection.rs b/mingling_macros/src/res_injection.rs index 0f180db..bdb3b73 100644 --- a/mingling_macros/src/res_injection.rs +++ b/mingling_macros/src/res_injection.rs @@ -149,7 +149,7 @@ pub(crate) fn generate_immut_resource_bindings<'a>( .filter(|r| !r.is_mut) .map(|res| { let var_binding_name = syn::Ident::new( - &format!("{}_binding", &res.var_name.to_string()), + &format!("__{}_binding", &res.var_name.to_string()), res.var_name.span(), ); let var_name = &res.var_name; -- cgit