From 5be59156aedc556ed7af159e7331388907df73c6 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 27 May 2025 11:37:52 -0700 Subject: [PATCH 1/2] [Rust] Make LowLevelIL{Expression,Instruction} implement Copy --- rust/src/low_level_il/expression.rs | 16 ++++++++++++++++ rust/src/low_level_il/function.rs | 4 ++-- rust/src/low_level_il/instruction.rs | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/rust/src/low_level_il/expression.rs b/rust/src/low_level_il/expression.rs index 8df8dfe0cf..81c4e57d15 100644 --- a/rust/src/low_level_il/expression.rs +++ b/rust/src/low_level_il/expression.rs @@ -59,6 +59,7 @@ where T: FnMut(&LowLevelILExpression<'func, M, F, ValueExpr>) -> VisitorAction; } +#[derive(Copy)] pub struct LowLevelILExpression<'func, M, F, R> where M: FunctionMutability, @@ -72,6 +73,21 @@ where pub(crate) _ty: PhantomData, } +impl Clone for LowLevelILExpression<'_, M, F, R> +where + M: FunctionMutability, + F: FunctionForm, + R: ExpressionResultType, +{ + fn clone(&self) -> Self { + Self { + function: self.function, + index: self.index, + _ty: PhantomData, + } + } +} + impl<'func, M, F, R> LowLevelILExpression<'func, M, F, R> where M: FunctionMutability, diff --git a/rust/src/low_level_il/function.rs b/rust/src/low_level_il/function.rs index 495aae7905..d46350dcf1 100644 --- a/rust/src/low_level_il/function.rs +++ b/rust/src/low_level_il/function.rs @@ -31,7 +31,7 @@ pub struct Mutable; #[derive(Copy, Clone, Debug)] pub struct Finalized; -pub trait FunctionMutability: 'static + Debug {} +pub trait FunctionMutability: 'static + Debug + Copy {} impl FunctionMutability for Mutable {} impl FunctionMutability for Finalized {} @@ -40,7 +40,7 @@ pub struct SSA; #[derive(Copy, Clone, Debug)] pub struct NonSSA; -pub trait FunctionForm: 'static + Debug {} +pub trait FunctionForm: 'static + Debug + Copy {} impl FunctionForm for SSA {} impl FunctionForm for NonSSA {} diff --git a/rust/src/low_level_il/instruction.rs b/rust/src/low_level_il/instruction.rs index ef546412ed..df9d1839b4 100644 --- a/rust/src/low_level_il/instruction.rs +++ b/rust/src/low_level_il/instruction.rs @@ -65,6 +65,7 @@ where T: FnMut(&LowLevelILExpression<'func, M, F, ValueExpr>) -> VisitorAction; } +#[derive(Copy, Clone)] pub struct LowLevelILInstruction<'func, M, F> where M: FunctionMutability, From faf44bc98590082c38a21961c835aff823be1c05 Mon Sep 17 00:00:00 2001 From: Mark Rowe Date: Tue, 27 May 2025 12:06:03 -0700 Subject: [PATCH 2/2] [Rust] Have LowLevelILBlock derive Clone rather than manually implementing it This is possible now that FunctionMutability and FunctionForm require Copy, and fixes an existing clippy warning about the non-canonical implementation of `clone` on a `Copy` type. --- rust/src/low_level_il/block.rs | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/rust/src/low_level_il/block.rs b/rust/src/low_level_il/block.rs index fd3e7c81b3..d3b1f99b46 100644 --- a/rust/src/low_level_il/block.rs +++ b/rust/src/low_level_il/block.rs @@ -19,7 +19,7 @@ use crate::basic_block::{BasicBlock, BlockContext}; use super::*; -#[derive(Copy)] +#[derive(Copy, Clone)] pub struct LowLevelILBlock<'func, M, F> where M: FunctionMutability, @@ -63,18 +63,6 @@ where } } -impl Clone for LowLevelILBlock<'_, M, F> -where - M: FunctionMutability, - F: FunctionForm, -{ - fn clone(&self) -> Self { - LowLevelILBlock { - function: self.function, - } - } -} - pub struct LowLevelILBlockIter<'func, M, F> where M: FunctionMutability,