Skip to content

Commit 24faac5

Browse files
committed
Fix Clippy warnings and UI tests
1 parent 7ab3178 commit 24faac5

File tree

11 files changed

+24
-24
lines changed

11 files changed

+24
-24
lines changed

bindings-generator/src/api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl core::cmp::Ord for Enum {
178178

179179
impl core::cmp::PartialOrd for Enum {
180180
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
181-
core::cmp::PartialOrd::partial_cmp(&self.name, &other.name)
181+
Some(self.cmp(other))
182182
}
183183
}
184184

gdnative-async/src/method.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ impl<'a, C: NativeClass, A> Spawner<'a, C, A> {
157157
/// Consumes this `Spawner` and spawns a future returned by the closure. This indirection
158158
/// is necessary so that implementors of the `AsyncMethod` trait do not have to name their
159159
/// future types.
160+
#[allow(clippy::arc_with_non_send_sync)] // Stability concerns: part of public API
160161
pub fn spawn<F, R>(self, f: F)
161162
where
162163
F: FnOnce(Arc<Context>, TInstance<'_, C>, A) -> R,

gdnative-bindings/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![allow(non_snake_case)]
55
#![allow(unused_unsafe)]
66
// False positives on generated drops that enforce lifetime
7-
#![allow(clippy::drop_copy)]
7+
#![allow(dropping_copy_types)]
88
// False positives on thread-safe singletons
99
#![allow(clippy::non_send_fields_in_send_ty)]
1010
// Disable non-critical lints for generated code

gdnative-core/src/export/class_registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ pub(crate) fn types_with_init_level(allow: InitLevel, deny: InitLevel) -> Vec<Co
9090
let registry = CLASS_REGISTRY.read();
9191
let mut list = registry
9292
.values()
93-
.filter_map(|class_info| {
94-
(class_info.init_level.intersects(allow) && !class_info.init_level.intersects(deny))
95-
.then(|| class_info.name.clone())
93+
.filter(|class_info| {
94+
class_info.init_level.intersects(allow) && !class_info.init_level.intersects(deny)
9695
})
96+
.map(|class_info| class_info.name.clone())
9797
.collect::<Vec<_>>();
9898

9999
list.sort_unstable();

gdnative-core/src/export/emplace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn take<T: NativeClass>() -> Option<T> {
4242
Err(any) => panic!(
4343
"expecting {} in the emplacement cell, got {:?} (this is a bug in the bindings)",
4444
class_registry::class_name_or_default::<T>(),
45-
any.type_id(),
45+
(*any).type_id(),
4646
),
4747
})
4848
}

gdnative-core/src/object/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ impl<T: GodotObject, Own: Ownership> Ord for Ref<T, Own> {
724724
impl<T: GodotObject, Own: Ownership> PartialOrd for Ref<T, Own> {
725725
#[inline]
726726
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
727-
self.ptr.as_non_null().partial_cmp(&other.ptr.as_non_null())
727+
Some(self.cmp(other))
728728
}
729729
}
730730

@@ -863,7 +863,7 @@ impl<'a, T: GodotObject, Own: Ownership> Copy for TRef<'a, T, Own> {}
863863
impl<'a, T: GodotObject, Own: Ownership> Clone for TRef<'a, T, Own> {
864864
#[inline]
865865
fn clone(&self) -> Self {
866-
TRef::new(self.obj)
866+
*self
867867
}
868868
}
869869

gdnative-core/src/object/raw.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl<T: GodotObject> RawObject<T> {
7070
pub fn class_name(&self) -> String {
7171
let api = crate::private::get_api();
7272
let get_class_method = crate::private::ObjectMethodTable::get(api).get_class;
73-
let mut argument_buffer = [ptr::null() as *const libc::c_void; 0];
73+
let mut argument_buffer: [*const libc::c_void; 0] = [];
7474
let mut class_name = sys::godot_string::default();
7575
let ret_ptr = &mut class_name as *mut sys::godot_string;
7676

@@ -127,7 +127,7 @@ impl<T: GodotObject<Memory = RefCounted>> RawObject<T> {
127127
pub fn add_ref(&self) {
128128
let api = crate::private::get_api();
129129
let addref_method = crate::private::ReferenceMethodTable::get(api).reference;
130-
let mut argument_buffer = [ptr::null() as *const libc::c_void; 0];
130+
let mut argument_buffer: [*const libc::c_void; 0] = [];
131131
let mut ok = false;
132132
let ok_ptr = &mut ok as *mut bool;
133133

@@ -158,7 +158,7 @@ impl<T: GodotObject<Memory = RefCounted>> RawObject<T> {
158158
let api = crate::private::get_api();
159159
let unref_method = crate::private::ReferenceMethodTable::get(api).unreference;
160160

161-
let mut argument_buffer = [ptr::null() as *const libc::c_void; 0];
161+
let mut argument_buffer: [*const libc::c_void; 0] = [];
162162
let mut last_reference = false;
163163
let ret_ptr = &mut last_reference as *mut bool;
164164
(api.godot_method_bind_ptrcall)(
@@ -201,7 +201,7 @@ impl<T: GodotObject<Memory = RefCounted>> RawObject<T> {
201201
let api = crate::private::get_api();
202202
let init_method = crate::private::ReferenceMethodTable::get(api).init_ref;
203203

204-
let mut argument_buffer = [ptr::null() as *const libc::c_void; 0];
204+
let mut argument_buffer: [*const libc::c_void; 0] = [];
205205
let mut ok = false;
206206
let ret_ptr = &mut ok as *mut bool;
207207
(api.godot_method_bind_ptrcall)(
@@ -237,7 +237,7 @@ unsafe fn ptr_is_class(obj: *mut sys::godot_object, class_name: &str) -> bool {
237237
class_name.len() as _,
238238
);
239239

240-
let mut argument_buffer = [ptr::null() as *const libc::c_void; 1];
240+
let mut argument_buffer: [*const libc::c_void; 1] = [ptr::null(); 1];
241241
argument_buffer[0] = (&class_name) as *const _ as *const _;
242242

243243
let mut ret = false;

gdnative-derive/src/methods.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,7 @@ fn impl_gdnative_expose(ast: ItemImpl) -> (ItemImpl, ClassMethodExport) {
568568

569569
if is_export {
570570
use syn::{punctuated::Punctuated, Lit};
571-
let mut export_args =
572-
export_args.get_or_insert_with(ExportArgs::default);
571+
let export_args = export_args.get_or_insert_with(ExportArgs::default);
573572
export_args.is_old_syntax = is_old_syntax;
574573

575574
// Codes like #[macro(path, name = "value")] are accepted.

gdnative/tests/ui/derive_fail_methods_special_args.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ impl Foo {
1111
}
1212

1313
#[method]
14-
async fn optional(#[opt] self, #[base] #[opt] _base: &Node, #[async_ctx] #[opt] ctx: ()) {}
14+
async fn optional(#[opt] self, #[base] #[opt] _base: &Node, #[async_ctx] #[opt] _ctx: ()) {}
1515

1616
#[method]
1717
fn based(#[base] self, #[base] _base: &Node, #[base] #[base] _basil: &Node, #[base] #[base] #[base] _basin: &Node) {}
1818

1919
#[method]
20-
fn sync(self, #[async_ctx] ctx: ()) {}
20+
fn sync(self, #[async_ctx] _ctx: ()) {}
2121
}
2222

2323
fn main() {}

gdnative/tests/ui/derive_fail_methods_special_args.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
error: the method receiver cannot be optional (instead, remove the argument entirely)
22
--> tests/ui/derive_fail_methods_special_args.rs:14:25
33
|
4-
14 | async fn optional(#[opt] self, #[base] #[opt] _base: &Node, #[async_ctx] #[opt] ctx: ()) {}
4+
14 | async fn optional(#[opt] self, #[base] #[opt] _base: &Node, #[async_ctx] #[opt] _ctx: ()) {}
55
| ^^^
66

77
error: the base/owner object cannot be optional (instead, remove the argument entirely)
88
--> tests/ui/derive_fail_methods_special_args.rs:14:46
99
|
10-
14 | async fn optional(#[opt] self, #[base] #[opt] _base: &Node, #[async_ctx] #[opt] ctx: ()) {}
10+
14 | async fn optional(#[opt] self, #[base] #[opt] _base: &Node, #[async_ctx] #[opt] _ctx: ()) {}
1111
| ^^^
1212

1313
error: the async context cannot be optional (instead, remove the argument entirely)
1414
--> tests/ui/derive_fail_methods_special_args.rs:14:80
1515
|
16-
14 | async fn optional(#[opt] self, #[base] #[opt] _base: &Node, #[async_ctx] #[opt] ctx: ()) {}
16+
14 | async fn optional(#[opt] self, #[base] #[opt] _base: &Node, #[async_ctx] #[opt] _ctx: ()) {}
1717
| ^^^
1818

1919
error: the method receiver cannot also be the base/owner object
@@ -55,5 +55,5 @@ error: the special parameter base/owner object must only be declared once (the s
5555
error: the async context is only available to async methods
5656
--> tests/ui/derive_fail_methods_special_args.rs:20:32
5757
|
58-
20 | fn sync(self, #[async_ctx] ctx: ()) {}
59-
| ^^^
58+
20 | fn sync(self, #[async_ctx] _ctx: ()) {}
59+
| ^^^^

0 commit comments

Comments
 (0)