diff --git a/etk-analyze/src/cfg.rs b/etk-analyze/src/cfg.rs index d52cbb87..2387efb1 100644 --- a/etk-analyze/src/cfg.rs +++ b/etk-analyze/src/cfg.rs @@ -368,14 +368,14 @@ mod tests { let connected = self .connected .into_iter() - .map(|x| x.borrow().clone()) + .map(|x| *x.borrow()) .map(|(f, t)| Self::find_nodes(&cfg, f, t)) .map(|(f, t)| (f, t, true)); let unconnected = self .unconnected .into_iter() - .map(|x| x.borrow().clone()) + .map(|x| *x.borrow()) .map(|(f, t)| Self::find_nodes(&cfg, f, t)) .map(|(f, t)| (f, t, false)); diff --git a/etk-analyze/src/sym.rs b/etk-analyze/src/sym.rs index 80087233..d7814bde 100644 --- a/etk-analyze/src/sym.rs +++ b/etk-analyze/src/sym.rs @@ -45,7 +45,7 @@ impl<'z> Z3Visit<'z> { } fn make_var(&self, var: &Var) -> BV<'z> { - let name = format!("etk_{}", var); + let name = format!("etk_{var}"); BV::new_const(self.context, name, 256) } @@ -461,7 +461,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[1]).add(&Expr::constant(&[2])); + let expr = Expr::constant([1]).add(&Expr::constant([2])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(3)); } @@ -471,7 +471,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[1]).add(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([1]).add(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0)); } @@ -481,7 +481,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).sub(&Expr::constant(&[2])); + let expr = Expr::constant([3]).sub(&Expr::constant([2])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(1)); } @@ -491,7 +491,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).sub(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([3]).sub(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(4)); } @@ -501,7 +501,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).mul(&Expr::constant(&[4])); + let expr = Expr::constant([3]).mul(&Expr::constant([4])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(12)); } @@ -511,7 +511,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0xff; 32]).mul(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([0xff; 32]).mul(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(1)); } @@ -521,7 +521,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0xff; 32]).div(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([0xff; 32]).div(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(1)); } @@ -531,7 +531,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[1]).div(&Expr::constant(&[0])); + let expr = Expr::constant([1]).div(&Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0)); } @@ -541,7 +541,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0]).div(&Expr::constant(&[0])); + let expr = Expr::constant([0]).div(&Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0)); } @@ -551,7 +551,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0]).div(&Expr::constant(&[1])); + let expr = Expr::constant([0]).div(&Expr::constant([1])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0)); } @@ -561,7 +561,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0xff; 32]).s_div(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([0xff; 32]).s_div(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(1)); } @@ -571,7 +571,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0]).s_div(&Expr::constant(&[0])); + let expr = Expr::constant([0]).s_div(&Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0)); } @@ -581,10 +581,10 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[1]).s_div(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([1]).s_div(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); - let expected = Expr::constant(&[0xff; 32]).to_z3(&ctx); + let expected = Expr::constant([0xff; 32]).to_z3(&ctx); assert_eq!(ast, expected); } @@ -594,7 +594,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).modulo(&Expr::constant(&[2])); + let expr = Expr::constant([3]).modulo(&Expr::constant([2])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); @@ -607,7 +607,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).modulo(&Expr::constant(&[0])); + let expr = Expr::constant([3]).modulo(&Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); @@ -620,7 +620,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[1]).modulo(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([1]).modulo(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); @@ -633,7 +633,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0xff; 32]).modulo(&Expr::constant(&[1])); + let expr = Expr::constant([0xff; 32]).modulo(&Expr::constant([1])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); @@ -646,7 +646,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0]).s_modulo(&Expr::constant(&[0])); + let expr = Expr::constant([0]).s_modulo(&Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0)); } @@ -656,7 +656,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[1]).s_modulo(&Expr::constant(&[0])); + let expr = Expr::constant([1]).s_modulo(&Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0)); } @@ -669,9 +669,9 @@ mod tests { let mut neg_two = [0xff; 32]; neg_two[31] = 0xfe; - let expr = Expr::constant(&[0xff; 32]).s_modulo(&Expr::constant(&neg_two)); + let expr = Expr::constant([0xff; 32]).s_modulo(&Expr::constant(neg_two)); let ast = expr.to_z3(&ctx).simplify(); - let expected = Expr::constant(&[0xff; 32]).to_z3(&ctx); + let expected = Expr::constant([0xff; 32]).to_z3(&ctx); assert_eq!(ast, expected); } @@ -683,7 +683,7 @@ mod tests { let mut neg_two = [0xff; 32]; neg_two[31] = 0xfe; - let expr = Expr::constant(&neg_two).s_modulo(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant(neg_two).s_modulo(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0)); } @@ -693,7 +693,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).exp(&Expr::constant(&[4])); + let expr = Expr::constant([3]).exp(&Expr::constant([4])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(0x51)); } @@ -703,7 +703,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).exp(&Expr::constant(&[0])); + let expr = Expr::constant([3]).exp(&Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); assert_eq!(ast.as_u64(), Some(1)); } @@ -713,7 +713,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0xff; 32]).exp(&Expr::constant(&[2])); + let expr = Expr::constant([0xff; 32]).exp(&Expr::constant([2])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); @@ -728,7 +728,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[2]).lt(&Expr::constant(&[3])); + let expr = Expr::constant([2]).lt(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -739,7 +739,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).lt(&Expr::constant(&[2])); + let expr = Expr::constant([3]).lt(&Expr::constant([2])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -750,7 +750,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).lt(&Expr::constant(&[3])); + let expr = Expr::constant([3]).lt(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -761,7 +761,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[2]).gt(&Expr::constant(&[3])); + let expr = Expr::constant([2]).gt(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -772,7 +772,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).gt(&Expr::constant(&[2])); + let expr = Expr::constant([3]).gt(&Expr::constant([2])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -783,7 +783,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).gt(&Expr::constant(&[3])); + let expr = Expr::constant([3]).gt(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -794,7 +794,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[2]).s_gt(&Expr::constant(&[3])); + let expr = Expr::constant([2]).s_gt(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -805,7 +805,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).s_gt(&Expr::constant(&[2])); + let expr = Expr::constant([3]).s_gt(&Expr::constant([2])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -816,7 +816,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).s_gt(&Expr::constant(&[3])); + let expr = Expr::constant([3]).s_gt(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -827,7 +827,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).s_gt(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([3]).s_gt(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -838,7 +838,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[2]).s_lt(&Expr::constant(&[3])); + let expr = Expr::constant([2]).s_lt(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -849,7 +849,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).s_lt(&Expr::constant(&[2])); + let expr = Expr::constant([3]).s_lt(&Expr::constant([2])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -860,7 +860,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).s_lt(&Expr::constant(&[3])); + let expr = Expr::constant([3]).s_lt(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -871,7 +871,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).s_lt(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([3]).s_lt(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -882,7 +882,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).is_eq(&Expr::constant(&[3])); + let expr = Expr::constant([3]).is_eq(&Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -893,7 +893,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).is_eq(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([3]).is_eq(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -904,7 +904,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).and(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([3]).and(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 3, 256); assert_eq!(ast, expected); @@ -915,7 +915,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).and(&Expr::constant(&[1])); + let expr = Expr::constant([3]).and(&Expr::constant([1])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -926,9 +926,9 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).or(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([3]).or(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); - let expected = Expr::constant(&[0xff; 32]).to_z3(&ctx); + let expected = Expr::constant([0xff; 32]).to_z3(&ctx); assert_eq!(ast, expected); } @@ -937,7 +937,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[4]).or(&Expr::constant(&[1])); + let expr = Expr::constant([4]).or(&Expr::constant([1])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 5, 256); assert_eq!(ast, expected); @@ -948,7 +948,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[3]).xor(&Expr::constant(&[1])); + let expr = Expr::constant([3]).xor(&Expr::constant([1])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 2, 256); assert_eq!(ast, expected); @@ -962,7 +962,7 @@ mod tests { let value: [_; 32] = hex!("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"); - let expr = Expr::constant(&[32]).byte(&Expr::constant(&value)); + let expr = Expr::constant([32]).byte(&Expr::constant(value)); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0x0, 256); assert_eq!(ast, expected); @@ -976,7 +976,7 @@ mod tests { let value: [_; 32] = hex!("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"); - let expr = Expr::constant(&[31]).byte(&Expr::constant(&value)); + let expr = Expr::constant([31]).byte(&Expr::constant(value)); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0xff, 256); assert_eq!(ast, expected); @@ -990,7 +990,7 @@ mod tests { let value: [_; 32] = hex!("00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"); - let expr = Expr::constant(&[30]).byte(&Expr::constant(&value)); + let expr = Expr::constant([30]).byte(&Expr::constant(value)); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0xee, 256); assert_eq!(ast, expected); @@ -1004,7 +1004,7 @@ mod tests { let value: [_; 32] = hex!("AB112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"); - let expr = Expr::constant(&[0]).byte(&Expr::constant(&value)); + let expr = Expr::constant([0]).byte(&Expr::constant(value)); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0xab, 256); assert_eq!(ast, expected); @@ -1015,7 +1015,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[4]).shl(&Expr::constant(&[1])); + let expr = Expr::constant([4]).shl(&Expr::constant([1])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0x10, 256); assert_eq!(ast, expected); @@ -1032,7 +1032,7 @@ mod tests { value[2] = 0x72; value[3] = 0xdd; - let expr = Expr::constant(&[224]).shr(&Expr::constant(&value)); + let expr = Expr::constant([224]).shr(&Expr::constant(value)); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0x23b872dd, 256); assert_eq!(ast, expected); @@ -1043,7 +1043,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[248]).shr(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([248]).shr(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0xff, 256); assert_eq!(ast, expected); @@ -1054,9 +1054,9 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[248]).sar(&Expr::constant(&[0xff; 32])); + let expr = Expr::constant([248]).sar(&Expr::constant([0xff; 32])); let ast = expr.to_z3(&ctx).simplify(); - let expected = Expr::constant(&[0xff; 32]).to_z3(&ctx); + let expected = Expr::constant([0xff; 32]).to_z3(&ctx); assert_eq!(ast, expected); } @@ -1065,7 +1065,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[1]).sar(&Expr::constant(&[1])); + let expr = Expr::constant([1]).sar(&Expr::constant([1])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -1076,7 +1076,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[1]).is_zero(); + let expr = Expr::constant([1]).is_zero(); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -1087,7 +1087,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0]).is_zero(); + let expr = Expr::constant([0]).is_zero(); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -1098,7 +1098,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[0xff; 32]).not(); + let expr = Expr::constant([0xff; 32]).not(); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -1109,7 +1109,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[5]).add_mod(&Expr::constant(&[8]), &Expr::constant(&[3])); + let expr = Expr::constant([5]).add_mod(&Expr::constant([8]), &Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -1120,7 +1120,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[5]).add_mod(&Expr::constant(&[8]), &Expr::constant(&[0])); + let expr = Expr::constant([5]).add_mod(&Expr::constant([8]), &Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); @@ -1131,7 +1131,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[5]).mul_mod(&Expr::constant(&[8]), &Expr::constant(&[3])); + let expr = Expr::constant([5]).mul_mod(&Expr::constant([8]), &Expr::constant([3])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 1, 256); assert_eq!(ast, expected); @@ -1142,7 +1142,7 @@ mod tests { let config = z3::Config::new(); let ctx = z3::Context::new(&config); - let expr = Expr::constant(&[5]).mul_mod(&Expr::constant(&[8]), &Expr::constant(&[0])); + let expr = Expr::constant([5]).mul_mod(&Expr::constant([8]), &Expr::constant([0])); let ast = expr.to_z3(&ctx).simplify(); let expected = BV::from_u64(&ctx, 0, 256); assert_eq!(ast, expected); diff --git a/etk-asm/src/asm.rs b/etk-asm/src/asm.rs index 6cf8ff81..c7030f24 100644 --- a/etk-asm/src/asm.rs +++ b/etk-asm/src/asm.rs @@ -269,7 +269,7 @@ impl Assembler { }) => { let labels = op.expr().unwrap().labels(&self.declared_macros).unwrap(); let declared: HashSet<_> = - self.declared_labels.into_iter().map(|(k, _)| k).collect(); + self.declared_labels.into_keys().collect(); let invoked: HashSet<_> = labels.into_iter().collect(); let missing = invoked .difference(&declared) @@ -780,7 +780,7 @@ mod tests { fn assemble_variable_push_const() -> Result<(), Error> { let mut asm = Assembler::new(); let sz = asm.push_all(vec![AbstractOp::Push( - Terminal::Number((0x00aaaaaaaaaaaaaaaaaaaaaaaa as u128).into()).into(), + Terminal::Number(0x00aaaaaaaaaaaaaaaaaaaaaaaa_u128.into()).into(), )])?; assert_eq!(13, sz); assert_eq!(asm.take(), hex!("6baaaaaaaaaaaaaaaaaaaaaaaa")); @@ -813,7 +813,7 @@ mod tests { fn assemble_variable_push_const0() -> Result<(), Error> { let mut asm = Assembler::new(); let sz = asm.push_all(vec![AbstractOp::Push( - Terminal::Number((0x00 as u128).into()).into(), + Terminal::Number(0x00_u128.into()).into(), )])?; assert_eq!(2, sz); assert_eq!(asm.take(), hex!("6000")); @@ -1273,7 +1273,7 @@ mod tests { AbstractOp::Macro(InstructionMacroInvocation { name: "my_macro".into(), parameters: vec![ - BigInt::from_bytes_be(Sign::Plus, &vec![0x42]).into(), + BigInt::from_bytes_be(Sign::Plus, &[0x42]).into(), Terminal::Label("b".to_string()).into(), ], }), diff --git a/etk-asm/src/disasm.rs b/etk-asm/src/disasm.rs index becc6edf..4902e50d 100644 --- a/etk-asm/src/disasm.rs +++ b/etk-asm/src/disasm.rs @@ -75,7 +75,7 @@ impl<'a> Iterator for Iter<'a> { let buffer = &mut self.disassembler.buffer; let front = *buffer.front()?; let specifier = Op::<()>::from(front); - let len = specifier.size() as usize; + let len = specifier.size(); if buffer.len() < len { return None; } diff --git a/etk-asm/src/ingest.rs b/etk-asm/src/ingest.rs index 05227609..52a44590 100644 --- a/etk-asm/src/ingest.rs +++ b/etk-asm/src/ingest.rs @@ -489,7 +489,7 @@ mod tests { let mut f = NamedTempFile::new().unwrap(); let root = f.path().parent().unwrap().join("root.asm"); - write!(f, "{}", s).unwrap(); + write!(f, "{s}").unwrap(); (f, root) } @@ -759,13 +759,12 @@ mod tests { fn ingest_recursive() { let (mut f, root) = new_file(""); let path = f.path().display().to_string(); - write!(f, r#"%import("{}")"#, path).unwrap(); + write!(f, r#"%import("{path}")"#).unwrap(); let text = format!( r#" - %import("{}") + %import("{path}") "#, - path, ); let mut output = Vec::new(); diff --git a/etk-asm/src/ops.rs b/etk-asm/src/ops.rs index 74ac47bc..9abe36b9 100644 --- a/etk-asm/src/ops.rs +++ b/etk-asm/src/ops.rs @@ -306,14 +306,14 @@ impl fmt::Display for AbstractOp { Self::Op(op) => { write!(f, "{}", op.code())?; if let Some(imm) = op.immediate() { - write!(f, " {}", imm)?; + write!(f, " {imm}")?; } Ok(()) } - Self::Push(txt) => write!(f, r#"%push({})"#, txt), - Self::Label(lbl) => write!(f, r#"{}:"#, lbl), - Self::Macro(m) => write!(f, "{}", m), - Self::MacroDefinition(defn) => write!(f, "{}", defn), + Self::Push(txt) => write!(f, r#"%push({txt})"#), + Self::Label(lbl) => write!(f, r#"{lbl}:"#), + Self::Macro(m) => write!(f, "{m}"), + Self::MacroDefinition(defn) => write!(f, "{defn}"), } } } diff --git a/etk-asm/src/ops/expression.rs b/etk-asm/src/ops/expression.rs index b5508606..29f0d3d5 100644 --- a/etk-asm/src/ops/expression.rs +++ b/etk-asm/src/ops/expression.rs @@ -118,14 +118,14 @@ pub enum Expression { impl Debug for Expression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Expression::Expression(s) => write!(f, r#"({:?})"#, s), + Expression::Expression(s) => write!(f, r#"({s:?})"#), Expression::Macro(m) => write!(f, r#"Expression::Macro("{}")"#, m.name), - Expression::Terminal(t) => write!(f, r#"Expression::Terminal({:?})"#, t), - Expression::Plus(lhs, rhs) => write!(f, r#"Expression::Plus({:?}, {:?})"#, lhs, rhs), - Expression::Minus(lhs, rhs) => write!(f, r#"Expression::Minus({:?}, {:?})"#, lhs, rhs), - Expression::Times(lhs, rhs) => write!(f, r#"Expression::Times({:?}, {:?})"#, lhs, rhs), + Expression::Terminal(t) => write!(f, r#"Expression::Terminal({t:?})"#), + Expression::Plus(lhs, rhs) => write!(f, r#"Expression::Plus({lhs:?}, {rhs:?})"#), + Expression::Minus(lhs, rhs) => write!(f, r#"Expression::Minus({lhs:?}, {rhs:?})"#), + Expression::Times(lhs, rhs) => write!(f, r#"Expression::Times({lhs:?}, {rhs:?})"#), Expression::Divide(lhs, rhs) => { - write!(f, r#"Expression::Divide({:?}, {:?})"#, lhs, rhs) + write!(f, r#"Expression::Divide({lhs:?}, {rhs:?})"#) } } } @@ -134,13 +134,13 @@ impl Debug for Expression { impl fmt::Display for Expression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Expression::Expression(s) => write!(f, r#"({})"#, s), - Expression::Macro(m) => write!(f, r#"{}"#, m), - Expression::Terminal(t) => write!(f, r#"{}"#, t), - Expression::Plus(lhs, rhs) => write!(f, r#"{}+{}"#, lhs, rhs), - Expression::Minus(lhs, rhs) => write!(f, r#"{}-{}"#, lhs, rhs), - Expression::Times(lhs, rhs) => write!(f, r#"{}*{}"#, lhs, rhs), - Expression::Divide(lhs, rhs) => write!(f, r#"{}/{}"#, lhs, rhs), + Expression::Expression(s) => write!(f, r#"({s})"#), + Expression::Macro(m) => write!(f, r#"{m}"#), + Expression::Terminal(t) => write!(f, r#"{t}"#), + Expression::Plus(lhs, rhs) => write!(f, r#"{lhs}+{rhs}"#), + Expression::Minus(lhs, rhs) => write!(f, r#"{lhs}-{rhs}"#), + Expression::Times(lhs, rhs) => write!(f, r#"{lhs}*{rhs}"#), + Expression::Divide(lhs, rhs) => write!(f, r#"{lhs}/{rhs}"#), } } } @@ -309,9 +309,9 @@ impl Expression { impl Debug for Terminal { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Terminal::Label(l) => write!(f, r#"Terminal::Label({})"#, l), - Terminal::Number(n) => write!(f, r#"Terminal::Number({})"#, n), - Terminal::Variable(v) => write!(f, r#"Terminal::Variable({})"#, v), + Terminal::Label(l) => write!(f, r#"Terminal::Label({l})"#), + Terminal::Number(n) => write!(f, r#"Terminal::Number({n})"#), + Terminal::Variable(v) => write!(f, r#"Terminal::Variable({v})"#), } } } @@ -319,9 +319,9 @@ impl Debug for Terminal { impl fmt::Display for Terminal { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { - Terminal::Label(l) => write!(f, r#"Label({})"#, l), - Terminal::Number(n) => write!(f, r#"{}"#, n), - Terminal::Variable(v) => write!(f, r#"Variable({})"#, v), + Terminal::Label(l) => write!(f, r#"Label({l})"#), + Terminal::Number(n) => write!(f, r#"{n}"#), + Terminal::Variable(v) => write!(f, r#"Variable({v})"#), } } } diff --git a/etk-asm/src/parse/mod.rs b/etk-asm/src/parse/mod.rs index af6e9ef5..3b9eb806 100644 --- a/etk-asm/src/parse/mod.rs +++ b/etk-asm/src/parse/mod.rs @@ -331,13 +331,11 @@ mod tests { #[test] fn parse_include() { - let asm = format!( - r#" + let asm = r#" push1 1 %include("foo.asm") push1 2 - "#, - ); + "#.to_string(); let expected = nodes![ Op::from(Push1(Imm::from(1u8))), Node::Include(PathBuf::from("foo.asm")), @@ -348,13 +346,11 @@ mod tests { #[test] fn parse_include_hex() { - let asm = format!( - r#" + let asm = r#" push1 1 %include_hex("foo.hex") push1 2 - "#, - ); + "#.to_string(); let expected = nodes![ Op::from(Push1(Imm::from(1u8))), Node::IncludeHex(PathBuf::from("foo.hex")), @@ -365,13 +361,11 @@ mod tests { #[test] fn parse_import() { - let asm = format!( - r#" + let asm = r#" push1 1 %import("foo.asm") push1 2 - "#, - ); + "#.to_string(); let expected = nodes![ Op::from(Push1(Imm::from(1u8))), Node::Import(PathBuf::from("foo.asm")), @@ -382,11 +376,9 @@ mod tests { #[test] fn parse_import_extra_argument() { - let asm = format!( - r#" + let asm = r#" %import("foo.asm", "bar.asm") - "#, - ); + "#.to_string(); assert!(matches!( parse_asm(&asm), Err(ParseError::ExtraArgument { @@ -398,11 +390,9 @@ mod tests { #[test] fn parse_import_missing_argument() { - let asm = format!( - r#" + let asm = r#" %import() - "#, - ); + "#.to_string(); assert!(matches!( parse_asm(&asm), Err(ParseError::MissingArgument { @@ -415,23 +405,19 @@ mod tests { #[test] fn parse_import_argument_type() { - let asm = format!( - r#" + let asm = r#" %import(0x44) - "#, - ); + "#.to_string(); assert_matches!(parse_asm(&asm), Err(ParseError::ArgumentType { .. })) } #[test] fn parse_import_spaces() { - let asm = format!( - r#" + let asm = r#" push1 1 %import( "hello.asm" ) push1 2 - "#, - ); + "#.to_string(); let expected = nodes![ Op::from(Push1(Imm::from(1u8))), Node::Import(PathBuf::from("hello.asm")), @@ -442,13 +428,11 @@ mod tests { #[test] fn parse_push_macro_with_label() { - let asm = format!( - r#" + let asm = r#" push1 1 %push( hello ) push1 2 - "#, - ); + "#.to_string(); let expected = nodes![ Op::from(Push1(Imm::from(1u8))), AbstractOp::Push(Imm::with_label("hello")), @@ -459,8 +443,7 @@ mod tests { #[test] fn parse_instruction_macro() { - let asm = format!( - r#" + let asm = r#" %macro my_macro(foo, bar) gasprice pop @@ -469,8 +452,7 @@ mod tests { %another_macro() %end %my_macro(0x42, 10) - "#, - ); + "#.to_string(); let expected = nodes![ AbstractOp::MacroDefinition( InstructionMacroDefinition { @@ -498,10 +480,10 @@ mod tests { AbstractOp::Macro(InstructionMacroInvocation { name: "my_macro".into(), parameters: vec![ - BigInt::from_bytes_be(Sign::Plus, &vec![0x42]).into(), + BigInt::from_bytes_be(Sign::Plus, &[0x42]).into(), BigInt::from_bytes_be( Sign::Plus, - &vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10] + &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10] ) .into() ] @@ -513,14 +495,12 @@ mod tests { #[test] fn parse_expression() { - let asm = format!( - r#" + let asm = r#" push1 1+-1 push1 2*foo push1 (1+(2*foo))-(bar/42) push1 0x20+0o1+0b10 - "#, - ); + "#.to_string(); let expected = nodes![ Op::from(Push1(Imm::with_expression(Expression::Plus( 1.into(), @@ -556,13 +536,11 @@ mod tests { #[test] fn parse_push_macro_with_expression() { - let asm = format!( - r#" + let asm = r#" push1 1 %push( 1 + 1 ) push1 2 - "#, - ); + "#.to_string(); let expected = nodes![ Op::from(Push1(Imm::from(1u8))), AbstractOp::Push(Imm::with_expression(Expression::Plus(1.into(), 1.into()))), @@ -573,14 +551,12 @@ mod tests { #[test] fn parse_expression_macro() { - let asm = format!( - r#" + let asm = r#" %def foobar() 1+2 %end push1 foobar() - "#, - ); + "#.to_string(); let expected = nodes![ ExpressionMacroDefinition { name: "foobar".into(), diff --git a/etk-asm/tests/asm.rs b/etk-asm/tests/asm.rs index 1dac9e68..b2c683a9 100644 --- a/etk-asm/tests/asm.rs +++ b/etk-asm/tests/asm.rs @@ -10,11 +10,11 @@ fn source
(paths: &[P]) -> PathBuf
where
P: AsRef