diff --git a/sway-core/src/abi_generation/evm_abi.rs b/sway-core/src/abi_generation/evm_abi.rs index fbf273aff51..ed5fc5af0fb 100644 --- a/sway-core/src/abi_generation/evm_abi.rs +++ b/sway-core/src/abi_generation/evm_abi.rs @@ -186,7 +186,7 @@ pub fn abi_param_type( } } -pub(self) fn generate_abi_function( +fn generate_abi_function( fn_decl: &TyFunctionDecl, type_engine: &TypeEngine, decl_engine: &DeclEngine, @@ -230,7 +230,7 @@ pub(self) fn generate_abi_function( }) } -pub(self) fn abi_str_type_arg( +fn abi_str_type_arg( type_arg: &TypeArgument, type_engine: &TypeEngine, decl_engine: &DeclEngine, diff --git a/sway-core/src/asm_generation/fuel/data_section.rs b/sway-core/src/asm_generation/fuel/data_section.rs index 8df1b89dc9d..8706aac2cbc 100644 --- a/sway-core/src/asm_generation/fuel/data_section.rs +++ b/sway-core/src/asm_generation/fuel/data_section.rs @@ -128,7 +128,7 @@ impl Entry { Datum::ByteArray(bs) if bs.len() % 8 == 0 => bs.clone(), Datum::ByteArray(bs) => bs .iter() - .chain(vec![0; 8].iter()) + .chain([0; 8].iter()) .copied() .take((bs.len() + 7) & 0xfffffff8_usize) .collect(), diff --git a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs index eaa2cb64fbd..0d300d5d4b7 100644 --- a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs +++ b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs @@ -152,10 +152,11 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { ) -> Result<(), ErrorEmitted> { let Some(instruction) = instr_val.get_instruction(self.context) else { return Err(handler.emit_err(CompileError::Internal( - "Value not an instruction.", - self.md_mgr - .val_to_span(self.context, *instr_val) - .unwrap_or_else(Span::dummy), ))); + "Value not an instruction.", + self.md_mgr + .val_to_span(self.context, *instr_val) + .unwrap_or_else(Span::dummy), + ))); }; // The only instruction whose compilation returns a Result itself is AsmBlock, which @@ -697,101 +698,96 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { // until then we can keep track of the constant values and add them once. let base_reg = self.value_to_register(base_val)?; - let (base_reg, const_offs, _) = - indices - .iter() - .fold(Ok((base_reg, 0, base_type)), |acc, idx_val| { - // So we're folding to a Result, as unwrapping the constants can fail. - acc.and_then(|(reg, offs, elem_ty)| { - // If we find a constant index then we add its offset to `offs`. Otherwise we grab - // its value, which should be compiled already, and add it to reg. - if elem_ty.is_struct(self.context) { - // For structs the index must be a const uint. - unwrap_constant_uint(idx_val).map(|idx| { - let field_types = elem_ty.get_field_types(self.context); - let field_type = field_types[idx]; - let field_offs_in_bytes = field_types - .iter() - .take(idx) - .map(|field_ty| ir_type_size_in_bytes(self.context, field_ty)) - .sum::(); - (reg, offs + field_offs_in_bytes, field_type) - }) - } else if elem_ty.is_union(self.context) { - // For unions the index must also be a const uint. - unwrap_constant_uint(idx_val).map(|idx| { - let field_type = elem_ty.get_field_types(self.context)[idx]; - let union_size_in_bytes = - ir_type_size_in_bytes(self.context, &elem_ty); - let field_size_in_bytes = - ir_type_size_in_bytes(self.context, &field_type); - - // The union fields are at offset (union_size - variant_size) due to left padding. - ( - reg, - offs + union_size_in_bytes - field_size_in_bytes, - field_type, - ) - }) - } else if elem_ty.is_array(self.context) { - // For arrays the index is a value. We need to fetch it and add it to - // the base. - let array_elem_ty = - elem_ty.get_array_elem_type(self.context).ok_or_else(|| { - CompileError::Internal( - "Failed to get elem type for known array", - owning_span.clone().unwrap_or_else(Span::dummy), - ) - })?; - let array_elem_size = - ir_type_size_in_bytes(self.context, &array_elem_ty); - let size_reg = self.reg_seqr.next(); - self.immediate_to_reg( - array_elem_size, - size_reg.clone(), - None, - "get size of element", - owning_span.clone(), - ); - - let index_reg = self.value_to_register(idx_val)?; - let offset_reg = self.reg_seqr.next(); - - self.cur_bytecode.push(Op { - opcode: Either::Left(VirtualOp::MUL( - offset_reg.clone(), - index_reg, - size_reg, - )), - comment: "get offset to array element".into(), - owning_span: owning_span.clone(), - }); - self.cur_bytecode.push(Op { - opcode: Either::Left(VirtualOp::ADD( - offset_reg.clone(), - reg, - offset_reg.clone(), - )), - comment: "add to array base".into(), - owning_span: owning_span.clone(), - }); - let member_type = - elem_ty.get_array_elem_type(self.context).ok_or_else(|| { - CompileError::Internal( - "Can't get array elem type for GEP.", - sway_types::span::Span::dummy(), - ) - })?; - - Ok((offset_reg, offs, member_type)) - } else { - Err(CompileError::Internal( - "Cannot get element offset in non-aggregate.", - sway_types::span::Span::dummy(), - )) - } + let (base_reg, const_offs, _) = indices.iter().try_fold( + (base_reg, 0, base_type), + |(reg, offs, elem_ty), idx_val| { + // So we're folding to a Result, as unwrapping the constants can fail. + // If we find a constant index then we add its offset to `offs`. Otherwise we grab + // its value, which should be compiled already, and add it to reg. + if elem_ty.is_struct(self.context) { + // For structs the index must be a const uint. + unwrap_constant_uint(idx_val).map(|idx| { + let field_types = elem_ty.get_field_types(self.context); + let field_type = field_types[idx]; + let field_offs_in_bytes = field_types + .iter() + .take(idx) + .map(|field_ty| ir_type_size_in_bytes(self.context, field_ty)) + .sum::(); + (reg, offs + field_offs_in_bytes, field_type) }) - })?; + } else if elem_ty.is_union(self.context) { + // For unions the index must also be a const uint. + unwrap_constant_uint(idx_val).map(|idx| { + let field_type = elem_ty.get_field_types(self.context)[idx]; + let union_size_in_bytes = ir_type_size_in_bytes(self.context, &elem_ty); + let field_size_in_bytes = ir_type_size_in_bytes(self.context, &field_type); + + // The union fields are at offset (union_size - variant_size) due to left padding. + ( + reg, + offs + union_size_in_bytes - field_size_in_bytes, + field_type, + ) + }) + } else if elem_ty.is_array(self.context) { + // For arrays the index is a value. We need to fetch it and add it to + // the base. + let array_elem_ty = + elem_ty.get_array_elem_type(self.context).ok_or_else(|| { + CompileError::Internal( + "Failed to get elem type for known array", + owning_span.clone().unwrap_or_else(Span::dummy), + ) + })?; + let array_elem_size = ir_type_size_in_bytes(self.context, &array_elem_ty); + let size_reg = self.reg_seqr.next(); + self.immediate_to_reg( + array_elem_size, + size_reg.clone(), + None, + "get size of element", + owning_span.clone(), + ); + + let index_reg = self.value_to_register(idx_val)?; + let offset_reg = self.reg_seqr.next(); + + self.cur_bytecode.push(Op { + opcode: Either::Left(VirtualOp::MUL( + offset_reg.clone(), + index_reg, + size_reg, + )), + comment: "get offset to array element".into(), + owning_span: owning_span.clone(), + }); + self.cur_bytecode.push(Op { + opcode: Either::Left(VirtualOp::ADD( + offset_reg.clone(), + reg, + offset_reg.clone(), + )), + comment: "add to array base".into(), + owning_span: owning_span.clone(), + }); + let member_type = + elem_ty.get_array_elem_type(self.context).ok_or_else(|| { + CompileError::Internal( + "Can't get array elem type for GEP.", + sway_types::span::Span::dummy(), + ) + })?; + + Ok((offset_reg, offs, member_type)) + } else { + Err(CompileError::Internal( + "Cannot get element offset in non-aggregate.", + sway_types::span::Span::dummy(), + )) + } + }, + )?; if const_offs == 0 { // No need to add anything. diff --git a/sway-core/src/asm_generation/fuel/register_allocator.rs b/sway-core/src/asm_generation/fuel/register_allocator.rs index 6a00c00170b..57395d31505 100644 --- a/sway-core/src/asm_generation/fuel/register_allocator.rs +++ b/sway-core/src/asm_generation/fuel/register_allocator.rs @@ -235,7 +235,7 @@ pub(crate) fn create_interference_graph( .fold(BTreeSet::new(), |mut tree, elem| { let mut regs = elem.registers(); regs.retain(|®| reg.is_virtual()); - tree.extend(regs.into_iter()); + tree.extend(regs); tree }) .iter() diff --git a/sway-core/src/asm_generation/miden_vm/miden_vm_asm_builder.rs b/sway-core/src/asm_generation/miden_vm/miden_vm_asm_builder.rs index 83bf6c8441e..08254a79d31 100644 --- a/sway-core/src/asm_generation/miden_vm/miden_vm_asm_builder.rs +++ b/sway-core/src/asm_generation/miden_vm/miden_vm_asm_builder.rs @@ -171,7 +171,7 @@ impl<'ir, 'eng> MidenVMAsmBuilder<'ir, 'eng> { fn copy_contract_code_to_memory( &self, - s: &mut MidenVMAsmSection, + s: &MidenVMAsmSection, data_size: u32, data_offset: u32, ) { diff --git a/sway-core/src/asm_generation/programs/abstract.rs b/sway-core/src/asm_generation/programs/abstract.rs index cb52a9ab7de..e1320419e10 100644 --- a/sway-core/src/asm_generation/programs/abstract.rs +++ b/sway-core/src/asm_generation/programs/abstract.rs @@ -64,7 +64,7 @@ impl AbstractProgram { .entries .into_iter() .map(|entry| entry.ops) - .chain(self.non_entries.into_iter()) + .chain(self.non_entries) .map(AbstractInstructionSet::optimize) .map(AbstractInstructionSet::verify) .collect::, _>>()?; diff --git a/sway-core/src/asm_generation/programs/final.rs b/sway-core/src/asm_generation/programs/final.rs index 62c6b78f967..cbf357f3a2d 100644 --- a/sway-core/src/asm_generation/programs/final.rs +++ b/sway-core/src/asm_generation/programs/final.rs @@ -80,10 +80,7 @@ impl std::fmt::Display for FinalProgram { .collect::>(); separator.push_all(concretized_ops); - let basic_blocks = separator - .take() - .into_iter() - .chain(separator.finish().into_iter()); + let basic_blocks = separator.take().into_iter().chain(separator.finish()); for block in basic_blocks { let mut offset = block.offset; diff --git a/sway-core/src/decl_engine/id.rs b/sway-core/src/decl_engine/id.rs index 6eefe6e9953..78e6d056b0e 100644 --- a/sway-core/src/decl_engine/id.rs +++ b/sway-core/src/decl_engine/id.rs @@ -29,7 +29,7 @@ impl DeclId { impl Copy for DeclId {} impl Clone for DeclId { fn clone(&self) -> Self { - Self(self.0, PhantomData) + *self } } @@ -46,7 +46,7 @@ impl PartialEq for DeclId { } impl PartialOrd for DeclId { fn partial_cmp(&self, other: &Self) -> Option { - self.0.partial_cmp(&other.0) + Some(self.cmp(other)) } } impl Ord for DeclId { diff --git a/sway-core/src/ir_generation/function.rs b/sway-core/src/ir_generation/function.rs index a93ef16451a..e4fa51ad64b 100644 --- a/sway-core/src/ir_generation/function.rs +++ b/sway-core/src/ir_generation/function.rs @@ -1138,7 +1138,7 @@ impl<'eng> FnCompiler<'eng> { .add_metadatum(context, span_md_idx); compiled_args .into_iter() - .zip(field_types.into_iter()) + .zip(field_types) .enumerate() .for_each(|(insert_idx, (field_val, field_type))| { let gep_val = self @@ -2133,7 +2133,7 @@ impl<'eng> FnCompiler<'eng> { // Fill it in. insert_values .into_iter() - .zip(field_types.into_iter()) + .zip(field_types) .enumerate() .for_each(|(insert_idx, (insert_val, field_type))| { let gep_val = self.current_block.ins(context).get_elem_ptr_with_idx( @@ -2328,7 +2328,7 @@ impl<'eng> FnCompiler<'eng> { init_values .into_iter() - .zip(init_types.into_iter()) + .zip(init_types) .enumerate() .for_each(|(insert_idx, (field_val, field_type))| { let gep_val = self diff --git a/sway-core/src/language/parsed/expression/scrutinee.rs b/sway-core/src/language/parsed/expression/scrutinee.rs index e9e93a7dc0e..f5a84a0d6de 100644 --- a/sway-core/src/language/parsed/expression/scrutinee.rs +++ b/sway-core/src/language/parsed/expression/scrutinee.rs @@ -151,7 +151,7 @@ impl Scrutinee { _ => vec![], }) .collect::>(); - vec![name, fields].concat() + [name, fields].concat() } Scrutinee::EnumScrutinee { call_path, value, .. @@ -162,7 +162,7 @@ impl Scrutinee { type_arguments: None, }]; let value = value.gather_approximate_typeinfo_dependencies(); - vec![name, value].concat() + [name, value].concat() } Scrutinee::Tuple { elems, .. } | Scrutinee::Or { elems, .. } => elems .iter() diff --git a/sway-core/src/language/ty/expression/expression_variant.rs b/sway-core/src/language/ty/expression/expression_variant.rs index 652c29ecb36..e23025eb733 100644 --- a/sway-core/src/language/ty/expression/expression_variant.rs +++ b/sway-core/src/language/ty/expression/expression_variant.rs @@ -1089,7 +1089,7 @@ impl UpdateConstantExpression for TyExpressionVariant { fn find_const_decl_from_impl( implementing_type: &TyDecl, decl_engine: &DeclEngine, - const_decl: &mut Box, + const_decl: &TyConstantDecl, ) -> Option { match implementing_type { TyDecl::ImplTrait(ImplTrait { decl_id, .. }) => { diff --git a/sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/pattern.rs b/sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/pattern.rs index e996c836dc7..59f99521ae4 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/pattern.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/match_expression/analysis/pattern.rs @@ -402,7 +402,7 @@ impl Pattern { fields: struct_pattern .fields .iter() - .zip(args.into_iter()) + .zip(args) .map(|((name, _), arg)| (name.clone(), arg)) .collect::>(), }) diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs index c2be1c070fc..7a83f703851 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression.rs @@ -83,7 +83,7 @@ impl ty::TyExpression { let args_and_names = method .parameters .into_iter() - .zip(arguments.into_iter()) + .zip(arguments) .map(|(param, arg)| (param.name, arg)) .collect::>(); let exp = ty::TyExpression { diff --git a/sway-core/src/semantic_analysis/namespace/trait_map.rs b/sway-core/src/semantic_analysis/namespace/trait_map.rs index f0ce7e1234c..4a67366fb0f 100644 --- a/sway-core/src/semantic_analysis/namespace/trait_map.rs +++ b/sway-core/src/semantic_analysis/namespace/trait_map.rs @@ -407,7 +407,7 @@ impl TraitMap { Ok(pos) => self.trait_impls[pos] .value .trait_items - .extend(oe.value.trait_items.into_iter()), + .extend(oe.value.trait_items), Err(pos) => self.trait_impls.insert(pos, oe), } } diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index bb5a13a4aab..f44747832ed 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -1599,7 +1599,7 @@ fn method_call_fields_to_method_application_expression( .collect::>()?, }; let arguments = iter::once(*target) - .chain(args.into_inner().into_iter()) + .chain(args.into_inner()) .map(|expr| expr_to_expression(context, handler, engines, expr)) .collect::>()?; Ok(Box::new(MethodApplicationExpression { @@ -4140,7 +4140,7 @@ fn error_if_self_param_is_not_allowed( /// Walks all the cfg attributes in a map, evaluating them /// and returning false if any evaluated to false. pub fn cfg_eval( - context: &mut Context, + context: &Context, handler: &Handler, attrs_map: &AttributesMap, ) -> Result { diff --git a/sway-core/src/type_system/substitute/subst_map.rs b/sway-core/src/type_system/substitute/subst_map.rs index 81b46425b92..56e192b5387 100644 --- a/sway-core/src/type_system/substitute/subst_map.rs +++ b/sway-core/src/type_system/substitute/subst_map.rs @@ -289,10 +289,7 @@ impl TypeSubstMap { type_parameters: Vec, type_arguments: Vec, ) -> TypeSubstMap { - let mapping = type_parameters - .into_iter() - .zip(type_arguments.into_iter()) - .collect(); + let mapping = type_parameters.into_iter().zip(type_arguments).collect(); TypeSubstMap { mapping } } diff --git a/sway-ir/src/analysis/dominator.rs b/sway-ir/src/analysis/dominator.rs index f033a70fa24..787d04a9350 100644 --- a/sway-ir/src/analysis/dominator.rs +++ b/sway-ir/src/analysis/dominator.rs @@ -147,9 +147,9 @@ fn compute_dom_tree( .pred_iter(context) .filter(|p| **p != picked_pred && po.block_to_po.contains_key(p)) { - if matches!(dom_tree[p].parent, Some(_)) { + if dom_tree[p].parent.is_some() { // if doms[p] already calculated - new_idom = intersect(po, &mut dom_tree, *p, new_idom); + new_idom = intersect(po, &dom_tree, *p, new_idom); } } let b_node = dom_tree.get_mut(b).unwrap(); @@ -167,7 +167,7 @@ fn compute_dom_tree( // using the partially computed dominator tree. fn intersect( po: &PostOrder, - dom_tree: &mut DomTree, + dom_tree: &DomTree, mut finger1: Block, mut finger2: Block, ) -> Block { diff --git a/sway-ir/src/irtype.rs b/sway-ir/src/irtype.rs index 0e88a4cc5a0..b463d5c1ba1 100644 --- a/sway-ir/src/irtype.rs +++ b/sway-ir/src/irtype.rs @@ -287,11 +287,9 @@ impl Type { return None; } - indices.iter().fold(Some(*self), |ty, idx| { - ty.and_then(|ty| { - ty.get_field_type(context, *idx) - .or_else(|| ty.get_array_elem_type(context)) - }) + indices.iter().try_fold(*self, |ty, idx| { + ty.get_field_type(context, *idx) + .or_else(|| ty.get_array_elem_type(context)) }) } @@ -300,7 +298,7 @@ impl Type { pub fn get_indexed_offset(&self, context: &Context, indices: &[Value]) -> Option { indices .iter() - .fold(Some((*self, 0)), |ty, idx| { + .try_fold((*self, 0), |(ty, accum_offset), idx| { let Some(Constant { value: ConstantValue::Uint(idx), ty: _, @@ -308,35 +306,33 @@ impl Type { else { return None; }; - ty.and_then(|(ty, accum_offset)| { - if ty.is_struct(context) { - // Sum up all sizes of all previous fields. - let prev_idxs_offset = (0..(*idx)).try_fold(0, |accum, pre_idx| { - ty.get_field_type(context, pre_idx) - .map(|field_ty| field_ty.size_in_bytes(context) + accum) - })?; - ty.get_field_type(context, *idx) - .map(|field_ty| (field_ty, accum_offset + prev_idxs_offset)) - } else if ty.is_union(context) { - ty.get_field_type(context, *idx) - .map(|field_ty| (field_ty, accum_offset)) - } else { - assert!( - ty.is_array(context), - "Expected aggregate type when indexing using GEP. Got {}", - ty.as_string(context) - ); - // size_of_element * idx will be the offset of idx. - ty.get_array_elem_type(context).map(|elm_ty| { - let prev_idxs_offset = ty - .get_array_elem_type(context) - .unwrap() - .size_in_bytes(context) - * idx; - (elm_ty, accum_offset + prev_idxs_offset) - }) - } - }) + if ty.is_struct(context) { + // Sum up all sizes of all previous fields. + let prev_idxs_offset = (0..(*idx)).try_fold(0, |accum, pre_idx| { + ty.get_field_type(context, pre_idx) + .map(|field_ty| field_ty.size_in_bytes(context) + accum) + })?; + ty.get_field_type(context, *idx) + .map(|field_ty| (field_ty, accum_offset + prev_idxs_offset)) + } else if ty.is_union(context) { + ty.get_field_type(context, *idx) + .map(|field_ty| (field_ty, accum_offset)) + } else { + assert!( + ty.is_array(context), + "Expected aggregate type when indexing using GEP. Got {}", + ty.as_string(context) + ); + // size_of_element * idx will be the offset of idx. + ty.get_array_elem_type(context).map(|elm_ty| { + let prev_idxs_offset = ty + .get_array_elem_type(context) + .unwrap() + .size_in_bytes(context) + * idx; + (elm_ty, accum_offset + prev_idxs_offset) + }) + } }) .map(|pair| pair.1) } diff --git a/sway-ir/src/optimize/dce.rs b/sway-ir/src/optimize/dce.rs index ec4617abc96..b7aa8821db5 100644 --- a/sway-ir/src/optimize/dce.rs +++ b/sway-ir/src/optimize/dce.rs @@ -67,7 +67,7 @@ fn get_loaded_symbols(context: &Context, val: Value) -> Vec { coins, asset_id, .. - } => vec![*params, *coins, *asset_id] + } => [*params, *coins, *asset_id] .iter() .flat_map(|val| get_symbols(context, *val).to_vec()) .collect(), diff --git a/sway-ir/src/optimize/memcpyopt.rs b/sway-ir/src/optimize/memcpyopt.rs index c9bb95f34ec..8bc5a855fe9 100644 --- a/sway-ir/src/optimize/memcpyopt.rs +++ b/sway-ir/src/optimize/memcpyopt.rs @@ -420,7 +420,7 @@ fn local_copy_prop( escaped_symbols: &EscapedSymbols, inst: Value, src_val_ptr: Value, - dest_to_copies: &mut FxHashMap>, + dest_to_copies: &FxHashMap>, replacements: &mut FxHashMap, ) -> bool { // For every `memcpy` that src_val_ptr is a destination of, @@ -566,7 +566,7 @@ fn local_copy_prop( escaped_symbols, inst, *src_val_ptr, - &mut dest_to_copies, + &dest_to_copies, &mut replacements, ); } @@ -587,7 +587,7 @@ fn local_copy_prop( escaped_symbols, inst, src_val_ptr, - &mut dest_to_copies, + &dest_to_copies, &mut replacements, ) { gen_new_copy( diff --git a/sway-ir/src/parser.rs b/sway-ir/src/parser.rs index 4c17c15b640..e58ac08c116 100644 --- a/sway-ir/src/parser.rs +++ b/sway-ir/src/parser.rs @@ -885,10 +885,10 @@ mod ir_builder { ) -> Result { let mut ctx = Context::new(source_engine); let md_map = build_metadata_map(&mut ctx, ir_ast_mod.metadata); - let mut module = Module::new(&mut ctx, ir_ast_mod.kind); + let module = Module::new(&mut ctx, ir_ast_mod.kind); let mut builder = IrBuilder { module, - configs_map: build_configs_map(&mut ctx, &mut module, ir_ast_mod.configs, &md_map), + configs_map: build_configs_map(&mut ctx, &module, ir_ast_mod.configs, &md_map), md_map, unresolved_calls: Vec::new(), }; @@ -1358,7 +1358,7 @@ mod ir_builder { fn build_configs_map( context: &mut Context, - module: &mut Module, + module: &Module, ir_configs: Vec, md_map: &HashMap, ) -> HashMap { diff --git a/sway-ir/src/verify.rs b/sway-ir/src/verify.rs index 94da9de6d9a..3f8b080a6cc 100644 --- a/sway-ir/src/verify.rs +++ b/sway-ir/src/verify.rs @@ -547,20 +547,18 @@ impl<'a, 'eng> InstructionVerifier<'a, 'eng> { // unwrap it and try to fetch the field type (which will fail for arrays) otherwise (i.e., // not a constant int or not a struct) fetch the array element type, which will fail for // non-arrays. - let index_ty = indices.iter().fold(Some(base_ty), |ty, idx_val| { - ty.and_then(|ty| { - idx_val - .get_constant(self.context) - .and_then(|const_ref| { - if let ConstantValue::Uint(n) = const_ref.value { - Some(n) - } else { - None - } - }) - .and_then(|idx| ty.get_field_type(self.context, idx)) - .or_else(|| ty.get_array_elem_type(self.context)) - }) + let index_ty = indices.iter().try_fold(base_ty, |ty, idx_val| { + idx_val + .get_constant(self.context) + .and_then(|const_ref| { + if let ConstantValue::Uint(n) = const_ref.value { + Some(n) + } else { + None + } + }) + .and_then(|idx| ty.get_field_type(self.context, idx)) + .or_else(|| ty.get_array_elem_type(self.context)) }); if self.opt_ty_not_eq(&Some(elem_inner_ty), &index_ty) { diff --git a/sway-lsp/src/handlers/request.rs b/sway-lsp/src/handlers/request.rs index 50e70fab708..a4defe00366 100644 --- a/sway-lsp/src/handlers/request.rs +++ b/sway-lsp/src/handlers/request.rs @@ -426,12 +426,7 @@ pub(crate) fn on_enter( { Ok((uri, session)) => { // handle on_enter capabilities if they are enabled - Ok(capabilities::on_enter( - &config, - &session, - &uri.clone(), - ¶ms, - )) + Ok(capabilities::on_enter(&config, &session, &uri, ¶ms)) } Err(err) => { tracing::error!("{}", err.to_string()); diff --git a/swayfmt/src/utils/language/expr/mod.rs b/swayfmt/src/utils/language/expr/mod.rs index a6062ccaf5e..6e0d51a8a12 100644 --- a/swayfmt/src/utils/language/expr/mod.rs +++ b/swayfmt/src/utils/language/expr/mod.rs @@ -609,7 +609,7 @@ pub(super) fn debug_expr( field_width: Option, body_width: Option, expr_width: usize, - formatter: &mut Formatter, + formatter: &Formatter, ) { println!( "DEBUG:\nline: {buf}\nfield: {:?}, body: {:?}, expr: {expr_width}, Shape::width: {}",