Skip to content

Commit dbbd59c

Browse files
authored
Merge pull request #802 from godot-rust/qol/small-cleanup
Typos + code reordering
2 parents 3e24714 + c1479a8 commit dbbd59c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+238
-257
lines changed

.github/workflows/release-version.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ jobs:
179179
# # Note: first block was for an alternative approach, where a separate `releases` branch tracks deployments.
180180
# # Such a branch would however be disjoint and require quite a bit of extra space in the repo.
181181
# run: |
182-
# # Backup current repo, so we can checkout.
182+
# # Backup current repo, so we can check out.
183183
# mkdir -p /tmp/repo
184184
# rsync -av --exclude .git --exclude target ./ /tmp/repo/
185185
# git fetch origin releases && git switch releases || git switch --orphan releases

godot-bindings/src/godot_version.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn test_godot_versions() {
9090
("4.0.rc1.official.8843d9ad3", 4, 0, 0, "rc1", s("8843d9ad3")),
9191
("4.0.stable.arch_linux", 4, 0, 0, "stable", None),
9292
("4.1.1.stable.arch_linux\n", 4, 1, 1, "stable", None),
93-
// Output from 4.0.stable on MacOS in debug mode:
93+
// Output from 4.0.stable on macOS in debug mode:
9494
// https://github.com/godotengine/godot/issues/74906
9595
("arguments
9696
0: /Users/runner/work/_temp/godot_bin/godot.macos.editor.dev.x86_64

godot-cell/src/blocking_cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::blocking_guards::{MutGuardBlocking, RefGuardBlocking};
1515
use crate::cell::GdCellInner;
1616
use crate::guards::InaccessibleGuard;
1717

18-
/// Blocking version of [`panicking::GdCell`](crate::panicking::GdCell) for multi-threaded usage.
18+
/// Blocking version of [`panicking::GdCell`](crate::panicking::GdCell) for multithreaded usage.
1919
///
2020
/// This version of GdCell blocks the current thread if it does not yet hold references to the cell.
2121
///

godot-cell/src/cell.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<T> GdCellInner<T> {
121121
let value = state.get_ptr();
122122

123123
// SAFETY: `increment_mut` succeeded, therefore any existing mutable references are inaccessible.
124-
// Additionally no new references can be created, unless the returned guard is made inaccessible.
124+
// Additionally, no new references can be created, unless the returned guard is made inaccessible.
125125
//
126126
// This is the case because the only way for a new `GdMut` or `GdRef` to be made after this is for
127127
// either this guard to be dropped or `make_inaccessible` to be called and succeed.
@@ -170,10 +170,9 @@ impl<T> GdCellInner<T> {
170170
}
171171
}
172172

173-
// SAFETY: `T` is sync so we can return references to it on different threads, it is also send so we can return
174-
// mutable references to it on different threads.
175-
// Additionally all internal state is synchronized via a mutex, so we wont have race conditions when trying
176-
// to use it from multiple threads.
173+
// SAFETY: `T` is Sync, so we can return references to it on different threads.
174+
// It is also Send, so we can return mutable references to it on different threads.
175+
// Additionally, all internal state is synchronized via a mutex, so we won't have race conditions when trying to use it from multiple threads.
177176
unsafe impl<T: Send + Sync> Sync for GdCellInner<T> {}
178177

179178
/// Mutable state of the `GdCell`, bundled together to make it easier to avoid deadlocks when locking the
@@ -227,7 +226,7 @@ impl<T> CellState<T> {
227226
NonNull::new(self.ptr).unwrap()
228227
}
229228

230-
/// Push a pointer to this state..
229+
/// Push a pointer to this state.
231230
pub(crate) fn push_ptr(&mut self, new_ptr: NonNull<T>) -> usize {
232231
self.ptr = new_ptr.as_ptr();
233232
self.stack_depth += 1;

godot-cell/src/guards.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<'a, T> Drop for MutGuard<'a, T> {
196196
/// creation. When the guard is dropped, `state`'s pointer is reset to the original pointer.
197197
///
198198
/// This ensures that any new references are derived from the new reference we pass in, and when this guard
199-
/// is dropped the state is reset to what it was before, as if this guard never existed.
199+
/// is dropped, it resets the state to what it was before, as if this guard never existed.
200200
#[derive(Debug)]
201201
pub struct InaccessibleGuard<'a, T> {
202202
state: &'a Mutex<CellState<T>>,

godot-cell/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
//! reference (or other pointer) to some value is considered accessible when it is possible to either read
2626
//! from or write to the value it points to without using `unsafe`. Importantly, if we know that a reference
2727
//! `a` is inaccessible, and then we create a new reference `b` derived from `a` to the same value, then we
28-
//! know for sure that `b` wont alias `a`. This is because aliasing in rust is based on accesses, and if we
28+
//! know for sure that `b` won't alias `a`. This is because aliasing in rust is based on accesses, and if we
2929
//! never access `a` then we cannot ever violate aliasing for `a` and `b`. And since `b` is derived from `a`
3030
//! (that is, `b` was created from `a` somehow such as by casting `a` to a raw pointer then to a reference
31-
//! `b`), then `a` wont get invalidated by accesses to `b`.
31+
//! `b`), then `a` won't get invalidated by accesses to `b`.
3232
3333
mod blocking_cell;
3434
mod blocking_guards;

godot-cell/tests/mock/blocking.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl MyClass {
3232

3333
/// Call each method from different threads, allowing them to run in parallel.
3434
///
35-
/// This should not cause borrow failures and should not lead to dead locks.
35+
/// This should not cause borrow failures and should not lead to deadlocks.
3636
#[test]
3737
fn calls_parallel() {
3838
use std::thread;
@@ -61,7 +61,7 @@ fn calls_parallel() {
6161

6262
/// Call each method from different threads, allowing them to run in parallel.
6363
///
64-
/// This should not cause borrow failures and should not lead to dead locks.
64+
/// This should not cause borrow failures and should not lead to deadlocks.
6565
///
6666
/// Runs each method several times in a row. This should reduce the non-determinism that comes from
6767
/// scheduling of threads.
@@ -95,7 +95,7 @@ fn calls_parallel_many_serial() {
9595

9696
/// Call each method from different threads, allowing them to run in parallel.
9797
///
98-
/// This should not cause borrow failures and should not lead to dead locks.
98+
/// This should not cause borrow failures and should not lead to deadlocks.
9999
///
100100
/// Runs all the tests several times. This is different from [`calls_parallel_many_serial`] as that calls the
101101
/// methods like AAA...BBB...CCC..., whereas this interleaves the methods like ABC...ABC...ABC...

godot-cell/tests/mock/panicking.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn calls_different_thread() {
8383
/// Call each method from different threads, allowing them to run in parallel.
8484
///
8585
/// This may cause borrow failures, we do a best-effort attempt at estimating the value then. We can detect
86-
/// if the first call failed, so then we know the integer was incremented by 0. Otherwise we at least know
86+
/// if the first call failed, so then we know the integer was incremented by 0. Otherwise, we at least know
8787
/// the range of values that it can be incremented by.
8888
#[test]
8989
fn calls_parallel() {
@@ -114,7 +114,7 @@ fn calls_parallel() {
114114
/// Call each method from different threads, allowing them to run in parallel.
115115
///
116116
/// This may cause borrow failures, we do a best-effort attempt at estimating the value then. We can detect
117-
/// if the first call failed, so then we know the integer was incremented by 0. Otherwise we at least know
117+
/// if the first call failed, so then we know the integer was incremented by 0. Otherwise, we at least know
118118
/// the range of values that it can be incremented by.
119119
///
120120
/// Runs each method several times in a row. This should reduce the non-determinism that comes from
@@ -150,7 +150,7 @@ fn calls_parallel_many_serial() {
150150
/// Call each method from different threads, allowing them to run in parallel.
151151
///
152152
/// This may cause borrow failures, we do a best-effort attempt at estimating the value then. We can detect
153-
/// if the first call failed, so then we know the integer was incremented by 0. Otherwise we at least know
153+
/// if the first call failed, so then we know the integer was incremented by 0. Otherwise, we at least know
154154
/// the range of values that it can be incremented by.
155155
///
156156
/// Runs all the tests several times. This is different from [`calls_parallel_many_serial`] as that calls the

godot-codegen/src/conv/name_conversions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn try_strip_prefixes<'e>(enumerator: &'e str, prefixes: &[&str]) -> &'e str {
280280
enumerator
281281
}
282282

283-
/// Check if input is a valid identifier; ie. no special characters except '_' and not starting with a digit.
283+
/// Check if input is a valid identifier; i.e. no special characters except '_' and not starting with a digit.
284284
fn is_valid_ident(s: &str) -> bool {
285285
!starts_with_invalid_char(s) && s.chars().all(|c| c == '_' || c.is_ascii_alphanumeric())
286286
}

godot-codegen/src/conv/type_conversions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn to_hardcoded_rust_enum(ty: &str) -> Option<&str> {
8282
Some(result)
8383
}
8484

85-
/// Maps an input type to a Godot type with the same C representation. This is subtly different than [`to_rust_type`],
85+
/// Maps an input type to a Godot type with the same C representation. This is subtly different from [`to_rust_type`],
8686
/// which maps to an appropriate corresponding Rust type. This function should be used in situations where the C ABI for
8787
/// a type must match the Godot equivalent exactly, such as when dealing with pointers.
8888
pub(crate) fn to_rust_type_abi(ty: &str, ctx: &mut Context) -> (RustTy, bool) {
@@ -105,7 +105,7 @@ pub(crate) fn to_rust_type_abi(ty: &str, ctx: &mut Context) -> (RustTy, bool) {
105105
(ty, is_obj)
106106
}
107107

108-
/// Maps an _input_ type from the Godot JSON to the corresponding Rust type (wrapping some sort of a token stream).
108+
/// Maps an _input_ type from the Godot JSON to the corresponding Rust type (wrapping some sort of token stream).
109109
///
110110
/// Uses an internal cache (via `ctx`), as several types are ubiquitous.
111111
// TODO take TyName as input
@@ -401,7 +401,7 @@ fn to_rust_expr_inner(expr: &str, ty: &RustTy, is_inner: bool) -> TokenStream {
401401
}
402402

403403
fn suffixed_lit(num: impl fmt::Display, suffix: &Ident) -> TokenStream {
404-
// i32, u16 etc happens to be also the literal suffix
404+
// i32, u16 etc. happen to be also the literal suffixes
405405
let combined = format!("{num}{suffix}");
406406
combined
407407
.parse::<Literal>()

godot-codegen/src/formatter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use proc_macro2::{Delimiter, Spacing, TokenStream, TokenTree};
4545
/// after the `,` but because this only looks at one TokenKind at a time
4646
/// and only keeps a single state, it's too much effort to keep track of which
4747
/// `,` in a [`TokenTree`] should trigger a newline (it would involve a stack
48-
/// of infos whether that group is in a match or not, detecting pattern etc)
48+
/// of infos whether that group is in a match or not, detecting pattern etc.)
4949
/// - Because `,` can be used for function args (no-newline) and separators
5050
/// in `struct` and `enum` definitons, those definitions are more awkward
5151
/// and crammed into one line as a trade-off to make function calls and args

godot-codegen/src/generator/default_parameters.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn make_function_definition_with_defaults(
5959
// #[allow] exceptions:
6060
// - wrong_self_convention: to_*() and from_*() are taken from Godot
6161
// - redundant_field_names: 'value: value' is a possible initialization pattern
62-
// - needless-update: '..self' has nothing left to change
62+
// - needless-update: Remainder expression '..self' has nothing left to change
6363
let builders = quote! {
6464
#[doc = #builder_doc]
6565
#[must_use]
@@ -191,10 +191,8 @@ fn make_extender_receiver(sig: &dyn Function) -> ExtenderReceiver {
191191
ExtenderReceiver {
192192
object_fn_param: Some(FnParam {
193193
name: ident("surround_object"),
194-
// Not exactly EngineClass, but close enough
195-
type_: RustTy::EngineClass {
194+
type_: RustTy::ExtenderReceiver {
196195
tokens: quote! { &'a #builder_mut re_export::#class },
197-
inner_class: ident("unknown"),
198196
},
199197
default_value: None,
200198
}),

godot-codegen/src/generator/enums.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ fn make_enum_engine_trait_impl(enum_: &Enum) -> TokenStream {
258258

259259
/// Creates implementations for bitwise operators for the given enum.
260260
///
261-
/// Currently this is just [`BitOr`](std::ops::BitOr) for bitfields but that could be expanded in the future.
261+
/// Currently, this is just [`BitOr`](std::ops::BitOr) for bitfields but that could be expanded in the future.
262262
fn make_enum_bitwise_operators(enum_: &Enum) -> TokenStream {
263263
let name = &enum_.name;
264264

@@ -278,7 +278,7 @@ fn make_enum_bitwise_operators(enum_: &Enum) -> TokenStream {
278278
}
279279
/// Returns the documentation for the given enum.
280280
///
281-
/// Each string is one line of documentation, usually this needs to be wrapped in a `#[doc = ..]`.
281+
/// Each string is one line of documentation, usually this needs to be wrapped in a `#[doc = ...]`.
282282
fn make_enum_doc(enum_: &Enum) -> Vec<String> {
283283
let mut docs = Vec::new();
284284

godot-codegen/src/generator/native_structures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ pub(crate) fn parse_native_structures_format(input: &str) -> Option<Vec<NativeSt
263263
}
264264

265265
// If the field is an array, store array size separately.
266-
// Not part of type because fixed-size arrays are not a concept in the JSON outside of native structures.
266+
// Not part of type because fixed-size arrays are not a concept in the JSON outside native structures.
267267
let mut array_size = None;
268268
if let Some(index) = field_name.find('[') {
269269
array_size = Some(field_name[index + 1..field_name.len() - 1].parse().ok()?);

godot-codegen/src/generator/virtual_traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn make_special_virtual_methods(notification_enum_name: &Ident) -> TokenStream {
127127
/// function will usually be called twice by Godot to find the revert.
128128
///
129129
/// Note that this should be a _pure_ function. That is, it should always return the same value for a property as long as `self`
130-
/// remains unchanged. Otherwise this may lead to unexpected (safe) behavior.
130+
/// remains unchanged. Otherwise, this may lead to unexpected (safe) behavior.
131131
///
132132
/// [`Object::_property_get_revert`]: https://docs.godotengine.org/en/latest/classes/class_object.html#class-object-private-method-property-get-revert
133133
/// [`Object::_property_can_revert`]: https://docs.godotengine.org/en/latest/classes/class_object.html#class-object-private-method-property-can-revert

godot-codegen/src/models/domain.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,11 @@ impl FnQualifier {
473473

474474
pub struct FnParam {
475475
pub name: Ident,
476+
477+
/// Type, as it appears in `type CallSig` tuple definition.
476478
pub type_: RustTy,
479+
480+
/// Rust expression for default value, if available.
477481
pub default_value: Option<TokenStream>,
478482
}
479483

@@ -573,15 +577,6 @@ pub struct GodotTy {
573577
pub meta: Option<String>,
574578
}
575579

576-
// impl GodotTy {
577-
// fn new<'a>(ty: &'a String, meta: &'a Option<String>) -> Self {
578-
// Self {
579-
// ty: ty.clone(),
580-
// meta: meta.clone(),
581-
// }
582-
// }
583-
// }
584-
585580
// ----------------------------------------------------------------------------------------------------------------------------------------------
586581
// Rust type
587582

@@ -627,6 +622,9 @@ pub enum RustTy {
627622
#[allow(dead_code)] // only read in minimal config
628623
inner_class: Ident,
629624
},
625+
626+
/// Receiver type of default parameters extender constructor.
627+
ExtenderReceiver { tokens: TokenStream },
630628
}
631629

632630
impl RustTy {
@@ -655,6 +653,7 @@ impl ToTokens for RustTy {
655653
RustTy::EngineEnum { tokens: path, .. } => path.to_tokens(tokens),
656654
RustTy::EngineBitfield { tokens: path, .. } => path.to_tokens(tokens),
657655
RustTy::EngineClass { tokens: path, .. } => path.to_tokens(tokens),
656+
RustTy::ExtenderReceiver { tokens: path } => path.to_tokens(tokens),
658657
}
659658
}
660659
}

godot-codegen/src/models/domain_mapping.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl BuiltinMethod {
353353
name: method.name.clone(),
354354
godot_name: method.name.clone(),
355355
// Disable default parameters for builtin classes.
356-
// They are not public-facing and need more involved implementation (lifetimes etc). Also reduces number of symbols in API.
356+
// They are not public-facing and need more involved implementation (lifetimes etc.). Also reduces number of symbols in API.
357357
parameters: FnParam::new_range_no_defaults(&method.arguments, ctx),
358358
return_value: FnReturn::new(&return_value, ctx),
359359
is_vararg: method.is_vararg,

godot-codegen/src/special_cases/codegen_special_cases.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ fn is_type_excluded(ty: &str, ctx: &mut Context) -> bool {
5353
Some(class) => is_class_excluded(class.as_str()),
5454
},
5555
RustTy::EngineClass { inner_class, .. } => is_class_excluded(&inner_class.to_string()),
56+
RustTy::ExtenderReceiver { .. } => false,
5657
}
5758
}
5859
is_rust_type_excluded(&conv::to_rust_type(ty, None, ctx))
@@ -69,7 +70,7 @@ pub(crate) fn is_class_method_excluded(method: &JsonClassMethod, ctx: &mut Conte
6970
// so passing in a class name while checking for any types is fine.
7071
let class_deleted = special_cases::is_godot_type_deleted(ty);
7172

72-
// Then also check if the type is excluded from codegen (due to current Cargo feature. RHS is always false in full-codegen.
73+
// Then also check if the type is excluded from codegen (due to current Cargo feature). RHS is always false in full-codegen.
7374
class_deleted || is_type_excluded(ty, _ctx)
7475
};
7576

godot-core/src/builtin/callable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use sys::{ffi_methods, GodotFfi};
2222
/// also be a custom callable, which is usually created from `bind`, `unbind`, or a GDScript lambda. See
2323
/// [`Callable::is_custom`].
2424
///
25-
/// Currently it is impossible to use `bind` and `unbind` in GDExtension, see [godot-cpp#802].
25+
/// Currently, it is impossible to use `bind` and `unbind` in GDExtension, see [godot-cpp#802].
2626
///
2727
/// [godot-cpp#802]: https://github.com/godotengine/godot-cpp/issues/802
2828
pub struct Callable {
@@ -145,7 +145,7 @@ impl Callable {
145145
}
146146
}
147147

148-
/// Creates an invalid/empty object that is not able to be called.
148+
/// Creates an invalid/empty object that cannot be called.
149149
///
150150
/// _Godot equivalent: `Callable()`_
151151
pub fn invalid() -> Self {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<T: ArrayElement> Array<T> {
702702
/// This has the same safety issues as doing `self.assume_type::<Variant>()` and so the relevant safety invariants from
703703
/// [`assume_type`](Self::assume_type) must be upheld.
704704
///
705-
/// In particular this means that all reads are fine, since all values can be converted to `Variant`. However writes are only ok
705+
/// In particular this means that all reads are fine, since all values can be converted to `Variant`. However, writes are only OK
706706
/// if they match the type `T`.
707707
#[doc(hidden)]
708708
pub unsafe fn as_inner_mut(&self) -> inner::InnerArray {
@@ -1077,7 +1077,7 @@ impl<T: ArrayElement + ToGodot> FromIterator<T> for Array<T> {
10771077
impl<T: ArrayElement + ToGodot> Extend<T> for Array<T> {
10781078
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
10791079
// Unfortunately the GDExtension API does not offer the equivalent of `Vec::reserve`.
1080-
// Otherwise we could use it to pre-allocate based on `iter.size_hint()`.
1080+
// Otherwise, we could use it to pre-allocate based on `iter.size_hint()`.
10811081
//
10821082
// A faster implementation using `resize()` and direct pointer writes might still be
10831083
// possible.
@@ -1122,7 +1122,7 @@ impl<'a, T: ArrayElement + FromGodot> Iterator for Iter<'a, T> {
11221122
let element_ptr = self.array.ptr_or_null(idx);
11231123

11241124
// SAFETY: We just checked that the index is not out of bounds, so the pointer won't be null.
1125-
// We immediately convert this to the right element, so barring `experimental-threads` the pointer wont be invalidated in time.
1125+
// We immediately convert this to the right element, so barring `experimental-threads` the pointer won't be invalidated in time.
11261126
let variant = unsafe { Variant::borrow_var_sys(element_ptr) };
11271127
let element = T::from_variant(variant);
11281128
Some(element)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ impl Dictionary {
333333

334334
// SAFETY:
335335
// - `move_return_ptr`
336-
// Nothing special needs to be done beyond a `std::mem::swap` when returning an Dictionary.
336+
// Nothing special needs to be done beyond a `std::mem::swap` when returning a Dictionary.
337337
// So we can just use `ffi_methods`.
338338
//
339339
// - `from_arg_ptr`

0 commit comments

Comments
 (0)