Skip to content

Commit f6ffe1e

Browse files
committed
misc: Do a lot of code cleanup
1 parent e65819b commit f6ffe1e

File tree

45 files changed

+231
-406
lines changed

Some content is hidden

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

45 files changed

+231
-406
lines changed

engine/libs/argus_util/src/math/vector.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ macro_rules! create_vector2_ops {
2727
}
2828
}
2929

30-
impl Into<[$el_type; 2]> for $vec_type {
31-
fn into(self) -> [$el_type; 2] {
32-
[self.x, self.y]
30+
impl From<$vec_type> for [$el_type; 2] {
31+
fn from(v: $vec_type) -> Self {
32+
[v.x, v.y]
3333
}
3434
}
3535

@@ -222,9 +222,9 @@ macro_rules! create_vector2_signed_ops {
222222

223223
macro_rules! create_vector3_ops {
224224
($vec_type: ty, $el_type: ty) => {
225-
impl Into<[$el_type; 3]> for $vec_type {
226-
fn into(self) -> [$el_type; 3] {
227-
[self.x, self.y, self.z]
225+
impl From<$vec_type> for [$el_type; 3] {
226+
fn from(v: $vec_type) -> Self {
227+
[v.x, v.y, v.z]
228228
}
229229
}
230230

@@ -347,9 +347,9 @@ macro_rules! create_vector3_signed_ops {
347347

348348
macro_rules! create_vector4_ops {
349349
($vec_type: ty, $el_type: ty) => {
350-
impl Into<[$el_type; 4]> for $vec_type {
351-
fn into(self) -> [$el_type; 4] {
352-
[self.x, self.y, self.z, self.w]
350+
impl From<$vec_type> for [$el_type; 4] {
351+
fn from(v: $vec_type) -> Self {
352+
[v.x, v.y, v.z, v.w]
353353
}
354354
}
355355

engine/libs/argus_util/src/semaphore.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ struct SemaphoreInner {
1212
}
1313

1414
impl Semaphore {
15-
fn new() -> Self {
16-
Self {
17-
inner: Arc::new(SemaphoreInner {
18-
mutex: Mutex::new(false),
19-
cv: Condvar::new(),
20-
}),
21-
}
22-
}
23-
2415
pub fn is_signaled(&self) -> bool {
2516
*self.inner.mutex.lock().unwrap()
2617
}

engine/libs/build_util/src/rerun.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn did_file_change(path: &Path, timestamp_file: &Path) -> bool {
3333
if !path.exists() {
3434
panic!(
3535
"No file exists at path {}",
36-
path.to_string_lossy().to_string()
36+
path.to_string_lossy()
3737
);
3838
}
3939

@@ -54,7 +54,7 @@ fn did_file_change(path: &Path, timestamp_file: &Path) -> bool {
5454
),
5555
};
5656

57-
let prev_modified_time = match fs::metadata(&timestamp_file).and_then(|meta| meta.modified()) {
57+
let prev_modified_time = match fs::metadata(timestamp_file).and_then(|meta| meta.modified()) {
5858
Ok(modified_time) => modified_time,
5959
Err(e) => panic!(
6060
"Failed to read metadata of timestamp file at path {} ({e})",

engine/libs/build_util/src/resource.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::{env, fs};
2-
use std::path::{Path, PathBuf};
3-
use arp::{create_arp_from_fs, CompressionType, PackingOptions};
41
use crate::rerun::run_if_changed;
2+
use arp::{create_arp_from_fs, CompressionType, PackingOptions};
3+
use std::path::PathBuf;
4+
use std::{env, fs};
55

66
const RES_MAPPINGS_PATH: &str = "../../../res/arp_custom_mappings.csv";
77

engine/libs/logging/src/manager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct LogManager {
2323

2424
impl LogManager {
2525
pub fn instance() -> &'static Self {
26-
&MANAGER.get().unwrap()
26+
MANAGER.get().unwrap()
2727
}
2828

2929
pub fn initialize(settings: LogSettings) -> Result<(), ()> {
@@ -191,7 +191,7 @@ fn emit_log_entry(mgr: &LogManager, message: StagedMessage) {
191191
.collect::<Vec<_>>()
192192
.join(" ");
193193

194-
let final_msg = if prelude.len() > 0 {
194+
let final_msg = if !prelude.is_empty() {
195195
format!("{} {}\n", prelude, message.message)
196196
} else {
197197
format!("{}\n", message.message)

engine/libs/scripting_bind_macros/src/lib.rs

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub fn script_bind(args: TokenStream, input: TokenStream) -> TokenStream {
6565
if meta_list.iter().any(|meta| match meta {
6666
Meta::Path(path) => {
6767
path.segments.len() == 1 &&
68-
path.segments.first().unwrap().ident.to_string() == UNIV_ARG_IGNORE
68+
path.segments.first().unwrap().ident == UNIV_ARG_IGNORE
6969
}
7070
_ => false,
7171
}) {
@@ -287,6 +287,7 @@ fn handle_struct(item: &ItemStruct, args: Vec<&Meta>) -> Result<TokenStream2, Co
287287
name: #field_name,
288288
type_serial: #field_type_serial,
289289
size: size_of::<#field_type>(),
290+
#[allow(clippy::clone_on_copy, clippy::needless_borrow)]
290291
accessor: #field_accessor_tokens,
291292
#[allow(clippy::clone_on_copy, clippy::needless_borrow)]
292293
mutator: #field_mutator_tokens,
@@ -301,7 +302,6 @@ fn handle_struct(item: &ItemStruct, args: Vec<&Meta>) -> Result<TokenStream2, Co
301302
Ok(quote! {
302303
#item
303304
const _: () = {
304-
use ::argus_scripting_bind::Wrappable;
305305
#ctor_dtor_proxies_tokens
306306
#script_bound_impl_tokens
307307
#wrappable_impl_tokens
@@ -313,7 +313,6 @@ fn handle_struct(item: &ItemStruct, args: Vec<&Meta>) -> Result<TokenStream2, Co
313313
Ok(quote! {
314314
#item
315315
const _: () = {
316-
use ::argus_scripting_bind::Wrappable;
317316
#script_bound_impl_tokens
318317
#register_struct_tokens
319318
#(#field_regs)*
@@ -483,7 +482,6 @@ fn handle_enum(item: &ItemEnum, args: Vec<&Meta>) -> Result<TokenStream2, Compil
483482
Ok(quote! {
484483
#item
485484
const _: () = {
486-
use ::argus_scripting_bind::Wrappable;
487485
#script_bound_impl_tokens
488486
#wrappable_impl_tokens
489487
const _: () = {
@@ -632,9 +630,9 @@ fn gen_fn_binding_code(
632630
Type::Path(assoc_type.expect("Associated type was missing").clone());
633631
match &self_type.reference {
634632
Some((and_token, lifetime)) => Ok(Type::Reference(TypeReference {
635-
and_token: and_token.clone(),
633+
and_token: *and_token,
636634
lifetime: lifetime.clone(),
637-
mutability: self_type.mutability.clone(),
635+
mutability: self_type.mutability,
638636
elem: Box::new(assoc_type_path),
639637
})),
640638
None => Ok(assoc_type_path),
@@ -649,7 +647,7 @@ fn gen_fn_binding_code(
649647
Vec<(ObjectType, Vec<Type>)> =
650648
param_types.iter()
651649
.map(|ty| {
652-
parse_type(&ty, ValueFlowDirection::FromScript)
650+
parse_type(ty, ValueFlowDirection::FromScript)
653651
})
654652
.collect::<Result<_, _>>()?;
655653

@@ -684,7 +682,7 @@ fn gen_fn_binding_code(
684682
for i in 0..param_obj_types.len() {
685683
let syn_type = &param_types[i];
686684
let param_type_tokens: TokenStream2;
687-
let boxed_trait_obj_opt = try_as_boxed_trait_object(&syn_type);
685+
let boxed_trait_obj_opt = try_as_boxed_trait_object(syn_type);
688686
if let Some(trait_obj) = boxed_trait_obj_opt {
689687
//TODO: only allow 1 bound (?)
690688
let Some(paren_args) = trait_obj.bounds.iter().find_map(|bound| match bound {
@@ -1052,9 +1050,9 @@ fn handle_impl(impl_block: &ItemImpl, _args: Vec<&Meta>) -> Result<TokenStream2,
10521050
if let Some(pos) = f.attrs.iter().position(|attr| {
10531051
if attr.path().segments.len() != 1 { return false; }
10541052
let seg = attr.path().segments.first().expect("First path segment was missing");
1055-
seg.ident.to_string() == ATTR_SCRIPT_BIND
1053+
seg.ident == ATTR_SCRIPT_BIND
10561054
}) {
1057-
fns_to_bind.push((&f, f.attrs[pos].meta.clone()));
1055+
fns_to_bind.push((f, f.attrs[pos].meta.clone()));
10581056
let mut f_clone = f.clone();
10591057
// remove script_bind attribute since it's being handled as
10601058
// part of the impl block
@@ -1117,7 +1115,7 @@ fn handle_impl(impl_block: &ItemImpl, _args: Vec<&Meta>) -> Result<TokenStream2,
11171115
}
11181116

11191117
fn handle_impl_fn(ty: &TypePath, f: &ImplItemFn, args: Meta) -> Result<TokenStream2, CompileError> {
1120-
let fn_attr_span = args.span().clone();
1118+
let fn_attr_span = args.span();
11211119
let meta_list = match args {
11221120
Meta::List(meta_list) => {
11231121
let args_tokens = TokenStream::from(meta_list.tokens);
@@ -1185,6 +1183,7 @@ enum ValueFlowDirection {
11851183
}
11861184

11871185
#[derive(Clone, Copy, PartialEq, PartialOrd)]
1186+
#[allow(unused)]
11881187
enum OuterTypeType {
11891188
None,
11901189
Reference,
@@ -1223,7 +1222,7 @@ fn parse_type_internal(
12231222
let ty = if let Type::Group(group) = ty {
12241223
group.elem.as_ref()
12251224
} else {
1226-
&base_ty
1225+
base_ty
12271226
};
12281227

12291228
if let Some(trait_obj) = try_as_boxed_trait_object(ty) {
@@ -1258,7 +1257,7 @@ fn parse_type_internal(
12581257
};
12591258
let (out_type, out_syn_types) = match &paren_args.output {
12601259
ReturnType::Type(_, ty) => {
1261-
parse_type_internal(&ty, flow_direction, OuterTypeType::None)?
1260+
parse_type_internal(ty, flow_direction, OuterTypeType::None)?
12621261
},
12631262
ReturnType::Default => (ObjectType::empty(), vec![]),
12641263
};
@@ -1294,32 +1293,32 @@ fn parse_type_internal(
12941293
all_syn_types,
12951294
))
12961295
} else if let Type::Path(path) = ty {
1297-
if path.path.segments.len() == 0 {
1296+
if path.path.segments.is_empty() {
12981297
return Err(CompileError::new(path.span(), "Type path does not contain any segments"));
12991298
}
13001299

13011300
let parsed_opt = first_some!(
1302-
resolve_i8(&path),
1303-
resolve_i16(&path),
1304-
resolve_i32(&path),
1305-
resolve_i64(&path),
1306-
resolve_i128(&path),
1307-
resolve_u8(&path),
1308-
resolve_u16(&path),
1309-
resolve_u32(&path),
1310-
resolve_u64(&path),
1311-
resolve_u128(&path),
1312-
resolve_f32(&path),
1313-
resolve_f64(&path),
1314-
resolve_bool(&path),
1315-
resolve_string(&path),
1301+
resolve_i8(path),
1302+
resolve_i16(path),
1303+
resolve_i32(path),
1304+
resolve_i64(path),
1305+
resolve_i128(path),
1306+
resolve_u8(path),
1307+
resolve_u16(path),
1308+
resolve_u32(path),
1309+
resolve_u64(path),
1310+
resolve_u128(path),
1311+
resolve_f32(path),
1312+
resolve_f64(path),
1313+
resolve_bool(path),
1314+
resolve_string(path),
13161315
);
13171316

13181317
if let Some(res) = parsed_opt {
13191318
return Ok((res, vec![]));
13201319
}
13211320

1322-
if let Some(res) = resolve_vec(&path, flow_direction)? {
1321+
if let Some(res) = resolve_vec(path, flow_direction)? {
13231322
if outer_type != OuterTypeType::None &&
13241323
outer_type != OuterTypeType::Reference {
13251324
return Err(CompileError::new(path.span(), "Vec may not be used as an inner type"));
@@ -1329,22 +1328,22 @@ fn parse_type_internal(
13291328
return Ok((res.0, resolved_inner_type));
13301329
}
13311330

1332-
if let Some(res) = resolve_result(&path, flow_direction)? {
1331+
if let Some(res) = resolve_result(path, flow_direction)? {
13331332
if outer_type != OuterTypeType::None {
1334-
if outer_type == OuterTypeType::Reference {
1335-
return Err(CompileError::new(
1333+
return if outer_type == OuterTypeType::Reference {
1334+
Err(CompileError::new(
13361335
path.span(),
13371336
"Result may not be passed as references in bound symbol"
1338-
));
1337+
))
13391338
} else {
1340-
return Err(CompileError::new(
1339+
Err(CompileError::new(
13411340
path.span(), "Result may not be used as an inner type"
1342-
));
1341+
))
13431342
}
13441343
}
13451344

13461345
let resolved_inner_types = [res.1, res.2].into_iter()
1347-
.filter_map(|opt| opt)
1346+
.flatten()
13481347
.collect();
13491348
return Ok((res.0, resolved_inner_types));
13501349
}
@@ -1426,7 +1425,7 @@ fn parse_type_internal(
14261425
} else if let Type::Ptr(_) = ty {
14271426
Err(CompileError::new(ty.span(), "Pointer is not allowed in bound symbol"))
14281427
} else if let Type::Tuple(tuple) = ty {
1429-
if tuple.elems.len() == 0 {
1428+
if tuple.elems.is_empty() {
14301429
Ok((
14311430
ObjectType::empty(),
14321431
vec![],
@@ -1449,8 +1448,8 @@ fn match_path(subject: &Path, needle: Vec<&'static str>) -> bool {
14491448
needle[needle.len() - subject.segments.len()..]
14501449
.iter()
14511450
.enumerate()
1452-
.map(|(i, seg)| subject.segments[i].ident.to_string() == *seg)
1453-
.fold(true, |a, b| a && b)
1451+
.map(|(i, seg)| subject.segments[i].ident == seg)
1452+
.all(|b| b)
14541453
}
14551454
}
14561455

@@ -1528,7 +1527,7 @@ fn resolve_vec(ty: &TypePath, flow_direction: ValueFlowDirection)
15281527
else { return Err(CompileError::new(ty.span(), "Invalid Vec argument syntax")); };
15291528

15301529
let (inner_obj_type, resolved_inner_types) =
1531-
parse_type_internal(&inner_type, flow_direction, OuterTypeType::Vec)?;
1530+
parse_type_internal(inner_type, flow_direction, OuterTypeType::Vec)?;
15321531
assert!(resolved_inner_types.len() <= 1,
15331532
"Parsing Vec type returned too many resolved types for inner type");
15341533

engine/libs/scripting_types/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,8 @@ impl ObjectType {
256256
pub fn get_is_refable(&self) -> Option<bool> {
257257
if let Some(refable) = self.is_refable {
258258
Some(refable)
259-
} else if let Some(getter) = self.is_refable_getter {
260-
Some((getter.fn_ptr)())
261259
} else {
262-
None
260+
self.is_refable_getter.map(|getter| (getter.fn_ptr)())
263261
}
264262
}
265263
}
@@ -403,7 +401,7 @@ impl Wrappable for String {
403401
}
404402
}
405403

406-
impl<'a> ScriptBound for &'a str {
404+
impl ScriptBound for &str {
407405
fn get_object_type() -> ObjectType {
408406
ObjectType {
409407
ty: IntegralType::String,
@@ -422,7 +420,7 @@ impl<'a> ScriptBound for &'a str {
422420
}
423421
}
424422

425-
impl<'a> Wrappable for &'a str {
423+
impl Wrappable for &str {
426424
type InternalFormat = ffi::c_char;
427425

428426
fn wrap_into(self, wrapper: &mut WrappedObject) {
@@ -560,6 +558,8 @@ impl<T: ScriptBound> Wrappable for &mut T {
560558

561559
const WRAPPED_OBJ_BUF_CAP: usize = 64;
562560

561+
pub type EnumValueGetter = fn() -> i64;
562+
563563
pub struct WrappedObject {
564564
pub ty: ObjectType,
565565
pub data: [u8; WRAPPED_OBJ_BUF_CAP],
@@ -648,7 +648,7 @@ impl WrappedObject {
648648
}
649649

650650
pub fn unwrap<T: Wrappable>(&self) -> T {
651-
<T as Wrappable>::unwrap_as_value(&self)
651+
<T as Wrappable>::unwrap_as_value(self)
652652
}
653653

654654
fn initialize_buffer(&mut self, size: usize) {
@@ -818,7 +818,7 @@ pub struct BoundEnumInfo {
818818
pub name: &'static str,
819819
pub type_id: fn() -> TypeId,
820820
pub width: usize,
821-
pub values: &'static [(&'static str, fn() -> i64)],
821+
pub values: &'static [(&'static str, EnumValueGetter)],
822822
}
823823

824824
pub unsafe extern "C" fn copy_string(dst: *mut (), src: *const ()) {

0 commit comments

Comments
 (0)