Prechádzať zdrojové kódy

Appease rust 1.78.0 clippies (#1643)

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 1 rok pred
rodič
commit
96a1cc842a

+ 1 - 1
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()

+ 6 - 6
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);
                     }
                 }
             }

+ 5 - 5
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()
     }
 }
 

+ 4 - 5
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())
     }
 }
 

+ 10 - 12
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"),
+        }
     }
 }
 

+ 4 - 3
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)
     }
 }
 

+ 2 - 2
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(());

+ 1 - 0
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),

+ 7 - 5
tests/evm.rs

@@ -272,18 +272,20 @@ fn set_file_contents(source: &str, path: &Path) -> (FileResolver, Vec<String>) {
             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);
             }

+ 4 - 5
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"));
 }