diff --git a/src/abi/anchor.rs b/src/abi/anchor.rs index 49173daa4..9d7290d2c 100644 --- a/src/abi/anchor.rs +++ b/src/abi/anchor.rs @@ -290,7 +290,7 @@ impl TypeManager<'_> { format!("_{real_name}") }; let unique_name = self.unique_string(new_other_name); - self.types[idx].name = unique_name.clone(); + self.types[idx].name.clone_from(&unique_name); self.added_names .insert(unique_name, (idx, other_contract, real_name)); type_name.clone() diff --git a/src/bin/languageserver/mod.rs b/src/bin/languageserver/mod.rs index 44595c1cf..eb09dfebf 100644 --- a/src/bin/languageserver/mod.rs +++ b/src/bin/languageserver/mod.rs @@ -1876,7 +1876,7 @@ impl<'a> Builder<'a> { .hover_overrides .get(&pt::Loc::File(lookup.0, lookup.1.start, lookup.1.stop)) { - lookup.1.val = msg.clone(); + lookup.1.val.clone_from(msg); } } @@ -1900,7 +1900,7 @@ impl<'a> Builder<'a> { for val in self.types.values_mut() { if let Some(path) = defs_to_files.get(&val.def_type) { - val.def_path = path.clone(); + val.def_path.clone_from(path); } } @@ -1948,7 +1948,7 @@ impl<'a> Builder<'a> { .map(|(_, i)| { let mut i = i.clone(); if let Some(def_path) = defs_to_files.get(&i.val.def_type) { - i.val.def_path = def_path.clone(); + i.val.def_path.clone_from(def_path); } i }) @@ -1963,7 +1963,7 @@ impl<'a> Builder<'a> { for val in &mut scope.val { if let Some(val) = &mut val.1 { if let Some(def_path) = defs_to_files.get(&val.def_type) { - val.def_path = def_path.clone(); + val.def_path.clone_from(def_path); } } } @@ -1980,7 +1980,7 @@ impl<'a> Builder<'a> { { if def_path.to_str().unwrap() == "" { if let Some(dp) = defs_to_files.get(def_type) { - *def_path = dp.clone(); + def_path.clone_from(dp); } } } @@ -1994,7 +1994,7 @@ impl<'a> Builder<'a> { for def_index in properties.values_mut().flatten() { if def_index.def_path.to_str().unwrap() == "" { if let Some(def_path) = defs_to_files.get(&def_index.def_type) { - def_index.def_path = def_path.clone(); + def_index.def_path.clone_from(def_path); } } } diff --git a/src/codegen/dispatch/polkadot.rs b/src/codegen/dispatch/polkadot.rs index f8c21c077..3cbbcc94b 100644 --- a/src/codegen/dispatch/polkadot.rs +++ b/src/codegen/dispatch/polkadot.rs @@ -12,6 +12,7 @@ use crate::{ }; use num_bigint::{BigInt, Sign}; use solang_parser::pt::{FunctionTy, Loc::Codegen}; +use std::fmt::{Display, Formatter, Result}; /// On Polkadot, contracts export a `call` and a `deploy` function. /// The `contracts` pallet will invoke `deploy` on contract instatiation, @@ -27,13 +28,12 @@ pub enum DispatchType { Call, } -impl ToString for DispatchType { - fn to_string(&self) -> String { +impl Display for DispatchType { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { match self { - Self::Deploy => "polkadot_deploy_dispatch", - Self::Call => "polkadot_call_dispatch", + Self::Deploy => f.write_str("polkadot_deploy_dispatch"), + Self::Call => f.write_str("polkadot_call_dispatch"), } - .into() } } diff --git a/src/sema/solana_accounts.rs b/src/sema/solana_accounts.rs index 88c20036f..478b910a1 100644 --- a/src/sema/solana_accounts.rs +++ b/src/sema/solana_accounts.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 -use std::str::FromStr; +use std::{fmt, str::FromStr}; pub enum BuiltinAccounts { /// These are the accounts that we can collect from a contract and that Anchor will populate @@ -31,10 +31,9 @@ impl BuiltinAccounts { } } -impl ToString for BuiltinAccounts { - fn to_string(&self) -> String { - let str = self.as_str(); - str.to_string() +impl fmt::Display for BuiltinAccounts { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(self.as_str()) } } diff --git a/src/sema/yul/ast.rs b/src/sema/yul/ast.rs index e3447e48e..02e25887c 100644 --- a/src/sema/yul/ast.rs +++ b/src/sema/yul/ast.rs @@ -7,7 +7,7 @@ use crate::sema::Recurse; use num_bigint::BigInt; use solang_parser::pt; use solang_parser::pt::{CodeLocation, StorageLocation}; -use std::sync::Arc; +use std::{fmt, sync::Arc}; #[derive(Debug, Clone)] pub struct InlineAssembly { @@ -97,17 +97,15 @@ pub enum YulSuffix { Address, } -impl ToString for YulSuffix { - fn to_string(&self) -> String { - let name = match self { - YulSuffix::Offset => "offset", - YulSuffix::Slot => "slot", - YulSuffix::Length => "length", - YulSuffix::Selector => "selector", - YulSuffix::Address => "address", - }; - - name.to_string() +impl fmt::Display for YulSuffix { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + YulSuffix::Offset => f.write_str("offset"), + YulSuffix::Slot => f.write_str("slot"), + YulSuffix::Length => f.write_str("length"), + YulSuffix::Selector => f.write_str("selector"), + YulSuffix::Address => f.write_str("address"), + } } } diff --git a/src/sema/yul/builtin.rs b/src/sema/yul/builtin.rs index ea1b1c61d..7b9808fed 100644 --- a/src/sema/yul/builtin.rs +++ b/src/sema/yul/builtin.rs @@ -2,6 +2,7 @@ use crate::Target; use phf::{phf_map, phf_set}; +use std::fmt; pub struct YulBuiltinPrototype { pub name: &'static str, @@ -258,10 +259,10 @@ impl YulBuiltInFunction { } } -impl ToString for YulBuiltInFunction { - fn to_string(&self) -> String { +impl fmt::Display for YulBuiltInFunction { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let prototype = self.get_prototype_info(); - prototype.name.to_owned() + f.write_str(prototype.name) } } diff --git a/src/sema/yul/expression.rs b/src/sema/yul/expression.rs index cb601387a..b8e767a1e 100644 --- a/src/sema/yul/expression.rs +++ b/src/sema/yul/expression.rs @@ -576,7 +576,7 @@ fn resolve_suffix_access( resolved_expr.loc(), format!( "the given expression does not support '.{}' suffixes", - suffix_type.to_string() + suffix_type ), )); } @@ -635,7 +635,7 @@ fn resolve_suffix_access( resolved_expr.loc(), format!( "the given expression does not support '.{}' suffixes", - suffix_type.to_string() + suffix_type ), )); return Err(()); diff --git a/tests/codegen.rs b/tests/codegen.rs index b674d1cc5..08de08071 100644 --- a/tests/codegen.rs +++ b/tests/codegen.rs @@ -33,6 +33,7 @@ fn run_test_for_path(path: &str) { } #[derive(Debug)] +#[allow(unused)] enum Test { Check(usize, String), CheckAbsent(usize, String), diff --git a/tests/evm.rs b/tests/evm.rs index 77bbe1547..ea8e7c7a8 100644 --- a/tests/evm.rs +++ b/tests/evm.rs @@ -272,18 +272,20 @@ fn set_file_contents(source: &str, path: &Path) -> (FileResolver, Vec) { if !contents.is_empty() { cache.set_file_contents(&name, contents); names.push(name); + name = String::new(); } - name = cap.get(1).unwrap().as_str().to_owned(); + cap.get(1).unwrap().as_str().clone_into(&mut name); if name == "////" { - name = "test.sol".to_owned(); + "test.sol".clone_into(&mut name); } contents = String::new(); } else if let Some(cap) = external_source_delimiter.captures(line) { - let mut name = cap.get(1).unwrap().as_str().to_owned(); - if let Some(cap) = equals.captures(&name) { + let filename = cap.get(1).unwrap().as_str(); + let mut name = filename.to_owned(); + if let Some(cap) = equals.captures(filename) { let mut ext = path.parent().unwrap().to_path_buf(); ext.push(cap.get(2).unwrap().as_str()); - name = cap.get(1).unwrap().as_str().to_owned(); + cap.get(1).unwrap().as_str().clone_into(&mut name); let source = fs::read_to_string(ext).unwrap(); cache.set_file_contents(&name, source); } diff --git a/tests/polkadot_tests/contracts.rs b/tests/polkadot_tests/contracts.rs index ddd6844d1..e5b44bee8 100644 --- a/tests/polkadot_tests/contracts.rs +++ b/tests/polkadot_tests/contracts.rs @@ -248,7 +248,7 @@ fn mangle_function_names_in_abi() { let _ = runtime.contracts()[0].code.messages["foo_"]; let _ = runtime.contracts()[0].code.messages["foo_uint256_addressArray2Array"]; let _ = runtime.contracts()[0].code.messages["foo_uint8Array2__int256_bool_address"]; - assert!(runtime.contracts()[0].code.messages.get("foo").is_none()); + assert!(!runtime.contracts()[0].code.messages.contains_key("foo")); } #[test] @@ -265,12 +265,11 @@ fn mangle_overloaded_function_names_in_abi() { ); let _ = runtime.contracts()[0].code.messages["foo"]; - assert!(runtime.contracts()[0] + assert!(!runtime.contracts()[0] .code .messages - .get("foo_bool") - .is_none()); + .contains_key("foo_bool")); let _ = runtime.contracts()[1].code.messages["foo_bool"]; - assert!(runtime.contracts()[1].code.messages.get("foo").is_none()); + assert!(!runtime.contracts()[1].code.messages.contains_key("foo")); }