Skip to content

Commit 421324a

Browse files
authored
Merge pull request #808 from godot-rust/qol/remove-deprecated
Remove deprecated symbols from before v0.1
2 parents f601eb6 + d75810c commit 421324a

File tree

27 files changed

+64
-408
lines changed

27 files changed

+64
-408
lines changed

godot-codegen/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ heck = "0.4"
2626
nanoserde = "0.1.35"
2727

2828
# Minimum versions compatible with -Zminimal-versions
29-
proc-macro2 = "1.0.63"
29+
proc-macro2 = "1.0.80" # Literal::c_string() added in 1.0.80.
3030
quote = "1.0.29"
3131

3232
# Since we don't use Regex for unicode parsing, the features unicode-bool/unicode-gencat are used instead of unicode-perl.

godot-codegen/src/generator/builtins.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ pub fn generate_builtin_class_files(
3838
std::fs::create_dir_all(gen_path).expect("create classes directory");
3939

4040
let mut modules = vec![];
41-
for class in api.builtins.iter() {
42-
let Some(class) = class.builtin_class.as_ref() else {
41+
for variant in api.builtins.iter() {
42+
let Some(class) = variant.builtin_class.as_ref() else {
4343
continue;
4444
};
4545

4646
// let godot_class_name = &class.name().godot_ty;
4747
let module_name = class.mod_name();
4848

49-
let generated_class = make_builtin_class(class, ctx);
49+
let variant_shout_name = util::ident(variant.godot_shout_name());
50+
let generated_class = make_builtin_class(class, &variant_shout_name, ctx);
5051
let file_contents = generated_class.code;
5152

5253
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<GeneratedBuiltinModule>
8788
// ----------------------------------------------------------------------------------------------------------------------------------------------
8889
// Implementation
8990

90-
fn make_builtin_class(class: &BuiltinClass, ctx: &mut Context) -> GeneratedBuiltin {
91+
fn make_builtin_class(
92+
class: &BuiltinClass,
93+
variant_shout_name: &Ident,
94+
ctx: &mut Context,
95+
) -> GeneratedBuiltin {
9196
let godot_name = &class.name().godot_ty;
9297

9398
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
98103
let FnDefinitions {
99104
functions: methods,
100105
builders,
101-
} = make_builtin_methods(class, &class.methods, ctx);
106+
} = make_builtin_methods(class, variant_shout_name, &class.methods, ctx);
102107

103108
let imports = util::make_imports();
104109
let enums = enums::make_enums(&class.enums, &TokenStream::new());
@@ -134,12 +139,13 @@ fn make_builtin_class(class: &BuiltinClass, ctx: &mut Context) -> GeneratedBuilt
134139

135140
fn make_builtin_methods(
136141
builtin_class: &BuiltinClass,
142+
variant_shout_name: &Ident,
137143
methods: &[BuiltinMethod],
138144
ctx: &mut Context,
139145
) -> FnDefinitions {
140-
let definitions = methods
141-
.iter()
142-
.map(|method| make_builtin_method_definition(builtin_class, method, ctx));
146+
let definitions = methods.iter().map(|method| {
147+
make_builtin_method_definition(builtin_class, variant_shout_name, method, ctx)
148+
});
143149

144150
FnDefinitions::expand(definitions)
145151
}
@@ -180,6 +186,7 @@ fn method_safety_doc(class_name: &TyName, method: &BuiltinMethod) -> Option<Toke
180186

181187
fn make_builtin_method_definition(
182188
builtin_class: &BuiltinClass,
189+
variant_shout_name: &Ident,
183190
method: &BuiltinMethod,
184191
ctx: &mut Context,
185192
) -> FnDefinition {
@@ -192,7 +199,7 @@ fn make_builtin_method_definition(
192199
let method_name_str = method.godot_name();
193200

194201
let fptr_access = if cfg!(feature = "codegen-lazy-fptrs") {
195-
let variant_type = quote! { sys::VariantType::#builtin_name };
202+
let variant_type = quote! { sys::VariantType::#variant_shout_name };
196203
let variant_type_str = &builtin_name.godot_ty;
197204

198205
quote! {

godot-codegen/src/generator/central_files.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use quote::{format_ident, quote, ToTokens};
1515

1616
pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream {
1717
let build_config_struct = gdext_build_struct::make_gdext_build_struct(&api.godot_version);
18-
let (variant_type_enum, variant_type_deprecated_enumerators) =
19-
make_variant_type_enum(api, true);
18+
let variant_type_enum = make_variant_type_enum(api, true);
2019
let [opaque_32bit, opaque_64bit] = make_opaque_types(api);
2120

2221
quote! {
@@ -45,8 +44,6 @@ pub fn make_sys_central_code(api: &ExtensionApi) -> TokenStream {
4544
pub fn sys(self) -> crate::GDExtensionVariantType {
4645
self.ord as _
4746
}
48-
49-
#variant_type_deprecated_enumerators
5047
}
5148
}
5249
}
@@ -60,7 +57,7 @@ pub fn make_core_central_code(api: &ExtensionApi, ctx: &mut Context) -> TokenStr
6057
} = make_variant_enums(api, ctx);
6158

6259
let (global_enum_defs, global_reexported_enum_defs) = make_global_enums(api);
63-
let variant_type_traits = make_variant_type_enum(api, false).0;
60+
let variant_type_traits = make_variant_type_enum(api, false);
6461

6562
// TODO impl Clone, Debug, PartialEq, PartialOrd, Hash for VariantDispatch
6663
// 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<TokenStream>, Vec<TokenStream>)
205202
(global_enum_defs, global_reexported_enum_defs)
206203
}
207204

208-
fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> (TokenStream, TokenStream) {
205+
fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> TokenStream {
209206
let variant_type_enum = api
210207
.global_enums
211208
.iter()
@@ -215,9 +212,5 @@ fn make_variant_type_enum(api: &ExtensionApi, is_definition: bool) -> (TokenStre
215212
let define_enum = is_definition;
216213
let define_traits = !is_definition;
217214

218-
let enum_definition =
219-
enums::make_enum_definition_with(variant_type_enum, define_enum, define_traits);
220-
let deprecated_enumerators = enums::make_deprecated_enumerators(variant_type_enum);
221-
222-
(enum_definition, deprecated_enumerators)
215+
enums::make_enum_definition_with(variant_type_enum, define_enum, define_traits)
223216
}

godot-codegen/src/generator/enums.rs

-31
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//! See also models/domain/enums.rs for other enum-related methods.
1111
1212
use crate::models::domain::{Enum, Enumerator, EnumeratorValue};
13-
use crate::{conv, util};
1413
use proc_macro2::TokenStream;
1514
use quote::{quote, ToTokens};
1615

@@ -335,33 +334,3 @@ fn make_enumerator_definition(
335334
}
336335
}
337336
}
338-
339-
pub(crate) fn make_deprecated_enumerators(enum_: &Enum) -> TokenStream {
340-
let enum_name = &enum_.name;
341-
let deprecated_enumerators = enum_.enumerators.iter().filter_map(|enumerator| {
342-
let Enumerator { name, .. } = enumerator;
343-
344-
if name == "MAX" {
345-
return None;
346-
}
347-
348-
let converted = conv::to_pascal_case(&name.to_string())
349-
.replace("2d", "2D")
350-
.replace("3d", "3D");
351-
352-
let pascal_name = util::ident(&converted);
353-
let msg = format!("Use `{enum_name}::{name}` instead.");
354-
355-
let decl = quote! {
356-
#[deprecated = #msg]
357-
#[doc(hidden)] // No longer advertise in API docs.
358-
pub const #pascal_name: #enum_name = Self::#name;
359-
};
360-
361-
Some(decl)
362-
});
363-
364-
quote! {
365-
#( #deprecated_enumerators )*
366-
}
367-
}

godot-codegen/src/util.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@ pub fn make_imports() -> TokenStream {
3333

3434
#[cfg(since_api = "4.2")]
3535
pub fn make_string_name(identifier: &str) -> TokenStream {
36-
let lit = Literal::byte_string(format!("{identifier}\0").as_bytes());
37-
quote! {
38-
// TODO: C-string literals cannot currently be constructed in proc-macros, see the tracking issue:
39-
// https://github.com/rust-lang/rust/issues/119750
40-
{
41-
#[allow(deprecated)]
42-
StringName::from_latin1_with_nul(#lit)
43-
}
44-
}
36+
let c_string = std::ffi::CString::new(identifier).expect("CString::new() failed");
37+
let lit = Literal::c_string(&c_string);
38+
39+
quote! { StringName::from(#lit) }
4540
}
4641

4742
#[cfg(before_api = "4.2")]

godot-core/src/builtin/collections/array.rs

-18
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,6 @@ impl<T: ArrayElement> Array<T> {
189189
}
190190
}
191191

192-
#[deprecated = "Renamed to `get`."]
193-
#[doc(hidden)] // No longer advertise in API docs.
194-
pub fn try_get(&self, index: usize) -> Option<T> {
195-
self.get(index)
196-
}
197-
198192
/// Returns `true` if the array contains the given value. Equivalent of `has` in GDScript.
199193
pub fn contains(&self, value: &T) -> bool {
200194
self.as_inner().has(value.to_variant())
@@ -251,18 +245,6 @@ impl<T: ArrayElement> Array<T> {
251245
})
252246
}
253247

254-
#[deprecated = "Renamed to `front`, in line with GDScript method and consistent with `push_front` and `pop_front`."]
255-
#[doc(hidden)] // No longer advertise in API docs.
256-
pub fn first(&self) -> Option<T> {
257-
self.front()
258-
}
259-
260-
#[deprecated = "Renamed to `back`, in line with GDScript method."]
261-
#[doc(hidden)] // No longer advertise in API docs.
262-
pub fn last(&self) -> Option<T> {
263-
self.back()
264-
}
265-
266248
/// Clears the array, removing all elements.
267249
pub fn clear(&mut self) {
268250
// SAFETY: No new values are written to the array, we only remove values from the array.

godot-core/src/builtin/collections/packed_array.rs

-22
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,6 @@ macro_rules! impl_packed_array {
127127
self.as_inner().clear();
128128
}
129129

130-
/// Sets the value at the specified index.
131-
///
132-
/// # Panics
133-
///
134-
/// If `index` is out of bounds.
135-
#[deprecated = "Use [] operator (IndexMut) instead."]
136-
#[doc(hidden)] // No longer advertise in API docs.
137-
pub fn set(&mut self, index: usize, value: $Element) {
138-
let ptr_mut = self.ptr_mut(index);
139-
140-
// SAFETY: `ptr_mut` just checked that the index is not out of bounds.
141-
unsafe {
142-
*ptr_mut = value;
143-
}
144-
}
145-
146130
/// Appends an element to the end of the array. Equivalent of `append` and `push_back`
147131
/// in GDScript.
148132
#[doc(alias = "append")]
@@ -312,12 +296,6 @@ macro_rules! impl_packed_array {
312296
to_usize(self.as_inner().bsearch(Self::to_arg(value), true))
313297
}
314298

315-
#[deprecated = "Renamed to bsearch like in Godot, to avoid confusion with Rust's slice::binary_search."]
316-
#[doc(hidden)] // No longer advertise in API docs.
317-
pub fn binary_search(&self, value: $Element) -> usize {
318-
self.bsearch(&value)
319-
}
320-
321299
/// Reverses the order of the elements in the array.
322300
pub fn reverse(&mut self) {
323301
self.as_inner().reverse();

godot-core/src/builtin/color.rs

-13
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,6 @@ pub enum ColorChannelOrder {
377377
ARGB,
378378
}
379379

380-
#[allow(non_upper_case_globals)]
381-
#[doc(hidden)] // No longer advertise in API docs.
382-
impl ColorChannelOrder {
383-
#[deprecated(note = "Renamed to `ColorChannelOrder::RGBA`.")]
384-
pub const Rgba: Self = Self::RGBA;
385-
386-
#[deprecated(note = "Renamed to `ColorChannelOrder::ABGR`.")]
387-
pub const Abgr: Self = Self::ABGR;
388-
389-
#[deprecated(note = "Renamed to `ColorChannelOrder::ARGB`.")]
390-
pub const Argb: Self = Self::ARGB;
391-
}
392-
393380
impl ColorChannelOrder {
394381
fn pack<T>(self, rgba: [T; 4]) -> [T; 4] {
395382
let [r, g, b, a] = rgba;

godot-core/src/builtin/mod.rs

-50
Original file line numberDiff line numberDiff line change
@@ -133,56 +133,6 @@ pub(crate) fn to_isize(i: usize) -> isize {
133133
i.try_into().unwrap()
134134
}
135135

136-
// ----------------------------------------------------------------------------------------------------------------------------------------------
137-
// Deprecated symbols
138-
139-
/// Specialized types related to arrays.
140-
#[deprecated = "Merged into `godot::builtin::iter`."]
141-
#[doc(hidden)] // No longer advertise in API docs.
142-
pub mod array {
143-
pub type Iter<'a, T> = super::iter::ArrayIter<'a, T>;
144-
}
145-
146-
/// Specialized types related to dictionaries.
147-
#[deprecated = "Merged into `godot::builtin::iter`."]
148-
#[doc(hidden)] // No longer advertise in API docs.
149-
pub mod dictionary {
150-
pub type Iter<'a> = super::iter::DictIter<'a>;
151-
pub type Keys<'a> = super::iter::DictKeys<'a>;
152-
pub type TypedIter<'a, K, V> = super::iter::DictTypedIter<'a, K, V>;
153-
pub type TypedKeys<'a, K> = super::iter::DictTypedKeys<'a, K>;
154-
}
155-
156-
#[deprecated = "Moved to `godot::meta` and submodules."]
157-
#[doc(hidden)] // No longer advertise in API docs.
158-
pub mod meta {
159-
pub use crate::meta::error::*;
160-
pub use crate::meta::*;
161-
}
162-
163-
/// The side of a [`Rect2`] or [`Rect2i`].
164-
///
165-
/// _Godot equivalent: `@GlobalScope.Side`_
166-
#[deprecated = "Merged with `godot::builtin::Side`."]
167-
#[doc(hidden)] // No longer advertise in API docs.
168-
pub type RectSide = Side;
169-
170-
#[allow(non_upper_case_globals)]
171-
#[doc(hidden)] // No longer advertise in API docs.
172-
impl Side {
173-
#[deprecated(note = "Renamed to `Side::LEFT`.")]
174-
pub const Left: Side = Side::LEFT;
175-
176-
#[deprecated(note = "Renamed to `Side::TOP`.")]
177-
pub const Top: Side = Side::TOP;
178-
179-
#[deprecated(note = "Renamed to `Side::RIGHT`.")]
180-
pub const Right: Side = Side::RIGHT;
181-
182-
#[deprecated(note = "Renamed to `Side::BOTTOM`.")]
183-
pub const Bottom: Side = Side::BOTTOM;
184-
}
185-
186136
// ----------------------------------------------------------------------------------------------------------------------------------------------
187137
// #[test] utils for serde
188138

godot-core/src/builtin/projection.rs

-31
Original file line numberDiff line numberDiff line change
@@ -551,28 +551,6 @@ pub enum ProjectionPlane {
551551
BOTTOM = 5,
552552
}
553553

554-
#[allow(non_upper_case_globals)]
555-
#[doc(hidden)] // No longer advertise in API docs.
556-
impl ProjectionPlane {
557-
#[deprecated(note = "Renamed to `ProjectionPlane::NEAR`")]
558-
pub const Near: Self = Self::NEAR;
559-
560-
#[deprecated(note = "Renamed to `ProjectionPlane::FAR`")]
561-
pub const Far: Self = Self::FAR;
562-
563-
#[deprecated(note = "Renamed to `ProjectionPlane::LEFT`")]
564-
pub const Left: Self = Self::LEFT;
565-
566-
#[deprecated(note = "Renamed to `ProjectionPlane::TOP`")]
567-
pub const Top: Self = Self::TOP;
568-
569-
#[deprecated(note = "Renamed to `ProjectionPlane::RIGHT`")]
570-
pub const Right: Self = Self::RIGHT;
571-
572-
#[deprecated(note = "Renamed to `ProjectionPlane::BOTTOM`")]
573-
pub const Bottom: Self = Self::BOTTOM;
574-
}
575-
576554
impl ProjectionPlane {
577555
/// Convert from one of GDScript's `Projection.PLANE_*` integer constants.
578556
pub fn try_from_ord(ord: i64) -> Option<Self> {
@@ -596,15 +574,6 @@ pub enum ProjectionEye {
596574
RIGHT = 2,
597575
}
598576

599-
#[allow(non_upper_case_globals)]
600-
impl ProjectionEye {
601-
#[deprecated(note = "Renamed to `ProjectionEye::LEFT`")]
602-
pub const Left: Self = Self::LEFT;
603-
604-
#[deprecated(note = "Renamed to `ProjectionEye::RIGHT`")]
605-
pub const Right: Self = Self::RIGHT;
606-
}
607-
608577
impl ProjectionEye {
609578
/// Convert from numbers `1` and `2`.
610579
pub fn try_from_ord(ord: i64) -> Option<Self> {

0 commit comments

Comments
 (0)