@@ -38,7 +38,7 @@ pub(crate) fn convert_module_element(element: wasmparser::Element<'_>) -> Result
3838 . collect :: < Result < Vec < _ > > > ( ) ?
3939 . into_boxed_slice ( ) ;
4040
41- Ok ( tinywasm_types:: Element { kind, items, ty : convert_reftype ( & ty) , range : element. range } )
41+ Ok ( tinywasm_types:: Element { kind, items, ty : convert_reftype ( ty) , range : element. range } )
4242 }
4343 }
4444}
@@ -76,23 +76,23 @@ pub(crate) fn convert_module_import(import: wasmparser::Import<'_>) -> Result<Im
7676 kind : match import. ty {
7777 wasmparser:: TypeRef :: Func ( ty) => ImportKind :: Function ( ty) ,
7878 wasmparser:: TypeRef :: Table ( ty) => ImportKind :: Table ( TableType {
79- element_type : convert_reftype ( & ty. element_type ) ,
79+ element_type : convert_reftype ( ty. element_type ) ,
8080 size_initial : ty. initial . try_into ( ) . map_err ( |_| {
8181 crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size initial is too large: {}" , ty. initial) )
8282 } ) ?,
8383 size_max : match ty. maximum {
8484 Some ( max) => Some ( max. try_into ( ) . map_err ( |_| {
85- crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size max is too large: {}" , max ) )
85+ crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size max is too large: {max}" ) )
8686 } ) ?) ,
8787 None => None ,
8888 } ,
8989 } ) ,
90- wasmparser:: TypeRef :: Memory ( ty) => ImportKind :: Memory ( convert_module_memory ( ty) ? ) ,
90+ wasmparser:: TypeRef :: Memory ( ty) => ImportKind :: Memory ( convert_module_memory ( ty) ) ,
9191 wasmparser:: TypeRef :: Global ( ty) => {
9292 ImportKind :: Global ( GlobalType { mutable : ty. mutable , ty : convert_valtype ( & ty. content_type ) } )
9393 }
9494 wasmparser:: TypeRef :: Tag ( ty) => {
95- return Err ( crate :: ParseError :: UnsupportedOperator ( format ! ( "Unsupported import kind: {:?}" , ty ) ) )
95+ return Err ( crate :: ParseError :: UnsupportedOperator ( format ! ( "Unsupported import kind: {ty :?}" ) ) )
9696 }
9797 } ,
9898 } )
@@ -101,18 +101,15 @@ pub(crate) fn convert_module_import(import: wasmparser::Import<'_>) -> Result<Im
101101pub ( crate ) fn convert_module_memories < T : IntoIterator < Item = wasmparser:: Result < wasmparser:: MemoryType > > > (
102102 memory_types : T ,
103103) -> Result < Vec < MemoryType > > {
104- memory_types. into_iter ( ) . map ( |memory| convert_module_memory ( memory?) ) . collect :: < Result < Vec < _ > > > ( )
104+ memory_types. into_iter ( ) . map ( |memory| Ok ( convert_module_memory ( memory?) ) ) . collect :: < Result < Vec < _ > > > ( )
105105}
106106
107- pub ( crate ) fn convert_module_memory ( memory : wasmparser:: MemoryType ) -> Result < MemoryType > {
108- Ok ( MemoryType {
109- arch : match memory. memory64 {
110- true => MemoryArch :: I64 ,
111- false => MemoryArch :: I32 ,
112- } ,
107+ pub ( crate ) fn convert_module_memory ( memory : wasmparser:: MemoryType ) -> MemoryType {
108+ MemoryType {
109+ arch : if memory. memory64 { MemoryArch :: I64 } else { MemoryArch :: I32 } ,
113110 page_count_initial : memory. initial ,
114111 page_count_max : memory. maximum ,
115- } )
112+ }
116113}
117114
118115pub ( crate ) fn convert_module_tables < ' a , T : IntoIterator < Item = wasmparser:: Result < wasmparser:: Table < ' a > > > > (
@@ -129,12 +126,12 @@ pub(crate) fn convert_module_table(table: wasmparser::Table<'_>) -> Result<Table
129126 let size_max = match table. ty . maximum {
130127 Some ( max) => Some (
131128 max. try_into ( )
132- . map_err ( |_| crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size max is too large: {}" , max ) ) ) ?,
129+ . map_err ( |_| crate :: ParseError :: UnsupportedOperator ( format ! ( "Table size max is too large: {max}" ) ) ) ?,
133130 ) ,
134131 None => None ,
135132 } ;
136133
137- Ok ( TableType { element_type : convert_reftype ( & table. ty . element_type ) , size_initial, size_max } )
134+ Ok ( TableType { element_type : convert_reftype ( table. ty . element_type ) , size_initial, size_max } )
138135}
139136
140137pub ( crate ) fn convert_module_globals (
@@ -185,11 +182,11 @@ pub(crate) fn convert_module_code(
185182
186183 for i in 0 ..validator. len_locals ( ) {
187184 match validator. get_local_type ( i) {
188- Some ( wasmparser:: ValType :: I32 ) | Some ( wasmparser:: ValType :: F32 ) => {
185+ Some ( wasmparser:: ValType :: I32 | wasmparser:: ValType :: F32 ) => {
189186 local_addr_map. push ( local_counts. c32 ) ;
190187 local_counts. c32 += 1 ;
191188 }
192- Some ( wasmparser:: ValType :: I64 ) | Some ( wasmparser:: ValType :: F64 ) => {
189+ Some ( wasmparser:: ValType :: I64 | wasmparser:: ValType :: F64 ) => {
193190 local_addr_map. push ( local_counts. c64 ) ;
194191 local_counts. c64 += 1 ;
195192 }
@@ -225,7 +222,7 @@ pub(crate) fn convert_module_type(ty: wasmparser::RecGroup) -> Result<FuncType>
225222 Ok ( FuncType { params, results } )
226223}
227224
228- pub ( crate ) fn convert_reftype ( reftype : & wasmparser:: RefType ) -> ValType {
225+ pub ( crate ) fn convert_reftype ( reftype : wasmparser:: RefType ) -> ValType {
229226 match reftype {
230227 _ if reftype. is_func_ref ( ) => ValType :: RefFunc ,
231228 _ if reftype. is_extern_ref ( ) => ValType :: RefExtern ,
@@ -240,7 +237,7 @@ pub(crate) fn convert_valtype(valtype: &wasmparser::ValType) -> ValType {
240237 wasmparser:: ValType :: F32 => ValType :: F32 ,
241238 wasmparser:: ValType :: F64 => ValType :: F64 ,
242239 wasmparser:: ValType :: V128 => ValType :: V128 ,
243- wasmparser:: ValType :: Ref ( r) => convert_reftype ( r) ,
240+ wasmparser:: ValType :: Ref ( r) => convert_reftype ( * r) ,
244241 }
245242}
246243
@@ -260,7 +257,7 @@ pub(crate) fn process_const_operators(ops: OperatorsReader<'_>) -> Result<ConstI
260257 wasmparser:: Operator :: F32Const { value } => Ok ( ConstInstruction :: F32Const ( f32:: from_bits ( value. bits ( ) ) ) ) ,
261258 wasmparser:: Operator :: F64Const { value } => Ok ( ConstInstruction :: F64Const ( f64:: from_bits ( value. bits ( ) ) ) ) ,
262259 wasmparser:: Operator :: GlobalGet { global_index } => Ok ( ConstInstruction :: GlobalGet ( * global_index) ) ,
263- op => Err ( crate :: ParseError :: UnsupportedOperator ( format ! ( "Unsupported const instruction: {:?}" , op ) ) ) ,
260+ op => Err ( crate :: ParseError :: UnsupportedOperator ( format ! ( "Unsupported const instruction: {op :?}" ) ) ) ,
264261 }
265262}
266263
0 commit comments