Skip to content

Commit ae6885b

Browse files
committed
Remove old attribute keys, but keep error message for now
Concerns: - #[class(editor_plugin)] - #[class(hidden)] - #[init(default = ...)] Those already caused compile errors, since the deprecation functions no longer existed, so this is not a breaking change. However, the new approach produces more readable errors.
1 parent 40b57bd commit ae6885b

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

godot-macros/src/class/derive_godot_class.rs

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -531,11 +531,12 @@ fn parse_struct_attributes(class: &venial::Struct) -> ParseResult<ClassAttribute
531531
is_tool = true;
532532
}
533533

534-
// Deprecated #[class(editor_plugin)]
535-
if let Some(_attr_key) = parser.handle_alone_with_span("editor_plugin")? {
536-
deprecations.push(quote_spanned! { _attr_key.span()=>
537-
::godot::__deprecated::emit_deprecated_warning!(class_editor_plugin);
538-
});
534+
// Removed #[class(editor_plugin)]
535+
if let Some(key) = parser.handle_alone_with_span("editor_plugin")? {
536+
return bail!(
537+
key,
538+
"#[class(editor_plugin)] has been removed in favor of #[class(tool, base=EditorPlugin)]",
539+
);
539540
}
540541

541542
// #[class(rename = NewName)]
@@ -556,20 +557,19 @@ fn parse_struct_attributes(class: &venial::Struct) -> ParseResult<ClassAttribute
556557
}
557558
}
558559

559-
// Deprecated #[class(hidden)]
560-
if let Some(ident) = parser.handle_alone_with_span("hidden")? {
561-
is_internal = true;
562-
563-
deprecations.push(quote_spanned! { ident.span()=>
564-
::godot::__deprecated::emit_deprecated_warning!(class_hidden);
565-
});
560+
// Removed #[class(hidden)]
561+
if let Some(key) = parser.handle_alone_with_span("hidden")? {
562+
return bail!(
563+
key,
564+
"#[class(hidden)] has been renamed to #[class(internal)]",
565+
);
566566
}
567567

568568
parser.finish()?;
569569
}
570570

571571
// Deprecated: #[class(no_init)] with base=EditorPlugin
572-
if init_strategy == InitStrategy::Absent && base_ty == "EditorPlugin" {
572+
if matches!(init_strategy, InitStrategy::Absent) && base_ty == ident("EditorPlugin") {
573573
deprecations.push(quote! {
574574
::godot::__deprecated::emit_deprecated_warning!(class_no_init_editor_plugin);
575575
});
@@ -594,6 +594,7 @@ fn parse_fields(
594594
) -> ParseResult<Fields> {
595595
let mut all_fields = vec![];
596596
let mut base_field = Option::<Field>::None;
597+
#[allow(unused_mut)] // Less chore when adding/removing deprecations.
597598
let mut deprecations = vec![];
598599
let mut errors = vec![];
599600

@@ -640,21 +641,12 @@ fn parse_fields(
640641
});
641642
}
642643

643-
// Deprecated #[init(default = expr)]
644-
if let Some((key, default)) = parser.handle_expr_with_key("default")? {
645-
if field.default_val.is_some() {
646-
return bail!(
647-
key,
648-
"Cannot use both `val` and `default` keys in #[init]; prefer using `val`"
649-
);
650-
}
651-
field.default_val = Some(FieldDefault {
652-
default_val: default,
653-
span: parser.span(),
654-
});
655-
deprecations.push(quote_spanned! { parser.span()=>
656-
::godot::__deprecated::emit_deprecated_warning!(init_default);
657-
})
644+
// Removed #[init(default = ...)]
645+
if let Some((key, _default)) = parser.handle_expr_with_key("default")? {
646+
return bail!(
647+
key,
648+
"#[init(default = ...)] has been renamed to #[init(val = ...)]",
649+
);
658650
}
659651

660652
// #[init(node = "PATH")]

0 commit comments

Comments
 (0)