@@ -13,7 +13,7 @@ use proc_macro2::{Ident, TokenStream};
13
13
use quote:: { quote, ToTokens } ;
14
14
15
15
/// Codegen for `#[godot_api] impl ISomething for MyType`.
16
- pub fn transform_trait_impl ( original_impl : venial:: Impl ) -> ParseResult < TokenStream > {
16
+ pub fn transform_trait_impl ( mut original_impl : venial:: Impl ) -> ParseResult < TokenStream > {
17
17
let ( class_name, trait_path, trait_base_class) =
18
18
util:: validate_trait_impl_virtual ( & original_impl, "godot_api" ) ?;
19
19
@@ -26,7 +26,7 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
26
26
27
27
let mut decls = IDecls :: default ( ) ;
28
28
29
- for item in original_impl. body_items . iter ( ) {
29
+ for item in original_impl. body_items . iter_mut ( ) {
30
30
let method = if let venial:: ImplMember :: AssocFunction ( f) = item {
31
31
f
32
32
} else {
@@ -70,6 +70,9 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
70
70
handle_property_get_revert ( & class_name, & trait_path, cfg_attrs, & mut decls) ;
71
71
}
72
72
regular_virtual_fn => {
73
+ // Break borrow chain to allow handle_regular_virtual_fn() to mutably borrow `method` and modify `original_impl` through it.
74
+ let cfg_attrs = cfg_attrs. iter ( ) . cloned ( ) . collect ( ) ;
75
+
73
76
// All the non-special engine ones: ready(), process(), etc.
74
77
// Can modify original_impl, concretely the fn body for f64->f32 conversions.
75
78
handle_regular_virtual_fn (
@@ -142,8 +145,8 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
142
145
. iter ( )
143
146
. map ( |v| v. make_match_arm ( & class_name) ) ;
144
147
145
- let result = quote ! {
146
- #original_impl
148
+ let mut result = quote ! {
149
+ // #original_impl inserted below.
147
150
#decls
148
151
149
152
impl :: godot:: private:: You_forgot_the_attribute__godot_api for #class_name { }
@@ -167,6 +170,10 @@ pub fn transform_trait_impl(original_impl: venial::Impl) -> ParseResult<TokenStr
167
170
) ) ;
168
171
} ;
169
172
173
+ // Not in upper quote!, because #decls still holds holds a mutable borrow to `original_impl`, so we can't also borrow `original_impl`
174
+ // as immutable.
175
+ original_impl. to_tokens ( & mut result) ;
176
+
170
177
Ok ( result)
171
178
}
172
179
0 commit comments