Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ function findGodot() {
# builtins like `test`.

function cmd_fmt() {
run cargo fmt --all -- --check
# Run rustfmt in nightly toolchain if available.
if [[ $(rustup toolchain list) =~ nightly ]]; then
run cargo +nightly fmt --all -- --check
else
log -e "${YELLOW}Warning: nightly toolchain not found; stable rustfmt might not pass CI.${END}"
run cargo fmt --all -- --check
fi
}

function cmd_clippy() {
Expand Down
2 changes: 2 additions & 0 deletions godot-codegen/src/generator/signals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// for these signals, and integration is slightly different due to lack of WithBaseField trait. Nonetheless, some parts could potentially
// be extracted into a future crate shared by godot-codegen and godot-macros.

// TODO(v0.5): signal parameters are Gd<T> instead of conservatively Option<Gd<T>>, which is a bug.

use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};

Expand Down
12 changes: 7 additions & 5 deletions godot-codegen/src/models/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,19 +737,22 @@ pub enum RustTy {
/// C-style raw pointer to a `RustTy`.
RawPointer { inner: Box<RustTy>, is_const: bool },

/// `Array<Gd<PhysicsBody3D>>`
/// `Array<Gd<PhysicsBody3D>>`. Never contains `Option` elements.
EngineArray {
tokens: TokenStream,
#[allow(dead_code)] // only read in minimal config

#[allow(dead_code)] // Only read in minimal config.
elem_class: String,
},

/// `module::Enum` or `module::Bitfield`
EngineEnum {
tokens: TokenStream,
/// `None` for globals
#[allow(dead_code)] // only read in minimal config

/// `None` for globals.
#[allow(dead_code)] // Only read in minimal config.
surrounding_class: Option<String>,

is_bitfield: bool,
},

Expand Down Expand Up @@ -794,7 +797,6 @@ impl RustTy {
/// Returns tokens without `Option<T>` wrapper, even for nullable engine classes.
///
/// For `EngineClass`, always returns `Gd<T>` regardless of nullability. For other types, behaves the same as `ToTokens`.
// TODO(v0.5): only used for signal params, which is a bug. Those should conservatively be Option<Gd<T>> as well.
// Might also be useful to directly extract inner `gd_tokens` field.
pub fn tokens_non_null(&self) -> TokenStream {
match self {
Expand Down
24 changes: 12 additions & 12 deletions godot-core/src/builtin/basis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,22 +703,22 @@ mod test {
Basis::from_euler(EulerOrder::XYZ, euler_xyz_from_rotation);

let res = to_rotation.inverse() * rotation_from_xyz_computed_euler;
let col_a = res.col_a();
let col_b = res.col_b();
let col_c = res.col_c();

assert!(
(res.col_a() - Vector3::new(1.0, 0.0, 0.0)).length() <= 0.1,
"Double check with XYZ rot order failed, due to X {} with {deg_original_euler} using {rot_order:?}",
res.col_a(),
);
(col_a - Vector3::new(1.0, 0.0, 0.0)).length() <= 0.1,
"Double check with XYZ rot order failed, due to A {col_a} with {deg_original_euler} using {rot_order:?}",
);
assert!(
(res.col_b() - Vector3::new(0.0, 1.0, 0.0)).length() <= 0.1,
"Double check with XYZ rot order failed, due to Y {} with {deg_original_euler} using {rot_order:?}",
res.col_b(),
);
(col_b - Vector3::new(0.0, 1.0, 0.0)).length() <= 0.1,
"Double check with XYZ rot order failed, due to B {col_b} with {deg_original_euler} using {rot_order:?}",
);
assert!(
(res.col_c() - Vector3::new(0.0, 0.0, 1.0)).length() <= 0.1,
"Double check with XYZ rot order failed, due to Z {} with {deg_original_euler} using {rot_order:?}",
res.col_c(),
);
(col_c - Vector3::new(0.0, 0.0, 1.0)).length() <= 0.1,
"Double check with XYZ rot order failed, due to C {col_c} with {deg_original_euler} using {rot_order:?}",
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl Callable {
/// _Godot equivalent: `hash`_
}

#[deprecated = "renamed to hash_u32"]
#[deprecated = "renamed to `hash_u32`"]
pub fn hash(&self) -> u32 {
self.as_inner().hash().try_into().unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/collections/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl<T: ArrayElement> Array<T> {
/// because different arrays can have identical hash values due to hash collisions.
}

#[deprecated = "renamed to hash_u32"]
#[deprecated = "renamed to `hash_u32`"]
pub fn hash(&self) -> u32 {
self.as_inner().hash().try_into().unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/collections/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl Dictionary {
/// Returns a 32-bit integer hash value representing the dictionary and its contents.
}

#[deprecated = "renamed to hash_u32"]
#[deprecated = "renamed to `hash_u32`"]
#[must_use]
pub fn hash(&self) -> u32 {
self.as_inner().hash().try_into().unwrap()
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub mod inner {

#[macro_export]
macro_rules! declare_hash_u32_method {
($ ($docs:tt)+ ) => {
( $( $docs:tt )+ ) => {
$( $docs )+
pub fn hash_u32(&self) -> u32 {
self.as_inner().hash().try_into().expect("Godot hashes are uint32_t")
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/string/gstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl GString {
/// Returns a 32-bit integer hash value representing the string.
}

#[deprecated = "renamed to hash_u32"]
#[deprecated = "renamed to `hash_u32`"]
pub fn hash(&self) -> u32 {
self.as_inner()
.hash()
Expand Down
4 changes: 2 additions & 2 deletions godot-core/src/builtin/string/node_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ impl NodePath {
}

crate::declare_hash_u32_method! {
/// Returns a 32-bit integer hash value representing the string.
/// Returns a 32-bit integer hash value representing the node path.
}

#[deprecated = "renamed to hash_u32"]
#[deprecated = "renamed to `hash_u32`"]
pub fn hash(&self) -> u32 {
self.as_inner()
.hash()
Expand Down
2 changes: 1 addition & 1 deletion godot-core/src/builtin/string/string_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl StringName {
/// Returns a 32-bit integer hash value representing the string.
}

#[deprecated = "renamed to hash_u32"]
#[deprecated = "renamed to `hash_u32`"]
pub fn hash(&self) -> u32 {
self.as_inner()
.hash()
Expand Down
6 changes: 3 additions & 3 deletions godot-core/src/builtin/variant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,17 +311,17 @@ impl Variant {
///
/// _Godot equivalent : `@GlobalScope.hash()`_
pub fn hash_u32(&self) -> u32 {
// @GlobalScope.hash() actually calls the VariantUtilityFunctions::hash(&Variant) function (cpp).
// @GlobalScope.hash() actually calls the VariantUtilityFunctions::hash(&Variant) function (C++).
// This function calls the passed reference's `hash` method, which returns a uint32_t.
// Therefore, casting this function to u32 is always fine.
unsafe { interface_fn!(variant_hash)(self.var_sys()) }
.try_into()
.expect("Godot hashes are uint32_t")
}

#[deprecated = "renamed to hash_u32 and type changed to u32"]
#[deprecated = "renamed to `hash_u32` and type changed to `u32`"]
pub fn hash(&self) -> i64 {
unsafe { interface_fn!(variant_hash)(self.var_sys()) }
self.hash_u32().into()
}

/// Interpret the `Variant` as `bool`.
Expand Down
6 changes: 5 additions & 1 deletion godot-macros/src/class/data_models/inherent_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,11 @@ fn add_virtual_script_call(
rename: &Option<String>,
gd_self_parameter: Option<Ident>,
) -> String {
assert!(cfg!(since_api = "4.3"));
#[allow(clippy::assertions_on_constants)]
{
// Without braces, clippy removes the #[allow] for some reason...
assert!(cfg!(since_api = "4.3"));
}

// Update parameter names, so they can be forwarded (e.g. a "_" declared by the user cannot).
let is_params = function.params.iter_mut().skip(1); // skip receiver.
Expand Down
2 changes: 1 addition & 1 deletion godot-macros/src/class/derive_godot_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn derive_godot_class(item: venial::Item) -> ParseResult<TokenStream> {
let class_name = &class.name;
let class_name_str: String = struct_cfg
.rename
.map_or_else(|| class.name.clone(), |rename| rename)
.unwrap_or_else(|| class.name.clone())
.to_string();

let class_name_allocation = quote! { ClassId::__alloc_next_unicode(#class_name_str) };
Expand Down
1 change: 0 additions & 1 deletion itest/rust/src/builtin_tests/containers/signal_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use godot::meta::{FromGodot, GodotConvert, ToGodot};
use godot::obj::{Base, Gd, InstanceId, NewAlloc, NewGd};
use godot::prelude::ConvertError;
use godot::register::{godot_api, GodotClass};
use godot::sys;
use godot::sys::Global;

use crate::framework::itest;
Expand Down
3 changes: 2 additions & 1 deletion itest/rust/src/engine_tests/async_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use godot::builtin::{array, vslice, Array, Callable, Signal};
use godot::classes::{Object, RefCounted};
use godot::obj::{Base, Gd, NewAlloc, NewGd};
use godot::prelude::{godot_api, GodotClass};
use godot::sys;
use godot::task::{self, create_test_signal_future_resolver, SignalFuture, TaskHandle};

use crate::framework::{expect_async_panic, itest, TestContext};
Expand Down Expand Up @@ -132,6 +131,8 @@ fn async_task_signal_future_panic() -> TaskHandle {
#[cfg(feature = "experimental-threads")]
#[itest(async)]
fn signal_future_non_send_arg_panic() -> TaskHandle {
use godot::sys;

use crate::framework::ThreadCrosser;

let mut object = RefCounted::new_gd();
Expand Down
Loading