Skip to content

Commit 6effb3e

Browse files
bors[bot]Bromeon
andauthored
Merge #793
793: Fix clippy lints in nightly r=Bromeon a=Bromeon Where "fix" means mostly "disable". Lints turned off globally for the time being (might change in the future): * `clippy::missing_safety_doc` -- requires each unsafe fn/trait to have a `# Safety` section. Nice in theory, annoying for internals, and boilerplate-enforcing for obvious public cases. * `clippy::if_then_panic` -- suggests that `if (!cond) { panic!(msg); }` be written as `assert!(cond, msg);` Probably makes sense to enable later, but currently not possible due to [approx/#73](brendanzab/approx#73). Lints turned of locally: * `clippy::redundant_closure` -- works around false positive [rust-clippy/#7812](rust-lang/rust-clippy#7812) * `dead_code` (compiler warning, not clippy) -- generated field `this` not always used. Naming it `_this` doesn't seem right, either. Co-authored-by: Jan Haller <bromeon@gmail.com>
2 parents ef7e096 + ac14a39 commit 6effb3e

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

bindings_generator/src/classes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ use std::collections::HashMap;
1212
pub(crate) fn generate_class_struct(class: &GodotClass) -> TokenStream {
1313
let class_name = format_ident!("{}", &class.name);
1414

15+
// dead_code: 'this' might not be read
1516
quote! {
1617
#[allow(non_camel_case_types)]
1718
#[derive(Debug)]
1819
pub struct #class_name {
20+
#[allow(dead_code)]
1921
this: RawObject<Self>,
2022
}
2123
}

gdnative-core/src/core_types/dictionary.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,11 @@ godot_test!(test_dictionary {
625625
let expected_keys = ["foo", "bar"].iter().map(|&s| s.to_string()).collect::<HashSet<_>>();
626626
for (key, value) in &dict {
627627
assert_eq!(Some(value), dict.get(&key));
628-
if !iter_keys.insert(key.to_string()) {
629-
panic!("key is already contained in set: {:?}", key);
630-
}
628+
assert!(
629+
iter_keys.insert(key.to_string()) ,
630+
"key is already contained in set: {:?}",
631+
key
632+
);
631633
}
632634
assert_eq!(expected_keys, iter_keys);
633635
});

gdnative-core/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
//! [thread-safety]: https://docs.godotengine.org/en/stable/tutorials/threads/thread_safe_apis.html
2121
2222
#![deny(clippy::missing_inline_in_public_items)]
23-
#![allow(clippy::transmute_ptr_to_ptr)]
23+
#![allow(
24+
clippy::transmute_ptr_to_ptr,
25+
clippy::missing_safety_doc,
26+
clippy::if_then_panic
27+
)]
2428
#![cfg_attr(feature = "gd_test", allow(clippy::blacklisted_name))]
2529

2630
#[doc(hidden)]

gdnative-core/src/private.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ unsafe fn check_api_compatibility(
7979
/// not bound will lead to an abort**, since in most cases there is simply no point to continue
8080
/// if `get_api` failed. This allows it to be used in FFI contexts without a `catch_unwind`.
8181
#[inline]
82+
#[allow(clippy::redundant_closure)] // clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7812
8283
pub fn get_api() -> &'static sys::GodotApi {
8384
unsafe { GODOT_API.as_ref().unwrap_or_else(|| std::process::abort()) }
8485
}

gdnative-sys/build.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ mod header_binding {
6464
// and have been erroneously used for target platforms in this library in the past. Make sure
6565
// to double-check them wherever they occur.
6666

67-
if !cfg!(target_arch = "x86_64") {
68-
panic!("unsupported host architecture: build from x86_64 instead");
69-
}
67+
assert!(
68+
cfg!(target_arch = "x86_64"),
69+
"unsupported host architecture: build from x86_64 instead"
70+
);
7071

7172
builder = builder
7273
.clang_arg("-I")
@@ -457,9 +458,10 @@ mod api_wrapper {
457458

458459
for api in api_root.all_apis() {
459460
// Currently don't support Godot 4.0
460-
if api.version.major == 1 && api.version.minor == 3 {
461-
panic!("GodotEngine v4.* is not yet supported. See https://github.com/godot-rust/godot-rust/issues/396");
462-
}
461+
assert!(
462+
!(api.version.major == 1 && api.version.minor == 3),
463+
"GodotEngine v4.* is not yet supported. See https://github.com/godot-rust/godot-rust/issues/396"
464+
);
463465
}
464466

465467
let struct_fields = godot_api_functions(&api_root);

test/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::blacklisted_name)]
1+
#![allow(clippy::blacklisted_name, clippy::if_then_panic)]
22

33
use gdnative::prelude::*;
44

0 commit comments

Comments
 (0)