Skip to content

Commit ce3a2e1

Browse files
authored
Merge pull request #439 from PgBiel/fix-segmented-attr
Fix usage of segmented path attribute with #[func]
2 parents 386d57a + 37a8d4a commit ce3a2e1

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

godot-macros/src/class/godot_api.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,10 @@ where
322322
{
323323
let mut found = None;
324324
for (index, attr) in attributes.iter().enumerate() {
325-
let attr_name = attr
326-
.get_single_path_segment()
327-
.expect("get_single_path_segment");
325+
let Some(attr_name) = attr.get_single_path_segment() else {
326+
// Attribute of the form #[segmented::path] can't be what we are looking for
327+
continue;
328+
};
328329

329330
let new_found = match attr_name {
330331
name if name == "func" => {

itest/rust/src/register_tests/constant_test.rs

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl HasConstants {
2424

2525
#[constant]
2626
const D: usize = 20 + 33 * 45;
27+
28+
#[constant]
29+
#[rustfmt::skip]
30+
const DONT_PANIC_WITH_SEGMENTED_PATH_ATTRIBUTE: bool = true;
2731
}
2832

2933
#[itest]

itest/rust/src/register_tests/func_test.rs

+10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ impl GdSelfReference {
6060
self.internal_value = new_value;
6161
}
6262

63+
#[func]
64+
#[rustfmt::skip]
65+
fn func_shouldnt_panic_with_segmented_path_attribute() -> bool {
66+
true
67+
}
68+
69+
#[signal]
70+
#[rustfmt::skip]
71+
fn signal_shouldnt_panic_with_segmented_path_attribute();
72+
6373
#[func]
6474
fn fail_to_update_internal_value_due_to_conflicting_borrow(
6575
&mut self,

0 commit comments

Comments
 (0)