Browse Source

Reduce clipping overrides

Signed-off-by: Sean Young <sean@mess.org>
Sean Young 5 years ago
parent
commit
76b1e7c30a
7 changed files with 32 additions and 35 deletions
  1. 1 2
      clippy.toml
  2. 2 2
      src/abi/substrate.rs
  3. 1 1
      src/emit/burrow.rs
  4. 7 7
      src/emit/ethabiencoder.rs
  5. 1 1
      src/emit/ewasm.rs
  6. 1 1
      src/emit/mod.rs
  7. 19 21
      src/emit/substrate.rs

+ 1 - 2
clippy.toml

@@ -1,3 +1,2 @@
 too-many-arguments-threshold = 10
-cognitive-complexity-threshold = 50
-trivial-copy-size-limit = 0
+cognitive-complexity-threshold = 40

+ 2 - 2
src/abi/substrate.rs

@@ -427,7 +427,7 @@ fn ty_to_abi(
         resolver::Type::StorageRef(ty) => ty_to_abi(ty, contract, registry),
         resolver::Type::Ref(ty) => ty_to_abi(ty, contract, registry),
         resolver::Type::Primitive(p) => {
-            let scalety = primitive_to_string(p);
+            let scalety = primitive_to_string(*p);
 
             ParamType {
                 ty: registry.builtin_type(&scalety),
@@ -454,7 +454,7 @@ fn ty_to_abi(
 
 // For a given primitive, give the name as Substrate would like it (i.e. 64 bits
 // signed int is i64, not int64).
-fn primitive_to_string(ty: &ast::PrimitiveType) -> String {
+fn primitive_to_string(ty: ast::PrimitiveType) -> String {
     match ty {
         ast::PrimitiveType::Bool => "bool".into(),
         ast::PrimitiveType::Uint(n) => format!("u{}", n),

+ 1 - 1
src/emit/burrow.rs

@@ -155,7 +155,7 @@ impl BurrowTarget {
             argsdata,
             argslen,
             function,
-            &fallback_block,
+            fallback_block,
             self,
         );
 

+ 7 - 7
src/emit/ethabiencoder.rs

@@ -23,7 +23,7 @@ impl EthAbiEncoder {
     ) {
         match &ty {
             resolver::Type::Primitive(e) => {
-                self.encode_primitive(contract, e, *data, arg);
+                self.encode_primitive(contract, *e, *data, arg);
 
                 *data = unsafe {
                     contract.builder.build_gep(
@@ -34,7 +34,7 @@ impl EthAbiEncoder {
                 };
             }
             resolver::Type::Enum(n) => {
-                self.encode_primitive(contract, &contract.ns.enums[*n].ty, *data, arg);
+                self.encode_primitive(contract, contract.ns.enums[*n].ty, *data, arg);
             }
             resolver::Type::FixedArray(_, dim) => {
                 contract.emit_static_loop(
@@ -90,7 +90,7 @@ impl EthAbiEncoder {
     fn encode_primitive(
         &self,
         contract: &Contract,
-        ty: &ast::PrimitiveType,
+        ty: ast::PrimitiveType,
         dest: PointerValue,
         val: BasicValueEnum,
     ) {
@@ -192,8 +192,8 @@ impl EthAbiEncoder {
             | ast::PrimitiveType::Int(_) => {
                 let n = match ty {
                     ast::PrimitiveType::Address => 160,
-                    ast::PrimitiveType::Uint(b) => *b,
-                    ast::PrimitiveType::Int(b) => *b,
+                    ast::PrimitiveType::Uint(b) => b,
+                    ast::PrimitiveType::Int(b) => b,
                     _ => unreachable!(),
                 };
 
@@ -304,7 +304,7 @@ impl EthAbiEncoder {
             }
             ast::PrimitiveType::Bytes(b) => {
                 // first clear/set the upper bits
-                if *b < 32 {
+                if b < 32 {
                     let dest8 = contract.builder.build_pointer_cast(
                         dest,
                         contract.context.i8_type().ptr_type(AddressSpace::Generic),
@@ -323,7 +323,7 @@ impl EthAbiEncoder {
 
                 // no need to allocate space for each uint64
                 // allocate enough for type
-                let int_type = contract.context.custom_width_int_type(*b as u32 * 8);
+                let int_type = contract.context.custom_width_int_type(b as u32 * 8);
                 let type_size = int_type.size_of();
 
                 let store = if val.is_pointer_value() {

+ 1 - 1
src/emit/ewasm.rs

@@ -279,7 +279,7 @@ impl EwasmTarget {
             argsdata,
             argslen,
             function,
-            &fallback_block,
+            fallback_block,
             self,
         );
 

+ 1 - 1
src/emit/mod.rs

@@ -1426,7 +1426,7 @@ impl<'a> Contract<'a> {
         argsdata: inkwell::values::PointerValue,
         argslen: inkwell::values::IntValue,
         function: inkwell::values::FunctionValue,
-        fallback_block: &inkwell::basic_block::BasicBlock,
+        fallback_block: inkwell::basic_block::BasicBlock,
         runtime: &dyn TargetRuntime,
     ) {
         // create start function

+ 19 - 21
src/emit/substrate.rs

@@ -210,7 +210,7 @@ impl SubstrateTarget {
             deploy_args,
             deploy_args_length,
             function,
-            &fallback_block,
+            fallback_block,
             self,
         );
 
@@ -237,7 +237,7 @@ impl SubstrateTarget {
             call_args,
             call_args_length,
             function,
-            &fallback_block,
+            fallback_block,
             self,
         );
 
@@ -261,7 +261,7 @@ impl SubstrateTarget {
     fn decode_primitive<'b>(
         &self,
         contract: &'b Contract,
-        ty: &ast::PrimitiveType,
+        ty: ast::PrimitiveType,
         to: Option<PointerValue<'b>>,
         src: PointerValue<'b>,
     ) -> (BasicValueEnum<'b>, u64) {
@@ -282,7 +282,7 @@ impl SubstrateTarget {
                 (val.into(), 1)
             }
             ast::PrimitiveType::Uint(n) | ast::PrimitiveType::Int(n) => {
-                let int_type = contract.context.custom_width_int_type(*n as u32);
+                let int_type = contract.context.custom_width_int_type(n as u32);
 
                 let store = to.unwrap_or_else(|| contract.builder.build_alloca(int_type, "stack"));
 
@@ -295,9 +295,9 @@ impl SubstrateTarget {
                     "",
                 );
 
-                let len = *n as u64 / 8;
+                let len = n as u64 / 8;
 
-                if *n <= 64 && to.is_none() {
+                if n <= 64 && to.is_none() {
                     (val, len)
                 } else {
                     contract.builder.build_store(store, val);
@@ -306,7 +306,7 @@ impl SubstrateTarget {
                 }
             }
             ast::PrimitiveType::Bytes(len) => {
-                let int_type = contract.context.custom_width_int_type(*len as u32 * 8);
+                let int_type = contract.context.custom_width_int_type(len as u32 * 8);
 
                 let store = to.unwrap_or_else(|| contract.builder.build_alloca(int_type, "stack"));
 
@@ -326,21 +326,19 @@ impl SubstrateTarget {
                         contract
                             .context
                             .i32_type()
-                            .const_int(*len as u64, false)
+                            .const_int(len as u64, false)
                             .into(),
                     ],
                     "",
                 );
 
-                if *len <= 8 && to.is_none() {
+                if len <= 8 && to.is_none() {
                     (
-                        contract
-                            .builder
-                            .build_load(store, &format!("bytes{}", *len)),
-                        *len as u64,
+                        contract.builder.build_load(store, &format!("bytes{}", len)),
+                        len as u64,
                     )
                 } else {
-                    (store.into(), *len as u64)
+                    (store.into(), len as u64)
                 }
             }
             ast::PrimitiveType::Address => {
@@ -388,7 +386,7 @@ impl SubstrateTarget {
     ) -> BasicValueEnum<'b> {
         match &ty {
             resolver::Type::Primitive(e) => {
-                let (arg, arglen) = self.decode_primitive(contract, &e, to, *data);
+                let (arg, arglen) = self.decode_primitive(contract, *e, to, *data);
 
                 *data = unsafe {
                     contract.builder.build_gep(
@@ -477,7 +475,7 @@ impl SubstrateTarget {
     fn encode_primitive(
         &self,
         contract: &Contract,
-        ty: &ast::PrimitiveType,
+        ty: ast::PrimitiveType,
         dest: PointerValue,
         val: BasicValueEnum,
     ) -> u64 {
@@ -517,7 +515,7 @@ impl SubstrateTarget {
                     val.into_int_value(),
                 );
 
-                *n as u64 / 8
+                n as u64 / 8
             }
             ast::PrimitiveType::Bytes(n) => {
                 let val = if val.is_pointer_value() {
@@ -548,13 +546,13 @@ impl SubstrateTarget {
                         contract
                             .context
                             .i32_type()
-                            .const_int(*n as u64, false)
+                            .const_int(n as u64, false)
                             .into(),
                     ],
                     "",
                 );
 
-                *n as u64
+                n as u64
             }
             ast::PrimitiveType::Address => {
                 // byte order needs to be reversed
@@ -597,7 +595,7 @@ impl SubstrateTarget {
     ) {
         match &ty {
             resolver::Type::Primitive(e) => {
-                let arglen = self.encode_primitive(contract, e, *data, arg);
+                let arglen = self.encode_primitive(contract, *e, *data, arg);
 
                 *data = unsafe {
                     contract.builder.build_gep(
@@ -608,7 +606,7 @@ impl SubstrateTarget {
                 };
             }
             resolver::Type::Enum(n) => {
-                self.encode_primitive(contract, &contract.ns.enums[*n].ty, *data, arg);
+                self.encode_primitive(contract, contract.ns.enums[*n].ty, *data, arg);
             }
             resolver::Type::FixedArray(_, dim) => {
                 contract.emit_static_loop(