Derive clone for ConstraintRef (#3241)

Derives `Clone` (and some other traits) for `ConstraintRef`. Since it is
a reference, it should implement Clone.

Note that `Clone` for `AlgebraicConstraint` is only auto-derived if `V`
is `Clone`, which is the case if `V` is a reference.
This commit is contained in:
chriseth
2025-09-01 19:11:46 +02:00
committed by GitHub
parent 396737e749
commit cfc7cf31e2
4 changed files with 4 additions and 3 deletions

View File

@@ -222,7 +222,7 @@ fn remove_free_variables<T: FieldElement, V: Clone + Ord + Eq + Hash + Display>(
.filter(|(variable, constraint)| match constraint {
// Remove the algebraic constraint if we can solve for the variable.
ConstraintRef::AlgebraicConstraint(constr) => {
can_always_be_satisfied_via_free_variable(constr.clone(), variable)
can_always_be_satisfied_via_free_variable(*constr, variable)
}
ConstraintRef::BusInteraction(bus_interaction) => {
let bus_id = bus_interaction.bus_id.try_to_number().unwrap();

View File

@@ -10,7 +10,7 @@ use num_traits::{One, Zero};
pub mod solve;
/// An algebraic constraint
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub struct AlgebraicConstraint<V> {
/// The expression representing the constraint, which must evaluate to 0 for the constraint to be satisfied.
pub expression: V,

View File

@@ -267,6 +267,7 @@ impl<T: FieldElement> BusInteractionHandler<T> for DefaultBusInteractionHandler<
}
}
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq)]
pub enum ConstraintRef<'a, T, V> {
AlgebraicConstraint(AlgebraicConstraint<&'a GroupedExpression<T, V>>),
BusInteraction(&'a BusInteraction<GroupedExpression<T, V>>),

View File

@@ -364,7 +364,7 @@ where
while let Some(item) = self.constraint_system.pop_front() {
let effects = match item {
ConstraintRef::AlgebraicConstraint(c) => {
if let Some((v1, expr)) = try_to_simple_equivalence(c.clone()) {
if let Some((v1, expr)) = try_to_simple_equivalence(c) {
self.apply_assignment(&v1, &expr);
continue;
}