Skip to content

Commit

Permalink
Remove most #[deprecated] symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Feb 19, 2024
1 parent c2be677 commit c5fbb66
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 131 deletions.
15 changes: 3 additions & 12 deletions godot-codegen/src/generator/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,10 @@ fn make_constructor_and_default(class: &Class, ctx: &Context) -> (TokenStream, T
// Abstract base classes or non-singleton classes without constructor
constructor = TokenStream::new();
has_godot_default_impl = false;
} else if class.is_refcounted {
// RefCounted, Resource, etc
constructor = quote! {
#[deprecated = "Replaced with `new_gd` in extension trait `NewGd`."]
pub fn new() -> Gd<Self> {
// <Self as crate::obj::NewGd>::new_gd()
crate::obj::Gd::default()
}
};
has_godot_default_impl = true;
} else {
// Manually managed classes: Object, Node etc
constructor = quote! {};
// Manually managed classes (Object, Node, ...) as well as ref-counted ones (RefCounted, Resource, ...).
// The constructors are provided as associated methods in NewGd::new_gd() and NewAlloc::new_alloc().
constructor = TokenStream::new();
has_godot_default_impl = true;
}

Expand Down
57 changes: 15 additions & 42 deletions godot-codegen/src/generator/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,29 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
// this might be a forward compatibility hazard, if Godot deprecates enumerators and adds new ones with existing ords.

let rust_enum_name = &enum_.name;

// TODO remove once deprecated is removed.
let deprecated_enum_decl = if rust_enum_name != enum_.godot_name.as_str() {
let deprecated_enum_name = util::ident(&enum_.godot_name);
let msg = format!("Renamed to `{rust_enum_name}`.");
quote! {
#[deprecated = #msg]
pub type #deprecated_enum_name = #rust_enum_name;
}
let godot_name_doc = if rust_enum_name != enum_.godot_name.as_str() {
let doc = format!("Godot enum name: `{}`.", enum_.godot_name);
quote! { #[doc = #doc] }
} else {
TokenStream::new()
};

let rust_enumerators = &enum_.enumerators;

let mut enumerators = Vec::with_capacity(rust_enumerators.len());
let mut deprecated_enumerators = Vec::new();

// This is only used for enum ords (i32), not bitfield flags (u64).
let mut unique_ords = Vec::with_capacity(rust_enumerators.len());

for enumerator in rust_enumerators.iter() {
let (def, deprecated_def) = make_enumerator_definition(enumerator);
let def = make_enumerator_definition(enumerator);
enumerators.push(def);

if let Some(def) = deprecated_def {
deprecated_enumerators.push(def);
}

if let EnumeratorValue::Enum(ord) = enumerator.value {
unique_ords.push(ord);
}
}

enumerators.extend(deprecated_enumerators);

let mut derives = vec!["Copy", "Clone", "Eq", "PartialEq", "Hash", "Debug"];

if enum_.is_bitfield {
Expand Down Expand Up @@ -143,10 +130,9 @@ pub fn make_enum_definition(enum_: &Enum) -> TokenStream {
// Public interface is i64 though, for consistency (and possibly forward compatibility?).
// Bitfield ordinals are stored as u64. See also: https://github.com/godotengine/godot-cpp/pull/1320
quote! {
#deprecated_enum_decl

#[repr(transparent)]
#[derive(#( #derives ),*)]
#godot_name_doc
pub struct #rust_enum_name {
ord: #enum_ord_type
}
Expand Down Expand Up @@ -190,7 +176,7 @@ fn make_bitfield_flag_ord(ord: u64) -> Literal {
Literal::u64_suffixed(ord)
}

fn make_enumerator_definition(enumerator: &Enumerator) -> (TokenStream, Option<TokenStream>) {
fn make_enumerator_definition(enumerator: &Enumerator) -> TokenStream {
let ordinal_lit = match enumerator.value {
EnumeratorValue::Enum(ord) => make_enumerator_ord(ord),
EnumeratorValue::Bitfield(ord) => make_bitfield_flag_ord(ord),
Expand All @@ -199,33 +185,20 @@ fn make_enumerator_definition(enumerator: &Enumerator) -> (TokenStream, Option<T
let rust_ident = &enumerator.name;
let godot_name_str = &enumerator.godot_name;

let (doc_alias, deprecated_def);

if rust_ident == godot_name_str {
deprecated_def = None;
doc_alias = TokenStream::new();
let doc = if rust_ident == godot_name_str {
TokenStream::new()
} else {
// Godot and Rust names differ -> add doc alias for searchability.
let msg = format!("Renamed to `{rust_ident}`.");
let deprecated_ident = util::ident(godot_name_str);

// For now, list previous identifier at the end.
deprecated_def = Some(quote! {
#[deprecated = #msg]
pub const #deprecated_ident: Self = Self { ord: #ordinal_lit };
});

doc_alias = quote! {
let doc_string = format!("Godot enumerator name: `{}`.", godot_name_str);
quote! {
#[doc(alias = #godot_name_str)]
};
#[doc = #doc_string]
}
};

let def = quote! {
#doc_alias
quote! {
#doc
pub const #rust_ident: Self = Self { ord: #ordinal_lit };
};

(def, deprecated_def)
}
}

/// If an enum qualifies as "indexable" (can be used as array index), returns the number of possible values.
Expand Down
27 changes: 3 additions & 24 deletions godot-core/src/obj/gd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,6 @@ where
Self::from_init_fn(move |_base| user_object)
}

#[deprecated = "Use `Gd::from_object()` instead."]
pub fn new(user_object: T) -> Self {
Self::from_object(user_object)
}

#[deprecated = "Use `Gd::default()` or the short-hands `T::new_gd()` and `T::new_alloc()` instead."]
pub fn new_default() -> Self
where
T: cap::GodotDefault,
{
Self::default_instance()
}

#[deprecated = "Use `Gd::from_init_fn()` instead."]
pub fn with_base<F>(init: F) -> Self
where
F: FnOnce(crate::obj::Base<T::Base>) -> T,
{
Self::from_init_fn(init)
}

/// Hands out a guard for a shared borrow, through which the user instance can be read.
///
/// The pattern is very similar to interior mutability with standard [`RefCell`][std::cell::RefCell].
Expand Down Expand Up @@ -782,13 +761,13 @@ impl NotUniqueError {
/// ## Example
///
/// ```no_run
/// use godot::engine::RefCounted;
/// use godot::prelude::*;
/// use godot::obj::NotUniqueError;
///
/// let unique = RefCounted::new();
/// let unique = RefCounted::new_gd();
/// assert!(NotUniqueError::check(unique).is_ok());
///
/// let shared = RefCounted::new();
/// let shared = RefCounted::new_gd();
/// let cloned = shared.clone();
/// assert!(NotUniqueError::check(shared).is_err());
/// assert!(NotUniqueError::check(cloned).is_err());
Expand Down
13 changes: 0 additions & 13 deletions godot-core/src/obj/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,7 @@ impl<T: GodotClass> Inherits<T> for T {}
pub trait ExportableObject: GodotClass {}

/// Implemented for all user-defined classes, providing extensions on the raw object to interact with `Gd`.
// #[deprecated = "Use `NewGd` and `NewAlloc` traits instead."]
pub trait UserClass: Bounds<Declarer = bounds::DeclUser> {
/// Return a new Gd which contains a default-constructed instance.
///
/// `MyClass::new_gd()` is equivalent to `Gd::<MyClass>::default()`.
#[deprecated = "Use `NewAlloc::new_alloc()` instead."]
#[must_use]
fn alloc_gd() -> Gd<Self>
where
Self: cap::GodotDefault + Bounds<Memory = bounds::MemManual>,
{
Gd::default_instance()
}

#[doc(hidden)]
fn __config() -> crate::private::ClassConfig;

Expand Down
76 changes: 38 additions & 38 deletions godot-macros/src/class/data_models/field_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ use crate::ParseResult;

/// Store info from `#[export]` attribute.
pub enum FieldExport {
/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export`
///
/// ### Property Hints
/// - `PROPERTY_HINT_NONE` (usually)
/// ### Property hints
/// - `NONE` (usually)
///
/// Can become other property hints, depends on context.
Default,

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_range`
///
/// ### Property Hints
/// - `PROPERTY_HINT_RANGE`
/// ### Property hints
/// - `RANGE`
Range {
min: TokenStream,
max: TokenStream,
Expand All @@ -41,82 +41,82 @@ pub enum FieldExport {
hide_slider: bool,
},

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_enum`
///
/// ### Property Hints
/// - `PROPERTY_HINT_ENUM`
/// ### Property hints
/// - `ENUM`
Enum { variants: Vec<ValueWithKey> },

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_exp_easing`
///
/// ### Property Hints
/// - `PROPERTY_HINT_EXP_EASING`
/// ### Property hints
/// - `EXP_EASING`
ExpEasing {
attenuation: bool,
positive_only: bool,
},

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_flags`
///
/// ### Property Hints
/// - `PROPERTY_HINT_FLAGS`
/// ### Property hints
/// - `FLAGS`
Flags { bits: Vec<ValueWithKey> },

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_flags_2d_physics`
/// - `@export_flags_2d_render`
/// - `@export_flags_2d_navigation`
/// - `@export_flags_3d_physics`
/// - `@export_flags_3d_render`
/// - `@export_flags_3d_navigation`
///
/// ### Property Hints
/// - `PROPERTY_HINT_LAYERS_2D_PHYSICS`
/// - `PROPERTY_HINT_LAYERS_2D_RENDER`
/// - `PROPERTY_HINT_LAYERS_2D_NAVIGATION`
/// - `PROPERTY_HINT_LAYERS_3D_PHYSICS`
/// - `PROPERTY_HINT_LAYERS_3D_RENDER`
/// - `PROPERTY_HINT_LAYERS_3D_NAVIGATION`
/// ### Property hints
/// - `LAYERS_2D_PHYSICS`
/// - `LAYERS_2D_RENDER`
/// - `LAYERS_2D_NAVIGATION`
/// - `LAYERS_3D_PHYSICS`
/// - `LAYERS_3D_RENDER`
/// - `LAYERS_3D_NAVIGATION`
Layers {
dimension: LayerDimension,
kind: LayerKind,
},

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_file`
/// - `@export_global_file`
/// - `@export_dir`
/// - `@export_global_dir`
///
/// ### Property Hints
/// - `PROPERTY_HINT_FILE`
/// - `PROPERTY_HINT_GLOBAL_FILE`
/// - `PROPERTY_HINT_DIR`
/// - `PROPERTY_HINT_GLOBAL_DIR`
/// ### Property hints
/// - `FILE`
/// - `GLOBAL_FILE`
/// - `DIR`
/// - `GLOBAL_DIR`
File { global: bool, kind: FileKind },

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_multiline`
///
/// ### Property Hints
/// - `PROPERTY_HINT_MULTILINE_TEXT`
/// ### Property hints
/// - `MULTILINE_TEXT`
Multiline,

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_placeholder`
///
/// ### Property Hints
/// - `PROPERTY_HINT_PLACEHOLDER_TEXT`
/// ### Property hints
/// - `PLACEHOLDER_TEXT`
PlaceholderText { placeholder: TokenStream },

/// ### GDScript Annotations
/// ### GDScript annotations
/// - `@export_color_no_alpha`
///
/// ### Property Hints
/// - `PROPERTY_HINT_COLOR_NO_ALPHA`
/// ### Property hints
/// - `COLOR_NO_ALPHA`
ColorNoAlpha,
}

Expand Down
1 change: 0 additions & 1 deletion godot/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ pub use super::obj::EngineBitfield as _;
pub use super::obj::EngineEnum as _;
pub use super::obj::NewAlloc as _;
pub use super::obj::NewGd as _;
pub use super::obj::UserClass as _; // TODO: remove (exposed functions are deprecated)
pub use super::obj::WithBaseField as _; // base(), base_mut(), to_gd()
2 changes: 1 addition & 1 deletion itest/rust/src/object_tests/property_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct HasProperty {
#[var]
texture_val: Gd<Texture>,

#[var(get = get_texture_val, set = set_texture_val, hint = PROPERTY_HINT_RESOURCE_TYPE, hint_string = "Texture")]
#[var(get = get_texture_val, set = set_texture_val, hint = RESOURCE_TYPE, hint_string = "Texture")]
texture_val_rw: Option<Gd<Texture>>,
}

Expand Down

0 comments on commit c5fbb66

Please sign in to comment.