@@ -227,6 +227,12 @@ fn fill_class_info(component: PluginComponent, c: &mut ClassRegistrationInfo) {
227
227
fill_into (
228
228
& mut c. godot_params . create_instance_func ,
229
229
generated_create_fn,
230
+ )
231
+ . unwrap_or_else ( |_|
232
+ panic ! (
233
+ "Godot class `{}` is defined multiple times in Rust; you can rename them with #[class(rename=NewName)]" ,
234
+ c. class_name,
235
+ )
230
236
) ;
231
237
c. godot_params . free_instance_func = Some ( free_fn) ;
232
238
}
@@ -245,7 +251,9 @@ fn fill_class_info(component: PluginComponent, c: &mut ClassRegistrationInfo) {
245
251
get_virtual_fn,
246
252
} => {
247
253
c. user_register_fn = user_register_fn;
248
- fill_into ( & mut c. godot_params . create_instance_func , user_create_fn) ;
254
+ // this shouldn't panic since rustc will error if there's
255
+ // multiple `impl {Class}Virtual for Thing` definitions
256
+ fill_into ( & mut c. godot_params . create_instance_func , user_create_fn) . unwrap ( ) ;
249
257
c. godot_params . to_string_func = user_to_string_fn;
250
258
c. godot_params . notification_func = user_on_notification_fn;
251
259
c. godot_params . get_virtual_func = Some ( get_virtual_fn) ;
@@ -260,12 +268,13 @@ fn fill_class_info(component: PluginComponent, c: &mut ClassRegistrationInfo) {
260
268
}
261
269
262
270
/// If `src` is occupied, it moves the value into `dst`, while ensuring that no previous value is present in `dst`.
263
- fn fill_into < T > ( dst : & mut Option < T > , src : Option < T > ) {
271
+ fn fill_into < T > ( dst : & mut Option < T > , src : Option < T > ) -> Result < ( ) , ( ) > {
264
272
match ( dst, src) {
265
273
( dst @ None , src) => * dst = src,
266
- ( Some ( _) , Some ( _) ) => panic ! ( "option already filled" ) ,
274
+ ( Some ( _) , Some ( _) ) => return Err ( ( ) ) ,
267
275
( Some ( _) , None ) => { /* do nothing */ }
268
276
}
277
+ Ok ( ( ) )
269
278
}
270
279
271
280
/// Registers a class with given the dynamic type information `info`.
0 commit comments