Skip to content

Commit d4466a1

Browse files
committed
Set span for empty type data parameters in macro
1 parent c8ef9b3 commit d4466a1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

crates/bevy_reflect/compile_fail/tests/reflect_derive/type_data_fail.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ impl<T> CreateTypeData<T, f32> for ReflectMyTrait {
1111
}
1212

1313
#[derive(Reflect)]
14-
//~^ ERROR: mismatched types
1514
#[reflect(MyTrait)]
15+
//~^ ERROR: mismatched types
1616
struct RequiredArgs;
1717

1818
#[derive(Reflect)]

crates/bevy_reflect/derive/src/registration.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
derive_data::ReflectMeta, serialization::SerializationDataDef,
55
where_clause_options::WhereClauseOptions,
66
};
7-
use quote::quote;
7+
use quote::{quote, quote_spanned};
88
use syn::Type;
99

1010
/// Creates the `GetTypeRegistration` impl for the given type data.
@@ -50,8 +50,16 @@ pub(crate) fn impl_get_type_registration<'a>(
5050
let reflect_ident = data.reflect_ident();
5151
let args = data.args();
5252

53+
let args = if args.is_empty() {
54+
// Set the span so that we get pointed to the correct identifier
55+
let span = reflect_ident.span();
56+
quote_spanned!(span => ())
57+
} else {
58+
quote!((#args))
59+
};
60+
5361
quote! {
54-
<#reflect_ident as #bevy_reflect_path::CreateTypeData<Self, _>>::create_type_data((#args))
62+
<#reflect_ident as #bevy_reflect_path::CreateTypeData<Self, _>>::create_type_data(#args)
5563
}
5664
});
5765

0 commit comments

Comments
 (0)