Skip to content

Commit f8823ac

Browse files
niko091viferga
andauthored
Refactor: Resolve all clippy warnings in rs_loader (#687)
* Refactor: Resolve all clippy warnings in rs_loader * Build: Add Clippy as a pre-build CMake target for CI * Update CMakeLists.txt --------- Co-authored-by: Vicente Eduardo Ferrer Garcia <7854099+viferga@users.noreply.github.com>
1 parent c0b0557 commit f8823ac

File tree

22 files changed

+1966
-1991
lines changed

22 files changed

+1966
-1991
lines changed

source/loaders/rs_loader/rust/compiler/src/api/class.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,12 @@ extern "C" fn class_singleton_static_invoke(
9292
.expect("Unable to get method name");
9393
let ret = class.call(name, args);
9494
std::mem::forget(class);
95-
std::mem::forget(name);
9695
ret
9796
};
9897
if let Ok(ret) = ret {
99-
return ret;
98+
ret
10099
} else {
101-
return 0 as OpaqueType;
100+
0 as OpaqueType
102101
}
103102
}
104103

@@ -116,12 +115,10 @@ extern "C" fn class_singleton_static_await(
116115

117116
#[no_mangle]
118117
extern "C" fn class_singleton_destroy(_klass: OpaqueType, class_impl: OpaqueType) {
119-
if !rs_loader_destroyed() {
120-
if !class_impl.is_null() {
121-
unsafe {
122-
let class = Box::from_raw(class_impl as *mut class::Class);
123-
drop(class);
124-
}
118+
if !rs_loader_destroyed() && !class_impl.is_null() {
119+
unsafe {
120+
let class = Box::from_raw(class_impl as *mut class::Class);
121+
drop(class);
125122
}
126123
}
127124
}
@@ -239,10 +236,8 @@ pub fn register_class(class_registration: ClassRegistration) {
239236
loader_impl_type(class_registration.loader_impl, ret.as_ptr()),
240237
);
241238
};
242-
}
243-
else {
244-
let ret = CString::new("Null")
245-
.expect("Failed to convert return type to C string");
239+
} else {
240+
let ret = CString::new("Null").expect("Failed to convert return type to C string");
246241

247242
unsafe {
248243
signature_set_return(
@@ -294,10 +289,8 @@ pub fn register_class(class_registration: ClassRegistration) {
294289
loader_impl_type(class_registration.loader_impl, ret.as_ptr()),
295290
);
296291
};
297-
}
298-
else {
299-
let ret = CString::new("Null")
300-
.expect("Failed to convert return type to C string");
292+
} else {
293+
let ret = CString::new("Null").expect("Failed to convert return type to C string");
301294

302295
unsafe {
303296
signature_set_return(

source/loaders/rs_loader/rust/compiler/src/api/function.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,12 @@ extern "C" fn function_singleton_await(
5454
0 as OpaqueType
5555
}
5656

57-
5857
#[no_mangle]
5958
extern "C" fn function_singleton_destroy(_func: OpaqueType, func_impl: OpaqueType) {
60-
if !rs_loader_destroyed() {
61-
if !func_impl.is_null() {
62-
unsafe {
63-
let func_ptr = Box::from_raw(func_impl as *mut class::Function);
64-
drop(func_ptr);
65-
}
59+
if !rs_loader_destroyed() && !func_impl.is_null() {
60+
unsafe {
61+
let func_ptr = Box::from_raw(func_impl as *mut class::Function);
62+
drop(func_ptr);
6663
}
6764
}
6865
}

source/loaders/rs_loader/rust/compiler/src/api/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ extern "C" {
121121
}
122122

123123
pub fn get_loader_lifecycle_state(loader_impl: OpaqueType) -> *mut LoaderLifecycleState {
124-
let loader_lifecycle_state =
125-
unsafe { loader_impl_get(loader_impl) } as *mut LoaderLifecycleState;
126-
127-
loader_lifecycle_state
124+
(unsafe { loader_impl_get(loader_impl) }) as *mut LoaderLifecycleState
128125
}
129126

130127
static mut RS_LOADER_PTR: *mut c_void = std::ptr::null_mut();
@@ -142,7 +139,9 @@ pub fn loader_lifecycle_register(loader_impl: OpaqueType) {
142139
}
143140

144141
pub fn loader_lifecycle_unload_children(loader_impl: OpaqueType) {
145-
unsafe { loader_unload_children(loader_impl); }
142+
unsafe {
143+
loader_unload_children(loader_impl);
144+
}
146145
}
147146

148147
pub enum PrimitiveMetacallProtocolTypes {
@@ -182,7 +181,5 @@ pub fn define_type(
182181
}
183182

184183
pub fn rs_loader_destroyed() -> bool {
185-
unsafe {
186-
loader_is_destroyed(RS_LOADER_PTR) == 0
187-
}
184+
unsafe { loader_is_destroyed(RS_LOADER_PTR) == 0 }
188185
}

0 commit comments

Comments
 (0)