Skip to content

Commit 1c8dd0c

Browse files
committed
Fix #[godot_api] impl godot::engine::ITrait not working with full path
1 parent 23043fc commit 1c8dd0c

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

godot-macros/src/class/godot_api.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ fn convert_to_match_expression_or_none(tokens: Option<TokenStream>) -> TokenStre
452452

453453
/// Codegen for `#[godot_api] impl GodotExt for MyType`
454454
fn transform_trait_impl(original_impl: Impl) -> Result<TokenStream, Error> {
455-
let (class_name, trait_name) = util::validate_trait_impl_virtual(&original_impl, "godot_api")?;
455+
let (class_name, trait_path) = util::validate_trait_impl_virtual(&original_impl, "godot_api")?;
456456
let class_name_obj = util::class_name_obj(&class_name);
457457

458458
let mut godot_init_impl = TokenStream::new();
@@ -505,7 +505,7 @@ fn transform_trait_impl(original_impl: Impl) -> Result<TokenStream, Error> {
505505
#(#cfg_attrs)*
506506
impl ::godot::obj::cap::GodotRegisterClass for #class_name {
507507
fn __godot_register_class(builder: &mut ::godot::builder::GodotBuilder<Self>) {
508-
<Self as #trait_name>::register_class(builder)
508+
<Self as #trait_path>::register_class(builder)
509509
}
510510
}
511511
};
@@ -534,7 +534,7 @@ fn transform_trait_impl(original_impl: Impl) -> Result<TokenStream, Error> {
534534
#(#cfg_attrs)*
535535
impl ::godot::obj::cap::GodotDefault for #class_name {
536536
fn __godot_user_init(base: ::godot::obj::Base<Self::Base>) -> Self {
537-
<Self as #trait_name>::init(base)
537+
<Self as #trait_path>::init(base)
538538
}
539539
}
540540
};
@@ -559,7 +559,7 @@ fn transform_trait_impl(original_impl: Impl) -> Result<TokenStream, Error> {
559559
#(#cfg_attrs)*
560560
impl ::godot::obj::cap::GodotToString for #class_name {
561561
fn __godot_to_string(&self) -> ::godot::builtin::GString {
562-
<Self as #trait_name>::to_string(self)
562+
<Self as #trait_path>::to_string(self)
563563
}
564564
}
565565
};
@@ -583,7 +583,7 @@ fn transform_trait_impl(original_impl: Impl) -> Result<TokenStream, Error> {
583583
return;
584584
}
585585

586-
<Self as #trait_name>::on_notification(self, what.into())
586+
<Self as #trait_path>::on_notification(self, what.into())
587587
}
588588
}
589589
};
@@ -605,7 +605,7 @@ fn transform_trait_impl(original_impl: Impl) -> Result<TokenStream, Error> {
605605
return None;
606606
}
607607

608-
<Self as #trait_name>::get_property(self, property)
608+
<Self as #trait_path>::get_property(self, property)
609609
}
610610
}
611611
};
@@ -626,7 +626,7 @@ fn transform_trait_impl(original_impl: Impl) -> Result<TokenStream, Error> {
626626
return false;
627627
}
628628

629-
<Self as #trait_name>::set_property(self, property, value)
629+
<Self as #trait_path>::set_property(self, property, value)
630630
}
631631
}
632632
};

godot-macros/src/util/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ParseResult;
1111
use proc_macro2::{Delimiter, Group, Ident, Literal, TokenStream, TokenTree};
1212
use quote::spanned::Spanned;
1313
use quote::{format_ident, quote, ToTokens, TokenStreamExt};
14-
use venial::{Error, Function, GenericParamList, Impl, WhereClause};
14+
use venial::{Error, Function, GenericParamList, Impl, TyExpr, WhereClause};
1515

1616
mod kv_parser;
1717
mod list_parser;
@@ -162,12 +162,12 @@ pub(crate) fn validate_impl(
162162
validate_self(original_impl, attr)
163163
}
164164

165-
/// Validates that the declaration is the of the form `impl Trait for
166-
/// SomeType`, where the name of `Trait` ends in `Virtual`.
167-
pub(crate) fn validate_trait_impl_virtual(
168-
original_impl: &Impl,
165+
/// Validates that the declaration is the of the form `impl Trait for SomeType`, where the name
166+
/// of `Trait` begins with `I`.
167+
pub(crate) fn validate_trait_impl_virtual<'a>(
168+
original_impl: &'a Impl,
169169
attr: &str,
170-
) -> ParseResult<(Ident, Ident)> {
170+
) -> ParseResult<(Ident, &'a TyExpr)> {
171171
let trait_name = original_impl.trait_ty.as_ref().unwrap(); // unwrap: already checked outside
172172
let typename = extract_typename(trait_name);
173173

@@ -184,8 +184,8 @@ pub(crate) fn validate_trait_impl_virtual(
184184

185185
// Validate self
186186
validate_self(original_impl, attr).map(|class_name| {
187-
let trait_name = typename.unwrap(); // unwrap: already checked in 'Validate trait'
188-
(class_name, trait_name.ident)
187+
// let trait_name = typename.unwrap(); // unwrap: already checked in 'Validate trait'
188+
(class_name, trait_name)
189189
})
190190
}
191191

@@ -207,7 +207,7 @@ fn validate_self(original_impl: &Impl, attr: &str) -> ParseResult<Ident> {
207207
}
208208
}
209209

210-
/// Gets the right-most type name in the path
210+
/// Gets the right-most type name in the path.
211211
fn extract_typename(ty: &venial::TyExpr) -> Option<venial::PathSegment> {
212212
match ty.as_path() {
213213
Some(mut path) => path.segments.pop(),

0 commit comments

Comments
 (0)