Skip to content

Commit 732b1ae

Browse files
authored
Merge pull request #1386 from godot-rust/qol/cleanups
Various small cleanups
2 parents 2d0a89b + da6710c commit 732b1ae

File tree

16 files changed

+47
-33
lines changed

16 files changed

+47
-33
lines changed

check.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ function findGodot() {
142142
# builtins like `test`.
143143

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

148154
function cmd_clippy() {

godot-codegen/src/generator/signals.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// for these signals, and integration is slightly different due to lack of WithBaseField trait. Nonetheless, some parts could potentially
1111
// be extracted into a future crate shared by godot-codegen and godot-macros.
1212

13+
// TODO(v0.5): signal parameters are Gd<T> instead of conservatively Option<Gd<T>>, which is a bug.
14+
1315
use proc_macro2::{Ident, TokenStream};
1416
use quote::{format_ident, quote};
1517

godot-codegen/src/models/domain.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,19 +737,22 @@ pub enum RustTy {
737737
/// C-style raw pointer to a `RustTy`.
738738
RawPointer { inner: Box<RustTy>, is_const: bool },
739739

740-
/// `Array<Gd<PhysicsBody3D>>`
740+
/// `Array<Gd<PhysicsBody3D>>`. Never contains `Option` elements.
741741
EngineArray {
742742
tokens: TokenStream,
743-
#[allow(dead_code)] // only read in minimal config
743+
744+
#[allow(dead_code)] // Only read in minimal config.
744745
elem_class: String,
745746
},
746747

747748
/// `module::Enum` or `module::Bitfield`
748749
EngineEnum {
749750
tokens: TokenStream,
750-
/// `None` for globals
751-
#[allow(dead_code)] // only read in minimal config
751+
752+
/// `None` for globals.
753+
#[allow(dead_code)] // Only read in minimal config.
752754
surrounding_class: Option<String>,
755+
753756
is_bitfield: bool,
754757
},
755758

@@ -794,7 +797,6 @@ impl RustTy {
794797
/// Returns tokens without `Option<T>` wrapper, even for nullable engine classes.
795798
///
796799
/// For `EngineClass`, always returns `Gd<T>` regardless of nullability. For other types, behaves the same as `ToTokens`.
797-
// TODO(v0.5): only used for signal params, which is a bug. Those should conservatively be Option<Gd<T>> as well.
798800
// Might also be useful to directly extract inner `gd_tokens` field.
799801
pub fn tokens_non_null(&self) -> TokenStream {
800802
match self {

godot-core/src/builtin/basis.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -703,22 +703,22 @@ mod test {
703703
Basis::from_euler(EulerOrder::XYZ, euler_xyz_from_rotation);
704704

705705
let res = to_rotation.inverse() * rotation_from_xyz_computed_euler;
706+
let col_a = res.col_a();
707+
let col_b = res.col_b();
708+
let col_c = res.col_c();
706709

707710
assert!(
708-
(res.col_a() - Vector3::new(1.0, 0.0, 0.0)).length() <= 0.1,
709-
"Double check with XYZ rot order failed, due to X {} with {deg_original_euler} using {rot_order:?}",
710-
res.col_a(),
711-
);
711+
(col_a - Vector3::new(1.0, 0.0, 0.0)).length() <= 0.1,
712+
"Double check with XYZ rot order failed, due to A {col_a} with {deg_original_euler} using {rot_order:?}",
713+
);
712714
assert!(
713-
(res.col_b() - Vector3::new(0.0, 1.0, 0.0)).length() <= 0.1,
714-
"Double check with XYZ rot order failed, due to Y {} with {deg_original_euler} using {rot_order:?}",
715-
res.col_b(),
716-
);
715+
(col_b - Vector3::new(0.0, 1.0, 0.0)).length() <= 0.1,
716+
"Double check with XYZ rot order failed, due to B {col_b} with {deg_original_euler} using {rot_order:?}",
717+
);
717718
assert!(
718-
(res.col_c() - Vector3::new(0.0, 0.0, 1.0)).length() <= 0.1,
719-
"Double check with XYZ rot order failed, due to Z {} with {deg_original_euler} using {rot_order:?}",
720-
res.col_c(),
721-
);
719+
(col_c - Vector3::new(0.0, 0.0, 1.0)).length() <= 0.1,
720+
"Double check with XYZ rot order failed, due to C {col_c} with {deg_original_euler} using {rot_order:?}",
721+
);
722722
}
723723

724724
#[test]

godot-core/src/builtin/callable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ impl Callable {
461461
/// _Godot equivalent: `hash`_
462462
}
463463

464-
#[deprecated = "renamed to hash_u32"]
464+
#[deprecated = "renamed to `hash_u32`"]
465465
pub fn hash(&self) -> u32 {
466466
self.as_inner().hash().try_into().unwrap()
467467
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<T: ArrayElement> Array<T> {
293293
/// because different arrays can have identical hash values due to hash collisions.
294294
}
295295

296-
#[deprecated = "renamed to hash_u32"]
296+
#[deprecated = "renamed to `hash_u32`"]
297297
pub fn hash(&self) -> u32 {
298298
self.as_inner().hash().try_into().unwrap()
299299
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl Dictionary {
289289
/// Returns a 32-bit integer hash value representing the dictionary and its contents.
290290
}
291291

292-
#[deprecated = "renamed to hash_u32"]
292+
#[deprecated = "renamed to `hash_u32`"]
293293
#[must_use]
294294
pub fn hash(&self) -> u32 {
295295
self.as_inner().hash().try_into().unwrap()

godot-core/src/builtin/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub mod inner {
118118

119119
#[macro_export]
120120
macro_rules! declare_hash_u32_method {
121-
($ ($docs:tt)+ ) => {
121+
( $( $docs:tt )+ ) => {
122122
$( $docs )+
123123
pub fn hash_u32(&self) -> u32 {
124124
self.as_inner().hash().try_into().expect("Godot hashes are uint32_t")

godot-core/src/builtin/string/gstring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl GString {
160160
/// Returns a 32-bit integer hash value representing the string.
161161
}
162162

163-
#[deprecated = "renamed to hash_u32"]
163+
#[deprecated = "renamed to `hash_u32`"]
164164
pub fn hash(&self) -> u32 {
165165
self.as_inner()
166166
.hash()

godot-core/src/builtin/string/node_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ impl NodePath {
118118
}
119119

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

124-
#[deprecated = "renamed to hash_u32"]
124+
#[deprecated = "renamed to `hash_u32`"]
125125
pub fn hash(&self) -> u32 {
126126
self.as_inner()
127127
.hash()

0 commit comments

Comments
 (0)