From aae41b93bbb1d659d46ce26b88299eaf10499ed8 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Mon, 2 Jan 2023 11:25:36 +0100 Subject: [PATCH] Clippy fixes --- src/dynamic_data/flow/choice_queue.rs | 2 +- src/dynamic_data/flow/turn_runner.rs | 2 +- src/dynamic_data/models/pokemon.rs | 5 ++--- src/dynamic_data/models/pokemon_builder.rs | 2 +- src/dynamic_data/script_handling/script_set.rs | 2 +- src/ffi/dynamic_data/models/pokemon.rs | 2 +- src/ffi/static_data/libraries/nature_library.rs | 2 +- src/lib.rs | 2 +- src/script_implementations/wasm/extern_ref.rs | 4 ++-- src/script_implementations/wasm/script_resolver.rs | 6 +++--- src/static_data/mod.rs | 8 ++++---- 11 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/dynamic_data/flow/choice_queue.rs b/src/dynamic_data/flow/choice_queue.rs index 8d1f7df..a15f749 100755 --- a/src/dynamic_data/flow/choice_queue.rs +++ b/src/dynamic_data/flow/choice_queue.rs @@ -151,7 +151,7 @@ mod tests { fn get_user(level: LevelInt) -> Pokemon { let lib = Arc::new(crate::dynamic_data::libraries::dynamic_library::test::build()); - let species = lib.static_data().species().get(&"foo".into()).unwrap().clone(); + let species = lib.static_data().species().get(&"foo".into()).unwrap(); let form = species.get_form(&"default".into()).unwrap(); Pokemon::new( diff --git a/src/dynamic_data/flow/turn_runner.rs b/src/dynamic_data/flow/turn_runner.rs index e2fe9c4..1cef78e 100755 --- a/src/dynamic_data/flow/turn_runner.rs +++ b/src/dynamic_data/flow/turn_runner.rs @@ -117,7 +117,7 @@ impl Battle { number_of_hits, choice.user().clone(), used_move.clone(), - move_data.clone(), + move_data, move_choice.script().clone(), ); let mut prevented = false; diff --git a/src/dynamic_data/models/pokemon.rs b/src/dynamic_data/models/pokemon.rs index 754f863..6d3f9e3 100755 --- a/src/dynamic_data/models/pokemon.rs +++ b/src/dynamic_data/models/pokemon.rs @@ -141,8 +141,7 @@ impl Pokemon { .static_data() .natures() .get_nature(nature) - .unwrap_or_else(|| panic!("Unknown nature name was given: {}.", &nature)) - .clone(); + .unwrap_or_else(|| panic!("Unknown nature name was given: {}.", &nature)); let mut pokemon = Self { identifier: Default::default(), library, @@ -892,7 +891,7 @@ pub mod test { #[test] fn construct_pokemon() { let lib = mock_library(); - let species = lib.static_data().species().get(&"foo".into()).unwrap().clone(); + let species = lib.static_data().species().get(&"foo".into()).unwrap(); let form = species.get_form(&"default".into()).unwrap(); let pokemon = Pokemon::new( diff --git a/src/dynamic_data/models/pokemon_builder.rs b/src/dynamic_data/models/pokemon_builder.rs index 7462aa1..645b855 100755 --- a/src/dynamic_data/models/pokemon_builder.rs +++ b/src/dynamic_data/models/pokemon_builder.rs @@ -46,7 +46,7 @@ impl PokemonBuilder { Random::default() }; - let species = self.library.static_data().species().get(&self.species).unwrap().clone(); + let species = self.library.static_data().species().get(&self.species).unwrap(); let form = species.get_default_form(); let p = Pokemon::new( self.library, diff --git a/src/dynamic_data/script_handling/script_set.rs b/src/dynamic_data/script_handling/script_set.rs index e32112e..02aab3d 100755 --- a/src/dynamic_data/script_handling/script_set.rs +++ b/src/dynamic_data/script_handling/script_set.rs @@ -36,7 +36,7 @@ impl ScriptSet { /// Adds a script with a name to the set. If the script with that name already exists in this /// set, this makes that script stack instead. The return value here is that script. - pub fn stack_or_add<'b, F>(&self, key: &StringKey, instantiation: &'b F) -> PkmnResult> + pub fn stack_or_add(&self, key: &StringKey, instantiation: &F) -> PkmnResult> where F: Fn() -> PkmnResult>>, { diff --git a/src/ffi/dynamic_data/models/pokemon.rs b/src/ffi/dynamic_data/models/pokemon.rs index 0cfe86c..1fca4cf 100644 --- a/src/ffi/dynamic_data/models/pokemon.rs +++ b/src/ffi/dynamic_data/models/pokemon.rs @@ -261,7 +261,7 @@ extern "C" fn pokemon_is_ability_overriden(ptr: ExternPointer>) -> /// Returns the currently active ability. #[no_mangle] extern "C" fn pokemon_active_ability(ptr: ExternPointer>) -> IdentifiablePointer> { - ptr.as_ref().active_ability().clone().into() + ptr.as_ref().active_ability().into() } /// Whether or not the Pokemon is allowed to gain experience. diff --git a/src/ffi/static_data/libraries/nature_library.rs b/src/ffi/static_data/libraries/nature_library.rs index 5d93739..063f7ab 100644 --- a/src/ffi/static_data/libraries/nature_library.rs +++ b/src/ffi/static_data/libraries/nature_library.rs @@ -35,7 +35,7 @@ unsafe extern "C" fn nature_library_get_nature( name: BorrowedPtr, ) -> IdentifiablePointer> { if let Some(nature) = ptr.as_ref().get_nature(&CStr::from_ptr(name).into()) { - nature.clone().into() + nature.into() } else { IdentifiablePointer::none() } diff --git a/src/lib.rs b/src/lib.rs index 5f8a054..0b8c1a2 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,7 +72,7 @@ impl Display for PokemonError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { PokemonError::ScriptNotFound { category, name } => { - write!(f, "No script found with category `{}` and name `{}`", category, name) + write!(f, "No script found with category `{category}` and name `{name}`") } PokemonError::InvalidTargetRequested => { write!(f, "Invalid target was requested") diff --git a/src/script_implementations/wasm/extern_ref.rs b/src/script_implementations/wasm/extern_ref.rs index bb3b766..6d32a3e 100755 --- a/src/script_implementations/wasm/extern_ref.rs +++ b/src/script_implementations/wasm/extern_ref.rs @@ -58,7 +58,7 @@ impl ExternRef { /// Returns the real value for a given ExternRef. Note that the requested type must be the same as the type of the /// value when it was passed before. If these types do not match, this will panic. - pub fn value_func<'a, 'b>(&'a self, env: &'b FunctionEnvMut) -> Option<&'b T> + pub fn value_func<'a>(&self, env: &'a FunctionEnvMut) -> Option<&'a T> where T: Sized + 'static, { @@ -85,7 +85,7 @@ impl ExternRef { /// Returns the real value for a given ExternRef. Note that the requested type must be the same as the type of the /// value when it was passed before. If these types do not match, this will panic. - pub fn value<'a, 'b, 'c>(&'a self, env: &'b Arc) -> Option<&'c T> + pub fn value<'a>(&self, env: &Arc) -> Option<&'a T> where T: Sized + 'static, { diff --git a/src/script_implementations/wasm/script_resolver.rs b/src/script_implementations/wasm/script_resolver.rs index 8e8664a..698fc72 100755 --- a/src/script_implementations/wasm/script_resolver.rs +++ b/src/script_implementations/wasm/script_resolver.rs @@ -382,7 +382,7 @@ impl WebAssemblyEnvironmentData { pub fn get_extern_vec_ref_extern_ref(&self, extern_vec_ref: usize, index: usize) -> usize { let r = self.extern_vec_ref_lookup.read(); let v = r.get(&extern_vec_ref).unwrap(); - v[index as usize] + v[index] } /// Gets the extern ref index belonging to a specific pointer. If none exists, this will create @@ -393,7 +393,7 @@ impl WebAssemblyEnvironmentData { ptr: value as *const dyn Any, is_vec, }) { - return *v as usize; + return *v; } let index = { let mut extern_ref_guard = self.extern_ref_pointers.write(); @@ -416,7 +416,7 @@ impl WebAssemblyEnvironmentData { /// Gets a value from the extern ref lookup. This turns an earlier registered index back into /// its proper value, validates its type, and returns the value. - pub fn get_extern_ref_value<'a, 'b, T: ?Sized>(&'a self, index: usize) -> &'b dyn Any { + pub fn get_extern_ref_value<'a, T: ?Sized>(&self, index: usize) -> &'a dyn Any { let read_guard = self.extern_ref_pointers.read(); let ptr = read_guard.get(index - 1).unwrap(); if self diff --git a/src/static_data/mod.rs b/src/static_data/mod.rs index 5ef885b..a84e7ba 100755 --- a/src/static_data/mod.rs +++ b/src/static_data/mod.rs @@ -92,10 +92,10 @@ impl From for EffectParameter { impl Display for EffectParameter { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { - EffectParameter::Bool(_, v) => f.write_fmt(format_args!("EffectParameter::Bool({})", v)), - EffectParameter::Int(_, v) => f.write_fmt(format_args!("EffectParameter::Int({})", v)), - EffectParameter::Float(_, v) => f.write_fmt(format_args!("EffectParameter::Float({})", v)), - EffectParameter::String(_, v) => f.write_fmt(format_args!("EffectParameter::String({})", v)), + EffectParameter::Bool(_, v) => f.write_fmt(format_args!("EffectParameter::Bool({v})")), + EffectParameter::Int(_, v) => f.write_fmt(format_args!("EffectParameter::Int({v})")), + EffectParameter::Float(_, v) => f.write_fmt(format_args!("EffectParameter::Float({v})")), + EffectParameter::String(_, v) => f.write_fmt(format_args!("EffectParameter::String({v})")), } } }