Skip to content

Commit e6beb49

Browse files
committed
clippy fixes
1 parent 7bafd98 commit e6beb49

File tree

28 files changed

+138
-617
lines changed

28 files changed

+138
-617
lines changed

crates/bevy_mod_scripting_core/src/asset.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
use std::{
2-
borrow::Cow,
3-
path::{Path, PathBuf},
4-
};
5-
1+
use crate::{prelude::ScriptError, script::ScriptId};
62
use bevy::{
7-
asset::{Asset, AssetId, AssetLoader, AsyncReadExt},
3+
asset::{Asset, AssetId, AssetLoader},
84
ecs::system::Resource,
95
reflect::TypePath,
10-
utils::{BoxedFuture, HashMap},
6+
utils::HashMap,
7+
};
8+
use std::{
9+
borrow::Cow,
10+
path::{Path, PathBuf},
1111
};
12-
13-
use crate::{prelude::ScriptError, script::ScriptId};
1412

1513
/// Represents a script loaded into memory as an asset
1614
#[derive(Asset, TypePath, Clone)]

crates/bevy_mod_scripting_core/src/bindings/access_map.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use std::{
2-
sync::atomic::{AtomicBool, AtomicUsize},
3-
thread::ThreadId,
4-
};
1+
use std::{sync::atomic::AtomicBool, thread::ThreadId};
52

63
use bevy::{
74
ecs::{component::ComponentId, world::unsafe_world_cell::UnsafeWorldCell},
85
prelude::Resource,
96
};
10-
use dashmap::{try_result::TryResult, DashMap, Entry, Map};
7+
use dashmap::{DashMap, Entry};
118
use smallvec::SmallVec;
129

1310
use super::{ReflectAllocationId, ReflectBase};
@@ -49,7 +46,7 @@ impl AccessCount {
4946
}
5047

5148
fn as_location(&self) -> Option<std::panic::Location<'static>> {
52-
self.read_by.first().map(|o| o.location.clone())
49+
self.read_by.first().map(|o| o.location)
5350
}
5451

5552
fn readers(&self) -> usize {
@@ -372,6 +369,7 @@ macro_rules! with_global_access {
372369
)
373370
);
374371
} else {
372+
#[allow(clippy::redundant_closure_call)]
375373
let result = (|| $body)();
376374
$access_map.release_global_access();
377375
result

crates/bevy_mod_scripting_core/src/bindings/allocator.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
use bevy::ecs::system::Resource;
2-
use bevy::reflect::{PartialReflect, Reflect};
1+
use bevy::{ecs::system::Resource, reflect::PartialReflect};
32
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
4-
use std::any::{Any, TypeId};
5-
use std::cell::UnsafeCell;
6-
use std::cmp::Ordering;
7-
use std::collections::HashMap;
8-
use std::fmt::{Display, Formatter};
9-
use std::hash::Hasher;
10-
use std::io::Read;
11-
use std::sync::atomic::{AtomicU64, AtomicUsize};
12-
use std::sync::Arc;
3+
use std::{
4+
any::TypeId,
5+
cell::UnsafeCell,
6+
cmp::Ordering,
7+
collections::HashMap,
8+
fmt::{Display, Formatter},
9+
hash::Hasher,
10+
sync::{atomic::AtomicU64, Arc},
11+
};
1312

1413
#[derive(Clone, Debug)]
1514
pub struct ReflectAllocationId(pub(crate) Arc<u64>);

crates/bevy_mod_scripting_core/src/bindings/function/from.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl FromScript for ScriptValue {
3434

3535
impl FromScript for () {
3636
type This<'w> = Self;
37-
fn from_script(value: ScriptValue, _world: WorldGuard) -> Result<Self, InteropError> {
37+
fn from_script(_value: ScriptValue, _world: WorldGuard) -> Result<Self, InteropError> {
3838
Ok(())
3939
}
4040
}

crates/bevy_mod_scripting_core/src/bindings/function/into.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::{
22
borrow::Cow,
33
ffi::OsString,
4-
path::{Path, PathBuf},
4+
path::PathBuf,
55
};
66

7-
use bevy::reflect::{GetTypeRegistration, PartialReflect, ReflectRef};
7+
use bevy::reflect::PartialReflect;
88

99
use crate::{
1010
bindings::{ReflectReference, WorldGuard},

crates/bevy_mod_scripting_core/src/bindings/function/into_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{any::TypeId, ffi::OsString, path::PathBuf};
1+
use std::{ffi::OsString, path::PathBuf};
22

33
use bevy::reflect::{ParsedPath, PartialReflect};
44

crates/bevy_mod_scripting_core/src/bindings/function/mod.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
use std::{any::TypeId, borrow::Cow, ops::Deref, sync::Arc};
21

32
pub mod from;
43
pub mod from_ref;
54
pub mod into;
65
pub mod into_ref;
76
pub mod script_function;
87

9-
use bevy::reflect::{
10-
func::{
11-
args::{Arg, ArgInfo, Ownership},
12-
ArgList, ArgValue, DynamicFunction, FunctionInfo, FunctionResult, Return,
13-
},
14-
PartialReflect,
15-
};
168
use script_function::{CallerContext, DynamicScriptFunction, DynamicScriptFunctionMut};
179

18-
use crate::{
19-
error::{FlattenError, InteropError, InteropErrorInner, ScriptError, ScriptResult},
20-
reflection_extensions::{PartialReflectExt, ReturnValExt},
21-
};
10+
use crate::error::InteropError;
2211

2312
use super::{
24-
access_map::ReflectAccessId, pretty_print::DisplayWithWorld, script_value::ScriptValue,
25-
ReflectBase, ReflectReference, WorldAccessGuard, WorldCallbackAccess, WorldGuard,
13+
pretty_print::DisplayWithWorld, script_value::ScriptValue, WorldCallbackAccess, WorldGuard,
2614
};
2715

2816
/// Can be implemented for callables which require dynamic access to the world to be called.

crates/bevy_mod_scripting_core/src/bindings/function/script_function.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ use crate::{
88
prelude::{ScriptValue, WorldCallbackAccess},
99
};
1010
use bevy::{
11-
prelude::{AppFunctionRegistry, IntoFunction, Reflect, Resource, World},
11+
prelude::{Reflect, Resource},
1212
reflect::{
13-
func::{args::GetOwnership, DynamicFunction, FunctionError, FunctionInfo, TypedFunction},
14-
FromReflect, GetTypeRegistration, PartialReflect, TypePath, TypeRegistration, TypeRegistry,
15-
Typed,
13+
func::{args::GetOwnership, FunctionError},
14+
FromReflect, GetTypeRegistration, TypePath, TypeRegistry, Typed,
1615
},
1716
};
1817
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
@@ -531,28 +530,6 @@ macro_rules! assert_is_script_function {
531530
#[cfg(test)]
532531
mod test {
533532
use super::*;
534-
use crate::bindings::function::script_function::ScriptFunction;
535-
use crate::prelude::AppReflectAllocator;
536-
use bevy::reflect::func::{ArgList, ArgValue, Return};
537-
use test_utils::test_data::*;
538-
539-
fn test_setup_world() -> World {
540-
setup_world(|w, _| w.insert_resource(AppReflectAllocator::default()))
541-
}
542-
543-
fn assert_function_info_eq(a: &FunctionInfo, b: &FunctionInfo) {
544-
assert_eq!(a.name(), b.name(), "Function names do not match");
545-
assert_eq!(
546-
a.args().len(),
547-
b.args().len(),
548-
"Function arg count does not match"
549-
);
550-
for (a, b) in a.args().iter().zip(b.args().iter()) {
551-
assert_eq!(a.type_id(), b.type_id(), "Function arg types do not match");
552-
assert_eq!(a.name(), b.name(), "Function arg names do not match");
553-
}
554-
}
555-
556533
#[test]
557534
fn test_register_script_function() {
558535
let mut registry = ScriptFunctionRegistry::default();

crates/bevy_mod_scripting_core/src/bindings/query.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use super::{ReflectReference, WorldAccessGuard, WorldCallbackAccess};
2-
use crate::{
3-
bindings::{CONCURRENT_WORLD_ACCESS_MSG, STALE_WORLD_MSG},
4-
error::InteropError,
5-
with_global_access,
6-
};
2+
use crate::{error::InteropError, with_global_access};
73
use bevy::{
84
ecs::{component::ComponentId, entity::Entity},
95
prelude::{EntityRef, QueryBuilder},
@@ -133,7 +129,7 @@ impl WorldCallbackAccess {
133129
}
134130
}
135131

136-
impl<'w> WorldAccessGuard<'w> {
132+
impl WorldAccessGuard<'_> {
137133
pub fn query(
138134
&self,
139135
query: ScriptQueryBuilder,
@@ -203,18 +199,3 @@ impl<'w> WorldAccessGuard<'w> {
203199
})
204200
}
205201
}
206-
207-
#[cfg(test)]
208-
mod test {
209-
use test_utils::test_data::setup_world;
210-
211-
use super::*;
212-
213-
// #[test]
214-
// fn test_simple_query() {
215-
// let world = setup_world(|w,r|{
216-
// w.spawn(TestComponent::init())
217-
// w.spawn(Te)
218-
// })
219-
// }
220-
}

crates/bevy_mod_scripting_core/src/bindings/reference.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
//! reflection gives us access to `dyn PartialReflect` objects via their type name,
55
//! Scripting languages only really support `Clone` objects so if we want to support references,
66
//! we need wrapper types which have owned and ref variants.
7-
use super::{
8-
access_map::{AccessMapKey, ReflectAccessId},
9-
WorldAccessGuard, WorldCallbackAccess, WorldGuard,
10-
};
7+
use super::{access_map::ReflectAccessId, WorldGuard};
118
use crate::{
12-
bindings::{pretty_print::DisplayWithWorld, ReflectAllocationId},
9+
bindings::ReflectAllocationId,
1310
error::InteropError,
14-
prelude::{ReflectAllocator, ScriptResult},
11+
prelude::ReflectAllocator,
1512
reflection_extensions::{PartialReflectExt, TypeIdExtensions},
1613
with_access_read, with_access_write,
1714
};
@@ -22,14 +19,9 @@ use bevy::{
2219
},
2320
prelude::{Component, ReflectDefault, Resource},
2421
ptr::Ptr,
25-
reflect::{
26-
func::{args::ArgInfo, ArgValue},
27-
ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectFromReflect, ReflectMut,
28-
ReflectPath, ReflectPathError, ReflectRef, TypeData,
29-
},
22+
reflect::{ParsedPath, PartialReflect, Reflect, ReflectFromPtr, ReflectPath},
3023
};
31-
use itertools::Either;
32-
use std::{any::TypeId, fmt::Debug, sync::Arc};
24+
use std::{any::TypeId, fmt::Debug};
3325

3426
/// An accessor to a `dyn PartialReflect` struct, stores a base ID of the type and a reflection path
3527
/// safe to build but to reflect on the value inside you need to ensure aliasing rules are upheld
@@ -464,25 +456,6 @@ impl ReflectBase {
464456
}
465457
}
466458

467-
fn map_key_to_concrete(key: &str, key_type_id: TypeId) -> Option<Box<dyn PartialReflect>> {
468-
match key_type_id {
469-
_ if key_type_id == std::any::TypeId::of::<String>() => Some(Box::new(key.to_owned())),
470-
_ if key_type_id == std::any::TypeId::of::<usize>() => key
471-
.parse::<usize>()
472-
.ok()
473-
.map(|u| Box::new(u) as Box<dyn PartialReflect>),
474-
_ if key_type_id == std::any::TypeId::of::<f32>() => key
475-
.parse::<f32>()
476-
.ok()
477-
.map(|f| Box::new(f) as Box<dyn PartialReflect>),
478-
_ if key_type_id == std::any::TypeId::of::<bool>() => key
479-
.parse::<bool>()
480-
.ok()
481-
.map(|b| Box::new(b) as Box<dyn PartialReflect>),
482-
_ => None,
483-
}
484-
}
485-
486459
pub trait ReflectionPathExt {
487460
fn convert_to_0_indexed(&mut self);
488461

crates/bevy_mod_scripting_core/src/bindings/script_value/mod.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
use std::{
2-
any::{type_name, TypeId},
3-
borrow::Cow,
4-
ffi::{CStr, CString, OsStr, OsString},
5-
path::{Path, PathBuf},
6-
};
7-
8-
use bevy::reflect::{
9-
Access, DynamicEnum, DynamicList, DynamicTuple, DynamicVariant, OffsetAccess, ParsedPath,
10-
PartialReflect, Reflect, ReflectFromReflect, TypeData,
11-
};
12-
13-
use crate::{
14-
error::{InteropError, InteropErrorInner, ScriptError, ScriptResult},
15-
reflection_extensions::{PartialReflectExt, TypeIdExtensions, TypeInfoExtensions},
16-
};
17-
18-
use super::{
19-
function::script_function::{DynamicScriptFunction, DynamicScriptFunctionMut},
20-
pretty_print::DisplayWithWorld,
21-
ReflectReference, WorldGuard,
22-
};
1+
use std::borrow::Cow;
2+
3+
use bevy::reflect::{OffsetAccess, ParsedPath, Reflect};
4+
5+
use crate::error::InteropError;
6+
7+
use super::{function::script_function::DynamicScriptFunctionMut, ReflectReference};
238

249
/// An abstraction of values that can be passed to and from scripts.
2510
/// This allows us to re-use logic between scripting languages.
@@ -148,7 +133,7 @@ impl TryFrom<ScriptValue> for ParsedPath {
148133
access: bevy::reflect::Access::ListIndex(i as usize),
149134
offset: Some(1),
150135
}]),
151-
ScriptValue::Float(v) => {
136+
ScriptValue::Float(_) => {
152137
return Err(InteropError::invalid_index(
153138
value,
154139
"Floating point numbers cannot be used to index into reflected values"

0 commit comments

Comments
 (0)