From c076f816097e5a770b28c4adaeb116240c071818 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Mon, 22 Jul 2024 22:16:54 +0200 Subject: [PATCH 1/3] Remove most deprecated symbols --- godot-codegen/src/generator/central_files.rs | 15 +-- godot-codegen/src/generator/enums.rs | 31 ------- godot-codegen/src/util.rs | 13 +-- godot-core/src/builtin/collections/array.rs | 18 ---- .../src/builtin/collections/packed_array.rs | 22 ----- godot-core/src/builtin/color.rs | 13 --- godot-core/src/builtin/mod.rs | 50 ---------- godot-core/src/builtin/projection.rs | 31 ------- godot-core/src/builtin/string/string_name.rs | 35 ++----- godot-core/src/deprecated.rs | 91 ++++--------------- godot-core/src/engine.rs | 57 ------------ godot-core/src/lib.rs | 21 ----- godot-core/src/obj/gd.rs | 4 - godot-core/src/obj/script.rs | 2 +- godot-core/src/tools/gfile.rs | 2 +- godot-core/src/tools/save_load.rs | 2 +- godot-macros/src/class/data_models/field.rs | 3 - .../src/class/data_models/field_export.rs | 2 +- godot-macros/src/class/derive_godot_class.rs | 15 --- godot/src/lib.rs | 7 +- itest/rust/build.rs | 3 +- .../src/builtin_tests/string/gstring_test.rs | 2 +- itest/rust/src/framework/runner.rs | 2 +- 23 files changed, 45 insertions(+), 396 deletions(-) delete mode 100644 godot-core/src/engine.rs diff --git a/godot-codegen/src/generator/central_files.rs b/godot-codegen/src/generator/central_files.rs index 65165e379..c724eb334 100644 --- a/godot-codegen/src/generator/central_files.rs +++ b/godot-codegen/src/generator/central_files.rs @@ -15,8 +15,7 @@ use quote::{format_ident, quote, ToTokens}; pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream { let build_config_struct = gdext_build_struct::make_gdext_build_struct(&api.godot_version); - let (variant_type_enum, variant_type_deprecated_enumerators) = - make_variant_type_enum(api, true); + let variant_type_enum = make_variant_type_enum(api, true); let [opaque_32bit, opaque_64bit] = make_opaque_types(api); quote! { @@ -45,8 +44,6 @@ pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream { pub fn sys(self) -> crate::GDExtensionVariantType { self.ord as _ } - - #variant_type_deprecated_enumerators } } } @@ -60,7 +57,7 @@ pub fn make_core_central_code(api: &ExtensionApi, ctx: &mut Context) -> TokenStr } = make_variant_enums(api, ctx); let (global_enum_defs, global_reexported_enum_defs) = make_global_enums(api); - let variant_type_traits = make_variant_type_enum(api, false).0; + let variant_type_traits = make_variant_type_enum(api, false); // TODO impl Clone, Debug, PartialEq, PartialOrd, Hash for VariantDispatch // TODO could use try_to().unwrap_unchecked(), since type is already verified. Also directly overload from_variant(). @@ -205,7 +202,7 @@ fn make_global_enums(api: &ExtensionApi) -> (Vec, Vec) (global_enum_defs, global_reexported_enum_defs) } -fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> (TokenStream, TokenStream) { +fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> TokenStream { let variant_type_enum = api .global_enums .iter() @@ -215,9 +212,5 @@ fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> (TokenStre let define_enum = is_definition; let define_traits = !is_definition; - let enum_definition = - enums::make_enum_definition_with(variant_type_enum, define_enum, define_traits); - let deprecated_enumerators = enums::make_deprecated_enumerators(variant_type_enum); - - (enum_definition, deprecated_enumerators) + enums::make_enum_definition_with(variant_type_enum, define_enum, define_traits) } diff --git a/godot-codegen/src/generator/enums.rs b/godot-codegen/src/generator/enums.rs index c63193160..a764265fa 100644 --- a/godot-codegen/src/generator/enums.rs +++ b/godot-codegen/src/generator/enums.rs @@ -10,7 +10,6 @@ //! See also models/domain/enums.rs for other enum-related methods. use crate::models::domain::{Enum, Enumerator, EnumeratorValue}; -use crate::{conv, util}; use proc_macro2::TokenStream; use quote::{quote, ToTokens}; @@ -335,33 +334,3 @@ fn make_enumerator_definition( } } } - -pub(crate) fn make_deprecated_enumerators(enum_: &Enum) -> TokenStream { - let enum_name = &enum_.name; - let deprecated_enumerators = enum_.enumerators.iter().filter_map(|enumerator| { - let Enumerator { name, .. } = enumerator; - - if name == "MAX" { - return None; - } - - let converted = conv::to_pascal_case(&name.to_string()) - .replace("2d", "2D") - .replace("3d", "3D"); - - let pascal_name = util::ident(&converted); - let msg = format!("Use `{enum_name}::{name}` instead."); - - let decl = quote! { - #[deprecated = #msg] - #[doc(hidden)] // No longer advertise in API docs. - pub const #pascal_name: #enum_name = Self::#name; - }; - - Some(decl) - }); - - quote! { - #( #deprecated_enumerators )* - } -} diff --git a/godot-codegen/src/util.rs b/godot-codegen/src/util.rs index b4e5d3492..63ec0d391 100644 --- a/godot-codegen/src/util.rs +++ b/godot-codegen/src/util.rs @@ -33,15 +33,10 @@ pub fn make_imports() -> TokenStream { #[cfg(since_api = "4.2")] pub fn make_string_name(identifier: &str) -> TokenStream { - let lit = Literal::byte_string(format!("{identifier}\0").as_bytes()); - quote! { - // TODO: C-string literals cannot currently be constructed in proc-macros, see the tracking issue: - // https://github.com/rust-lang/rust/issues/119750 - { - #[allow(deprecated)] - StringName::from_latin1_with_nul(#lit) - } - } + let c_string = std::ffi::CString::new(identifier).expect("CString::new() failed"); + let lit = Literal::c_string(&c_string); + + quote! { StringName::from(#lit) } } #[cfg(before_api = "4.2")] diff --git a/godot-core/src/builtin/collections/array.rs b/godot-core/src/builtin/collections/array.rs index 4c60603b1..08673474f 100644 --- a/godot-core/src/builtin/collections/array.rs +++ b/godot-core/src/builtin/collections/array.rs @@ -189,12 +189,6 @@ impl Array { } } - #[deprecated = "Renamed to `get`."] - #[doc(hidden)] // No longer advertise in API docs. - pub fn try_get(&self, index: usize) -> Option { - self.get(index) - } - /// Returns `true` if the array contains the given value. Equivalent of `has` in GDScript. pub fn contains(&self, value: &T) -> bool { self.as_inner().has(value.to_variant()) @@ -251,18 +245,6 @@ impl Array { }) } - #[deprecated = "Renamed to `front`, in line with GDScript method and consistent with `push_front` and `pop_front`."] - #[doc(hidden)] // No longer advertise in API docs. - pub fn first(&self) -> Option { - self.front() - } - - #[deprecated = "Renamed to `back`, in line with GDScript method."] - #[doc(hidden)] // No longer advertise in API docs. - pub fn last(&self) -> Option { - self.back() - } - /// Clears the array, removing all elements. pub fn clear(&mut self) { // SAFETY: No new values are written to the array, we only remove values from the array. diff --git a/godot-core/src/builtin/collections/packed_array.rs b/godot-core/src/builtin/collections/packed_array.rs index 17550815e..7f30a0829 100644 --- a/godot-core/src/builtin/collections/packed_array.rs +++ b/godot-core/src/builtin/collections/packed_array.rs @@ -127,22 +127,6 @@ macro_rules! impl_packed_array { self.as_inner().clear(); } - /// Sets the value at the specified index. - /// - /// # Panics - /// - /// If `index` is out of bounds. - #[deprecated = "Use [] operator (IndexMut) instead."] - #[doc(hidden)] // No longer advertise in API docs. - pub fn set(&mut self, index: usize, value: $Element) { - let ptr_mut = self.ptr_mut(index); - - // SAFETY: `ptr_mut` just checked that the index is not out of bounds. - unsafe { - *ptr_mut = value; - } - } - /// Appends an element to the end of the array. Equivalent of `append` and `push_back` /// in GDScript. #[doc(alias = "append")] @@ -312,12 +296,6 @@ macro_rules! impl_packed_array { to_usize(self.as_inner().bsearch(Self::to_arg(value), true)) } - #[deprecated = "Renamed to bsearch like in Godot, to avoid confusion with Rust's slice::binary_search."] - #[doc(hidden)] // No longer advertise in API docs. - pub fn binary_search(&self, value: $Element) -> usize { - self.bsearch(&value) - } - /// Reverses the order of the elements in the array. pub fn reverse(&mut self) { self.as_inner().reverse(); diff --git a/godot-core/src/builtin/color.rs b/godot-core/src/builtin/color.rs index 8a7c3d6ea..f5b96f6e2 100644 --- a/godot-core/src/builtin/color.rs +++ b/godot-core/src/builtin/color.rs @@ -377,19 +377,6 @@ pub enum ColorChannelOrder { ARGB, } -#[allow(non_upper_case_globals)] -#[doc(hidden)] // No longer advertise in API docs. -impl ColorChannelOrder { - #[deprecated(note = "Renamed to `ColorChannelOrder::RGBA`.")] - pub const Rgba: Self = Self::RGBA; - - #[deprecated(note = "Renamed to `ColorChannelOrder::ABGR`.")] - pub const Abgr: Self = Self::ABGR; - - #[deprecated(note = "Renamed to `ColorChannelOrder::ARGB`.")] - pub const Argb: Self = Self::ARGB; -} - impl ColorChannelOrder { fn pack(self, rgba: [T; 4]) -> [T; 4] { let [r, g, b, a] = rgba; diff --git a/godot-core/src/builtin/mod.rs b/godot-core/src/builtin/mod.rs index 249e224f2..f7b7847e6 100644 --- a/godot-core/src/builtin/mod.rs +++ b/godot-core/src/builtin/mod.rs @@ -133,56 +133,6 @@ pub(crate) fn to_isize(i: usize) -> isize { i.try_into().unwrap() } -// ---------------------------------------------------------------------------------------------------------------------------------------------- -// Deprecated symbols - -/// Specialized types related to arrays. -#[deprecated = "Merged into `godot::builtin::iter`."] -#[doc(hidden)] // No longer advertise in API docs. -pub mod array { - pub type Iter<'a, T> = super::iter::ArrayIter<'a, T>; -} - -/// Specialized types related to dictionaries. -#[deprecated = "Merged into `godot::builtin::iter`."] -#[doc(hidden)] // No longer advertise in API docs. -pub mod dictionary { - pub type Iter<'a> = super::iter::DictIter<'a>; - pub type Keys<'a> = super::iter::DictKeys<'a>; - pub type TypedIter<'a, K, V> = super::iter::DictTypedIter<'a, K, V>; - pub type TypedKeys<'a, K> = super::iter::DictTypedKeys<'a, K>; -} - -#[deprecated = "Moved to `godot::meta` and submodules."] -#[doc(hidden)] // No longer advertise in API docs. -pub mod meta { - pub use crate::meta::error::*; - pub use crate::meta::*; -} - -/// The side of a [`Rect2`] or [`Rect2i`]. -/// -/// _Godot equivalent: `@GlobalScope.Side`_ -#[deprecated = "Merged with `godot::builtin::Side`."] -#[doc(hidden)] // No longer advertise in API docs. -pub type RectSide = Side; - -#[allow(non_upper_case_globals)] -#[doc(hidden)] // No longer advertise in API docs. -impl Side { - #[deprecated(note = "Renamed to `Side::LEFT`.")] - pub const Left: Side = Side::LEFT; - - #[deprecated(note = "Renamed to `Side::TOP`.")] - pub const Top: Side = Side::TOP; - - #[deprecated(note = "Renamed to `Side::RIGHT`.")] - pub const Right: Side = Side::RIGHT; - - #[deprecated(note = "Renamed to `Side::BOTTOM`.")] - pub const Bottom: Side = Side::BOTTOM; -} - // ---------------------------------------------------------------------------------------------------------------------------------------------- // #[test] utils for serde diff --git a/godot-core/src/builtin/projection.rs b/godot-core/src/builtin/projection.rs index b56b68e9b..4e1836ab8 100644 --- a/godot-core/src/builtin/projection.rs +++ b/godot-core/src/builtin/projection.rs @@ -551,28 +551,6 @@ pub enum ProjectionPlane { BOTTOM = 5, } -#[allow(non_upper_case_globals)] -#[doc(hidden)] // No longer advertise in API docs. -impl ProjectionPlane { - #[deprecated(note = "Renamed to `ProjectionPlane::NEAR`")] - pub const Near: Self = Self::NEAR; - - #[deprecated(note = "Renamed to `ProjectionPlane::FAR`")] - pub const Far: Self = Self::FAR; - - #[deprecated(note = "Renamed to `ProjectionPlane::LEFT`")] - pub const Left: Self = Self::LEFT; - - #[deprecated(note = "Renamed to `ProjectionPlane::TOP`")] - pub const Top: Self = Self::TOP; - - #[deprecated(note = "Renamed to `ProjectionPlane::RIGHT`")] - pub const Right: Self = Self::RIGHT; - - #[deprecated(note = "Renamed to `ProjectionPlane::BOTTOM`")] - pub const Bottom: Self = Self::BOTTOM; -} - impl ProjectionPlane { /// Convert from one of GDScript's `Projection.PLANE_*` integer constants. pub fn try_from_ord(ord: i64) -> Option { @@ -596,15 +574,6 @@ pub enum ProjectionEye { RIGHT = 2, } -#[allow(non_upper_case_globals)] -impl ProjectionEye { - #[deprecated(note = "Renamed to `ProjectionEye::LEFT`")] - pub const Left: Self = Self::LEFT; - - #[deprecated(note = "Renamed to `ProjectionEye::RIGHT`")] - pub const Right: Self = Self::RIGHT; -} - impl ProjectionEye { /// Convert from numbers `1` and `2`. pub fn try_from_ord(ord: i64) -> Option { diff --git a/godot-core/src/builtin/string/string_name.rs b/godot-core/src/builtin/string/string_name.rs index 3d3d0dc89..a312510c9 100644 --- a/godot-core/src/builtin/string/string_name.rs +++ b/godot-core/src/builtin/string/string_name.rs @@ -28,8 +28,14 @@ use crate::builtin::{GString, NodePath}; /// /// # Null bytes /// -/// Note that Godot ignores any bytes after a null-byte. This means that for instance `"hello, world!"` and `"hello, world!\0 ignored by Godot"` -/// will be treated as the same string if converted to a `StringName`. +/// Note that Godot ignores any bytes after a null-byte. This means that for instance `"hello, world!"` and \ +/// `"hello, world!\0 ignored by Godot"` will be treated as the same string if converted to a `StringName`. +/// +/// # Performance +/// +/// The fastest way to create string names is by using null-terminated C-string literals such as `c"MyClass"`. These have `'static` lifetime and +/// can be used directly by Godot, without allocation or conversion. The encoding is limited to Latin-1, however. See the corresponding +/// [`From<&'static CStr>` impl](#impl-From<%26CStr>-for-StringName). // Currently we rely on `transparent` for `borrow_string_sys`. #[repr(transparent)] pub struct StringName { @@ -41,31 +47,6 @@ impl StringName { Self { opaque } } - /// Creates a `StringName` from a static, nul-terminated ASCII/Latin-1 `b"string"` literal. - /// - /// Avoids unnecessary copies and allocations and directly uses the backing buffer. Useful for literals. - /// - /// # Example - /// ```no_run - /// use godot::builtin::StringName; - /// - /// // '±' is a Latin-1 character with codepoint 0xB1. Note that this is not UTF-8, where it would need two bytes. - /// let sname = StringName::from_latin1_with_nul(b"\xb1 Latin-1 string\0"); - /// ``` - /// - /// # Panics - /// When the string is not nul-terminated or contains interior nul bytes. - /// - /// Note that every byte is valid in Latin-1, so there is no encoding validation being performed. - #[cfg(since_api = "4.2")] - #[deprecated = "Since Rust 1.77, you can use c-string literals with `From/Into` instead of this function."] - pub fn from_latin1_with_nul(latin1_c_str: &'static [u8]) -> Self { - let c_str = std::ffi::CStr::from_bytes_with_nul(latin1_c_str) - .unwrap_or_else(|_| panic!("invalid or not nul-terminated CStr: '{latin1_c_str:?}'")); - - c_str.into() - } - /// Returns the number of characters in the string. /// /// _Godot equivalent: `length`_ diff --git a/godot-core/src/deprecated.rs b/godot-core/src/deprecated.rs index fd3fcf51e..b0dacfe6c 100644 --- a/godot-core/src/deprecated.rs +++ b/godot-core/src/deprecated.rs @@ -12,20 +12,18 @@ // https://github.com/rust-lang/rust/pull/58994. Fortunately, an extra layer of indirection solves most problems: we generate a declarative // macro that itself isn't deprecated, but _its_ expansion is. Since the expansion happens in a later step, the warning is emitted. -#[deprecated = "#[base] is no longer needed; Base is recognized directly. \n\ - More information on https://github.com/godot-rust/gdext/pull/577."] -pub const fn base_attribute() {} - -#[deprecated = "Cargo feature `custom-godot` has been renamed to `api-custom`. \n\ - More information on https://github.com/godot-rust/gdext/pull/702."] -pub const fn feature_custom_godot() {} - -#[cfg_attr( - since_api = "4.2", - deprecated = "Use #[export(range = (radians_as_degrees))] and not #[export(range = (radians))]. \n\ - More information on https://github.com/godotengine/godot/pull/82195." -)] -pub const fn export_range_radians() {} +// Usage example. +// +// 1. Declare a const fn which describes the deprecation warning. +// +// #[deprecated = "#[base] is no longer needed; Base is recognized directly. \n\ +// More information on https://github.com/godot-rust/gdext/pull/577."] +// pub const fn base_attribute() {} +// +// 2. At the place of usage, use the `emit_deprecated_warning!` macro to emit the warning. This can be generated by codegen, as well. +// +// #[cfg(feature = "custom-godot")] +// __deprecated::emit_deprecated_warning!(feature_custom_godot); #[macro_export] macro_rules! emit_deprecated_warning { @@ -37,61 +35,12 @@ macro_rules! emit_deprecated_warning { pub use crate::emit_deprecated_warning; // ---------------------------------------------------------------------------------------------------------------------------------------------- -// Old names for VariantOperator constants +// Concrete deprecations -#[allow(non_upper_case_globals)] -#[doc(hidden)] // No longer advertise in API docs. -impl crate::builtin::VariantOperator { - #[deprecated = "Renamed to `EQUAL`"] - pub const Equal: Self = Self::EQUAL; - #[deprecated = "Renamed to `NOT_EQUAL`"] - pub const NotEqual: Self = Self::NOT_EQUAL; - #[deprecated = "Renamed to `LESS`"] - pub const Less: Self = Self::LESS; - #[deprecated = "Renamed to `LESS_EQUAL`"] - pub const LessEqual: Self = Self::LESS_EQUAL; - #[deprecated = "Renamed to `GREATER`"] - pub const Greater: Self = Self::GREATER; - #[deprecated = "Renamed to `GREATER_EQUAL`"] - pub const GreaterEqual: Self = Self::GREATER_EQUAL; - #[deprecated = "Renamed to `ADD`"] - pub const Add: Self = Self::ADD; - #[deprecated = "Renamed to `SUBTRACT`"] - pub const Subtract: Self = Self::SUBTRACT; - #[deprecated = "Renamed to `MULTIPLY`"] - pub const Multiply: Self = Self::MULTIPLY; - #[deprecated = "Renamed to `DIVIDE`"] - pub const Divide: Self = Self::DIVIDE; - #[deprecated = "Renamed to `NEGATE`"] - pub const Negate: Self = Self::NEGATE; - #[deprecated = "Renamed to `POSITIVE`"] - pub const Positive: Self = Self::POSITIVE; - #[deprecated = "Renamed to `MODULO`"] - pub const Modulo: Self = Self::MODULO; - #[deprecated = "Renamed to `POWER`"] - pub const Power: Self = Self::POWER; - #[deprecated = "Renamed to `SHIFT_LEFT`"] - pub const ShiftLeft: Self = Self::SHIFT_LEFT; - #[deprecated = "Renamed to `SHIFT_RIGHT`"] - pub const ShiftRight: Self = Self::SHIFT_RIGHT; - #[deprecated = "Renamed to `BIT_AND`"] - pub const BitAnd: Self = Self::BIT_AND; - #[deprecated = "Renamed to `BIT_OR`"] - pub const BitOr: Self = Self::BIT_OR; - #[deprecated = "Renamed to `BIT_XOR`"] - pub const BitXor: Self = Self::BIT_XOR; - #[deprecated = "Renamed to `BIT_NEGATE`"] - pub const BitNegate: Self = Self::BIT_NEGATE; - #[deprecated = "Renamed to `AND`"] - pub const And: Self = Self::AND; - #[deprecated = "Renamed to `OR`"] - pub const Or: Self = Self::OR; - #[deprecated = "Renamed to `XOR`"] - pub const Xor: Self = Self::XOR; - #[deprecated = "Renamed to `NOT`"] - pub const Not: Self = Self::NOT; - #[deprecated = "Renamed to `IN`"] - pub const In: Self = Self::IN; - #[deprecated = "Renamed to `MAX`"] - pub const Max: Self = Self::MAX; -} +// This is a Godot-side deprecation. Since it's the only way in Godot 4.1, we keep compatibility for now. +#[cfg_attr( + since_api = "4.2", + deprecated = "Use #[export(range = (radians_as_degrees))] and not #[export(range = (radians))]. \n\ + More information on https://github.com/godotengine/godot/pull/82195." +)] +pub const fn export_range_radians() {} diff --git a/godot-core/src/engine.rs b/godot-core/src/engine.rs deleted file mode 100644 index 0cf9eb9bf..000000000 --- a/godot-core/src/engine.rs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) godot-rust; Bromeon and contributors. - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - */ - -#[deprecated = "Classes have been moved to `godot::classes`."] -pub use crate::classes::*; - -#[deprecated = "Enums have been moved to `godot::global`."] -pub mod global { - pub use crate::builtin::{Corner, EulerOrder, Side}; - pub use crate::global::*; -} - -#[deprecated = "Utility functions have been moved to `godot::global`."] -pub mod utilities { - pub use crate::global::*; -} - -#[deprecated = "Native structures have been moved to `godot::classes::native`."] -pub mod native { - pub use crate::gen::native::*; -} - -#[deprecated = "`godot::classes::translate` has been moved to `godot::tools`."] -pub mod translate { - pub use crate::tools::{tr, tr_n}; -} - -#[deprecated = "`create_script_instance` has been moved to `godot::obj::script`."] -pub use crate::obj::script::create_script_instance; - -#[deprecated = "`ScriptInstance` has been moved to `godot::obj::script`."] -pub use crate::obj::script::ScriptInstance; - -#[deprecated = "`SiMut` has been moved to `godot::obj::script`."] -pub use crate::obj::script::SiMut; - -#[deprecated = "`GFile` has been moved to `godot::tools`."] -pub use crate::tools::GFile; - -#[deprecated = "`IoError` has been moved to `godot::meta::error`."] -pub use crate::meta::error::IoError; - -#[deprecated = "`save` has been moved to `godot::global`."] -pub use crate::tools::save; - -#[deprecated = "`try_save` has been moved to `godot::global`."] -pub use crate::tools::try_save; - -#[deprecated = "`load` has been moved to `godot::global`."] -pub use crate::tools::load; - -#[deprecated = "`try_load` has been moved to `godot::global`."] -pub use crate::tools::try_load; diff --git a/godot-core/src/lib.rs b/godot-core/src/lib.rs index 34d64443e..efdf3e5db 100644 --- a/godot-core/src/lib.rs +++ b/godot-core/src/lib.rs @@ -62,24 +62,3 @@ pub mod private; /// Re-export logging macro. #[doc(hidden)] pub use godot_ffi::out; - -// ---------------------------------------------------------------------------------------------------------------------------------------------- -// Deprecated modules - -#[deprecated = "Module has been split into `godot::classes`, `godot::global` and `godot::tools`."] -#[doc(hidden)] // No longer advertise in API docs. -pub mod engine; - -#[deprecated = "Print macros have been moved to `godot::global`."] -#[doc(hidden)] // No longer advertise in API docs. -pub mod log { - pub use crate::global::{ - godot_error, godot_print, godot_print_rich, godot_script_error, godot_warn, - }; -} - -// ---- -// Validation - -#[cfg(all(feature = "docs", before_api = "4.3"))] -compile_error!("Documentation generation requires 4.3."); diff --git a/godot-core/src/obj/gd.rs b/godot-core/src/obj/gd.rs index 4a9ba564b..2b64b6228 100644 --- a/godot-core/src/obj/gd.rs +++ b/godot-core/src/obj/gd.rs @@ -846,7 +846,3 @@ impl std::hash::Hash for Gd { // its mutability is anyway present, in the Godot engine. impl std::panic::UnwindSafe for Gd {} impl std::panic::RefUnwindSafe for Gd {} - -#[deprecated = "Removed; see `Gd::try_to_unique()`"] -#[doc(hidden)] // No longer advertise in API docs. -pub type NotUniqueError = (); diff --git a/godot-core/src/obj/script.rs b/godot-core/src/obj/script.rs index dba6e2e23..adc4a4222 100644 --- a/godot-core/src/obj/script.rs +++ b/godot-core/src/obj/script.rs @@ -538,12 +538,12 @@ mod script_instance_info { use std::any::type_name; use std::ffi::c_void; - use crate::builtin::meta::{MethodInfo, PropertyInfo}; use crate::builtin::{StringName, Variant}; use crate::private::handle_panic; use crate::sys; use super::{ScriptInstance, ScriptInstanceData, SiMut}; + use crate::meta::{MethodInfo, PropertyInfo}; use sys::conv::{bool_to_sys, SYS_FALSE, SYS_TRUE}; /// # Safety diff --git a/godot-core/src/tools/gfile.rs b/godot-core/src/tools/gfile.rs index 7d1ac97b3..8f9944c2c 100644 --- a/godot-core/src/tools/gfile.rs +++ b/godot-core/src/tools/gfile.rs @@ -9,9 +9,9 @@ use crate::builtin::{real, GString, PackedByteArray, PackedStringArray, Variant} use crate::classes::file_access::{CompressionMode, ModeFlags}; use crate::classes::FileAccess; use crate::global::Error; +use crate::meta::error::IoError; use crate::obj::Gd; -use crate::engine::IoError; use std::cmp; use std::io::{BufRead, ErrorKind, Read, Seek, SeekFrom, Write}; diff --git a/godot-core/src/tools/save_load.rs b/godot-core/src/tools/save_load.rs index 228b5771e..0c473bf63 100644 --- a/godot-core/src/tools/save_load.rs +++ b/godot-core/src/tools/save_load.rs @@ -7,8 +7,8 @@ use crate::builtin::GString; use crate::classes::{Resource, ResourceLoader, ResourceSaver}; -use crate::engine::IoError; use crate::global::Error as GodotError; +use crate::meta::error::IoError; use crate::obj::{Gd, Inherits}; /// ⚠️ Loads a resource from the filesystem located at `path`, panicking on error. diff --git a/godot-macros/src/class/data_models/field.rs b/godot-macros/src/class/data_models/field.rs index 160a72a4e..caa0d44d8 100644 --- a/godot-macros/src/class/data_models/field.rs +++ b/godot-macros/src/class/data_models/field.rs @@ -40,7 +40,4 @@ pub struct Fields { /// The field with type `Base`, if available. pub base_field: Option, - - /// Whether a deprecated `#[base]` was used. - pub has_deprecated_base: bool, } diff --git a/godot-macros/src/class/data_models/field_export.rs b/godot-macros/src/class/data_models/field_export.rs index 0d76ec464..f3b0578af 100644 --- a/godot-macros/src/class/data_models/field_export.rs +++ b/godot-macros/src/class/data_models/field_export.rs @@ -262,7 +262,7 @@ impl FieldExport { "or_less", "exp", "radians_as_degrees", - "radians", // godot deprecated this key for 4.2 in favor of radians_as_degrees + "radians", // Godot deprecated this key since 4.2, in favor of `radians_as_degrees`. "degrees", "hide_slider", ]; diff --git a/godot-macros/src/class/derive_godot_class.rs b/godot-macros/src/class/derive_godot_class.rs index de4c6b55e..f1ee01e37 100644 --- a/godot-macros/src/class/derive_godot_class.rs +++ b/godot-macros/src/class/derive_godot_class.rs @@ -66,12 +66,6 @@ pub fn derive_godot_class(item: venial::Item) -> ParseResult { quote! {} }; - let deprecated_base_warning = if fields.has_deprecated_base { - quote! { ::godot::__deprecated::emit_deprecated_warning!(base_attribute); } - } else { - TokenStream::new() - }; - let (user_class_impl, has_default_virtual) = make_user_class_impl(class_name, struct_cfg.is_tool, &fields.all_fields); @@ -170,7 +164,6 @@ pub fn derive_godot_class(item: venial::Item) -> ParseResult { }); #prv::class_macros::#inherits_macro!(#class_name); - #deprecated_base_warning }) } @@ -385,7 +378,6 @@ fn parse_fields( ) -> ParseResult { let mut all_fields = vec![]; let mut base_field = Option::::None; - let mut has_deprecated_base = false; // Attributes on struct fields for (named_field, _punct) in named_fields { @@ -397,12 +389,6 @@ fn parse_fields( is_base = true; } - // deprecated #[base] - if KvParser::parse(&named_field.attributes, "base")?.is_some() { - has_deprecated_base = true; - is_base = true; - } - // OnReady type inference if path_ends_with_complex(&field.ty, "OnReady") { field.is_onready = true; @@ -480,7 +466,6 @@ fn parse_fields( Ok(Fields { all_fields, base_field, - has_deprecated_base, }) } diff --git a/godot/src/lib.rs b/godot/src/lib.rs index df2ced805..8b5946fa6 100644 --- a/godot/src/lib.rs +++ b/godot/src/lib.rs @@ -148,8 +148,8 @@ compile_error!("Must opt-in using `experimental-wasm` Cargo feature; keep in min #[cfg(all(feature = "double-precision", not(feature = "api-custom")))] compile_error!("The feature `double-precision` currently requires `api-custom` due to incompatibilities in the GDExtension API JSON."); -#[cfg(feature = "custom-godot")] -__deprecated::emit_deprecated_warning!(feature_custom_godot); +#[cfg(all(feature = "register-docs", before_api = "4.3"))] +compile_error!("Generating editor docs for Rust symbols requires at least Godot 4.3."); const fn _validate_features() { let mut count = 0; @@ -175,9 +175,6 @@ const _: () = _validate_features(); #[doc(inline)] pub use godot_core::{builtin, classes, global, meta, obj, tools}; -#[allow(deprecated)] -pub use godot_core::{engine, log}; - #[doc(hidden)] pub use godot_core::possibly_docs as docs; diff --git a/itest/rust/build.rs b/itest/rust/build.rs index c76d62b50..81f21e998 100644 --- a/itest/rust/build.rs +++ b/itest/rust/build.rs @@ -217,9 +217,8 @@ fn main() { let rust_tokens = quote::quote! { use godot::builtin::*; use godot::meta::*; - use godot::log::godot_error; use godot::obj::{Gd, InstanceId}; - use godot::global::Error; + use godot::global::{Error, godot_error}; use godot::classes::{Node, Resource}; #[derive(godot::register::GodotClass)] diff --git a/itest/rust/src/builtin_tests/string/gstring_test.rs b/itest/rust/src/builtin_tests/string/gstring_test.rs index e8366e43f..7b2268db4 100644 --- a/itest/rust/src/builtin_tests/string/gstring_test.rs +++ b/itest/rust/src/builtin_tests/string/gstring_test.rs @@ -66,7 +66,7 @@ fn string_clone() { #[itest] fn empty_string_chars() { - // Tests regression from #228: Null pointer passed to slice::from_raw_parts + // Tests regression from #228: Null pointer passed to slice::from_raw_parts(). let s = GString::new(); #[allow(deprecated)] diff --git a/itest/rust/src/framework/runner.rs b/itest/rust/src/framework/runner.rs index 1349e6b35..1dca97aa9 100644 --- a/itest/rust/src/framework/runner.rs +++ b/itest/rust/src/framework/runner.rs @@ -9,7 +9,7 @@ use std::time::{Duration, Instant}; use godot::builtin::{Array, GString, Variant, VariantArray}; use godot::classes::{Engine, Node, Os}; -use godot::log::godot_error; +use godot::global::godot_error; use godot::meta::ToGodot; use godot::obj::Gd; use godot::register::{godot_api, GodotClass}; From 8aaa1e6501fc7ef6417772288989d4e5577cc396 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Mon, 22 Jul 2024 22:40:09 +0200 Subject: [PATCH 2/3] Change VariantType::CamelCase to SHOUT_CASE in lazy function codegen --- godot-codegen/src/generator/builtins.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/godot-codegen/src/generator/builtins.rs b/godot-codegen/src/generator/builtins.rs index c1f1ce6a7..4d393ea44 100644 --- a/godot-codegen/src/generator/builtins.rs +++ b/godot-codegen/src/generator/builtins.rs @@ -38,15 +38,16 @@ pub fn generate_builtin_class_files( std::fs::create_dir_all(gen_path).expect("create classes directory"); let mut modules = vec![]; - for class in api.builtins.iter() { - let Some(class) = class.builtin_class.as_ref() else { + for variant in api.builtins.iter() { + let Some(class) = variant.builtin_class.as_ref() else { continue; }; // let godot_class_name = &class.name().godot_ty; let module_name = class.mod_name(); - let generated_class = make_builtin_class(class, ctx); + let variant_shout_name = util::ident(variant.godot_shout_name()); + let generated_class = make_builtin_class(class, &variant_shout_name, ctx); let file_contents = generated_class.code; let out_path = gen_path.join(format!("{}.rs", module_name.rust_mod)); @@ -87,7 +88,11 @@ pub fn make_builtin_module_file(classes_and_modules: Vec // ---------------------------------------------------------------------------------------------------------------------------------------------- // Implementation -fn make_builtin_class(class: &BuiltinClass, ctx: &mut Context) -> GeneratedBuiltin { +fn make_builtin_class( + class: &BuiltinClass, + variant_shout_name: &Ident, + ctx: &mut Context, +) -> GeneratedBuiltin { let godot_name = &class.name().godot_ty; let RustTy::BuiltinIdent(outer_class) = conv::to_rust_type(godot_name, None, ctx) else { @@ -98,7 +103,7 @@ fn make_builtin_class(class: &BuiltinClass, ctx: &mut Context) -> GeneratedBuilt let FnDefinitions { functions: methods, builders, - } = make_builtin_methods(class, &class.methods, ctx); + } = make_builtin_methods(class, variant_shout_name, &class.methods, ctx); let imports = util::make_imports(); let enums = enums::make_enums(&class.enums, &TokenStream::new()); @@ -134,12 +139,13 @@ fn make_builtin_class(class: &BuiltinClass, ctx: &mut Context) -> GeneratedBuilt fn make_builtin_methods( builtin_class: &BuiltinClass, + variant_shout_name: &Ident, methods: &[BuiltinMethod], ctx: &mut Context, ) -> FnDefinitions { - let definitions = methods - .iter() - .map(|method| make_builtin_method_definition(builtin_class, method, ctx)); + let definitions = methods.iter().map(|method| { + make_builtin_method_definition(builtin_class, variant_shout_name, method, ctx) + }); FnDefinitions::expand(definitions) } @@ -180,6 +186,7 @@ fn method_safety_doc(class_name: &TyName, method: &BuiltinMethod) -> Option FnDefinition { @@ -192,7 +199,7 @@ fn make_builtin_method_definition( let method_name_str = method.godot_name(); let fptr_access = if cfg!(feature = "codegen-lazy-fptrs") { - let variant_type = quote! { sys::VariantType::#builtin_name }; + let variant_type = quote! { sys::VariantType::#variant_shout_name }; let variant_type_str = &builtin_name.godot_ty; quote! { From d75810c9e4358ccdff78d3b369d8ef4f36cb4dc2 Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Mon, 22 Jul 2024 22:44:11 +0200 Subject: [PATCH 3/3] Update proc_macro2 min-version, to enable Literal::c_string() --- godot-codegen/Cargo.toml | 2 +- godot-macros/Cargo.toml | 2 +- itest/rust/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/godot-codegen/Cargo.toml b/godot-codegen/Cargo.toml index d10d3ab1c..ada9686b0 100644 --- a/godot-codegen/Cargo.toml +++ b/godot-codegen/Cargo.toml @@ -26,7 +26,7 @@ heck = "0.4" nanoserde = "0.1.35" # Minimum versions compatible with -Zminimal-versions -proc-macro2 = "1.0.63" +proc-macro2 = "1.0.80" # Literal::c_string() added in 1.0.80. quote = "1.0.29" # Since we don't use Regex for unicode parsing, the features unicode-bool/unicode-gencat are used instead of unicode-perl. diff --git a/godot-macros/Cargo.toml b/godot-macros/Cargo.toml index b0daedf41..737cc8c7e 100644 --- a/godot-macros/Cargo.toml +++ b/godot-macros/Cargo.toml @@ -19,7 +19,7 @@ proc-macro = true [dependencies] # Minimum versions compatible with -Zminimal-versions -proc-macro2 = "1.0.63" +proc-macro2 = "1.0.80" # Literal::c_string() added in 1.0.80. quote = "1.0.29" # Enabled by `docs` diff --git a/itest/rust/Cargo.toml b/itest/rust/Cargo.toml index ba6e8dd85..8778d188b 100644 --- a/itest/rust/Cargo.toml +++ b/itest/rust/Cargo.toml @@ -28,5 +28,5 @@ godot-bindings = { path = "../../godot-bindings" } # emit_godot_version_cfg repo-tweak = { path = "../repo-tweak" } # Minimum versions compatible with -Zminimal-versions -proc-macro2 = "1.0.63" +proc-macro2 = "1.0.80" # Literal::c_string() added in 1.0.80. quote = "1.0.29"