From 37a8d4a26713a694421048b51eb4226eba44dfd5 Mon Sep 17 00:00:00 2001 From: PgBiel <9021226+PgBiel@users.noreply.github.com> Date: Mon, 2 Oct 2023 20:48:27 -0300 Subject: [PATCH] Fix usage of segmented path attribute with #[func] --- godot-macros/src/class/godot_api.rs | 7 ++++--- itest/rust/src/register_tests/constant_test.rs | 4 ++++ itest/rust/src/register_tests/func_test.rs | 10 ++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/godot-macros/src/class/godot_api.rs b/godot-macros/src/class/godot_api.rs index 0eaa2f21c..7833ae6db 100644 --- a/godot-macros/src/class/godot_api.rs +++ b/godot-macros/src/class/godot_api.rs @@ -322,9 +322,10 @@ where { let mut found = None; for (index, attr) in attributes.iter().enumerate() { - let attr_name = attr - .get_single_path_segment() - .expect("get_single_path_segment"); + let Some(attr_name) = attr.get_single_path_segment() else { + // Attribute of the form #[segmented::path] can't be what we are looking for + continue; + }; let new_found = match attr_name { name if name == "func" => { diff --git a/itest/rust/src/register_tests/constant_test.rs b/itest/rust/src/register_tests/constant_test.rs index 5a01e3a79..e2c047f89 100644 --- a/itest/rust/src/register_tests/constant_test.rs +++ b/itest/rust/src/register_tests/constant_test.rs @@ -24,6 +24,10 @@ impl HasConstants { #[constant] const D: usize = 20 + 33 * 45; + + #[constant] + #[rustfmt::skip] + const DONT_PANIC_WITH_SEGMENTED_PATH_ATTRIBUTE: bool = true; } #[itest] diff --git a/itest/rust/src/register_tests/func_test.rs b/itest/rust/src/register_tests/func_test.rs index 0a60b6657..9637f769b 100644 --- a/itest/rust/src/register_tests/func_test.rs +++ b/itest/rust/src/register_tests/func_test.rs @@ -60,6 +60,16 @@ impl GdSelfReference { self.internal_value = new_value; } + #[func] + #[rustfmt::skip] + fn func_shouldnt_panic_with_segmented_path_attribute() -> bool { + true + } + + #[signal] + #[rustfmt::skip] + fn signal_shouldnt_panic_with_segmented_path_attribute(); + #[func] fn fail_to_update_internal_value_due_to_conflicting_borrow( &mut self,