clippy: fix useless_format

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-10-05 16:36:12 +02:00
parent b4ae089d29
commit c21b5ad2f3
28 changed files with 58 additions and 60 deletions

View File

@ -50,7 +50,7 @@ impl ConsoleError {
}
pub fn assertion_depends_on_input(span: Span) -> Self {
let message = format!("console.assert() failed to evaluate. This error is caused by empty input file values");
let message = "console.assert() failed to evaluate. This error is caused by empty input file values".to_string();
Self::new_from_span(message, span)
}

View File

@ -146,7 +146,7 @@ impl ExpressionError {
}
pub fn self_keyword(span: Span) -> Self {
let message = format!("cannot call keyword `Self` outside of a circuit function");
let message = "cannot call keyword `Self` outside of a circuit function".to_string();
Self::new_from_span(message, span)
}

View File

@ -48,7 +48,7 @@ impl ImportError {
}
pub fn convert_os_string(span: Span) -> Self {
let message = format!("failed to convert file string name, maybe an illegal character?");
let message = "failed to convert file string name, maybe an illegal character?".to_string();
Self::new_from_span(message, span)
}

View File

@ -36,7 +36,7 @@ impl OutputBytesError {
}
pub fn not_enough_registers(span: Span) -> Self {
let message = format!("number of input registers must be greater than or equal to output registers");
let message = "number of input registers must be greater than or equal to output registers".to_string();
Self::new_from_span(message, span)
}

View File

@ -67,13 +67,13 @@ impl StatementError {
}
pub fn array_assign_index(span: Span) -> Self {
let message = format!("Cannot assign single index to array of values");
let message = "Cannot assign single index to array of values".to_string();
Self::new_from_span(message, span)
}
pub fn array_assign_range(span: Span) -> Self {
let message = format!("Cannot assign range of array values to single value");
let message = "Cannot assign range of array values to single value".to_string();
Self::new_from_span(message, span)
}
@ -145,7 +145,7 @@ impl StatementError {
}
pub fn tuple_assign_index(span: Span) -> Self {
let message = format!("Cannot assign single index to tuple of values");
let message = "Cannot assign single index to tuple of values".to_string();
Self::new_from_span(message, span)
}

View File

@ -64,7 +64,7 @@ impl AddressError {
}
pub fn missing_address(span: Span) -> Self {
let message = format!("expected address input not found");
let message = "expected address input not found".to_string();
Self::new_from_span(message, span)
}

View File

@ -88,13 +88,13 @@ impl GroupError {
}
pub fn x_recover(span: Span) -> Self {
let message = format!("could not recover group element from x coordinate");
let message = "could not recover group element from x coordinate".to_string();
Self::new_from_span(message, span)
}
pub fn y_recover(span: Span) -> Self {
let message = format!("could not recover group element from y coordinate");
let message = "could not recover group element from y coordinate".to_string();
Self::new_from_span(message, span)
}

View File

@ -68,7 +68,7 @@ impl IntegerError {
}
pub fn negate_operation(span: Span) -> Self {
let message = format!("integer negation can only be enforced on signed integers");
let message = "integer negation can only be enforced on signed integers".to_string();
Self::new_from_span(message, span)
}
@ -83,9 +83,10 @@ impl IntegerError {
}
pub fn invalid_index(span: Span) -> Self {
let message = format!(
let message =
"index must be a constant value unsigned integer. allocated indices produce a circuit of unknown size"
);
.to_string()
;
Self::new_from_span(message, span)
}

View File

@ -63,7 +63,7 @@ impl ValueError {
}
pub fn implicit_group(span: Span) -> Self {
let message = format!("group coordinates should be in (x, y)group format");
let message = "group coordinates should be in (x, y)group format".to_string();
Self::new_from_span(message, span)
}

View File

@ -74,6 +74,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
});
ConstrainedValue::conditionally_select(unique_namespace, &conditional_value, &first_value, &second_value)
.map_err(|e| ExpressionError::cannot_enforce(format!("conditional select"), e, span))
.map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, span))
}
}

View File

@ -35,7 +35,7 @@ pub fn enforce_and<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
if let (ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) = (left, right) {
let name_unique = format!("{} {}:{}", name, span.line, span.start);
let result = Boolean::and(cs.ns(|| name_unique), &left_bool, &right_bool)
.map_err(|e| BooleanError::cannot_enforce(format!("&&"), e, span))?;
.map_err(|e| BooleanError::cannot_enforce("&&".to_string(), e, span))?;
return Ok(ConstrainedValue::Boolean(result));
}

View File

@ -35,7 +35,7 @@ pub fn enforce_or<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<F
if let (ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) = (left, right) {
let name_unique = format!("{} {}:{}", name, span.line, span.start);
let result = Boolean::or(cs.ns(|| name_unique), &left_bool, &right_bool)
.map_err(|e| BooleanError::cannot_enforce(format!("||"), e, span))?;
.map_err(|e| BooleanError::cannot_enforce("||".to_string(), e, span))?;
return Ok(ConstrainedValue::Boolean(result));
}

View File

@ -102,7 +102,7 @@ pub fn evaluate_eq<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("=="), span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("==".to_string(), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -52,7 +52,7 @@ pub fn evaluate_ge<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">="), span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(">=".to_string(), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -52,7 +52,7 @@ pub fn evaluate_gt<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">"), span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(">".to_string(), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -52,7 +52,7 @@ pub fn evaluate_le<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<="), span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("<=".to_string(), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -52,7 +52,7 @@ pub fn evaluate_lt<F: Field + PrimeField, G: GroupType<F>, CS: ConstraintSystem<
}
};
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<"), span))?;
let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("<".to_string(), span))?;
Ok(ConstrainedValue::Boolean(boolean))
}

View File

@ -28,7 +28,7 @@ fn indicator_to_string(indicator: &Boolean) -> String {
indicator
.get_value()
.map(|b| b.to_string())
.unwrap_or(format!("[input]"))
.unwrap_or("[input]".to_string())
}
impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {

View File

@ -79,7 +79,7 @@ impl<F: Field + PrimeField> FieldType<F> {
(FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => {
let result = self_value
.add(cs, other_value)
.map_err(|e| FieldError::binary_operation(format!("+"), e, span))?;
.map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?;
Ok(FieldType::Allocated(result))
}
@ -88,7 +88,7 @@ impl<F: Field + PrimeField> FieldType<F> {
| (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated(
allocated_value
.add_constant(cs, constant_value)
.map_err(|e| FieldError::binary_operation(format!("+"), e, span))?,
.map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?,
)),
}
}
@ -102,7 +102,7 @@ impl<F: Field + PrimeField> FieldType<F> {
(FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => {
let result = self_value
.sub(cs, other_value)
.map_err(|e| FieldError::binary_operation(format!("-"), e, span))?;
.map_err(|e| FieldError::binary_operation("-".to_string(), e, span))?;
Ok(FieldType::Allocated(result))
}
@ -111,7 +111,7 @@ impl<F: Field + PrimeField> FieldType<F> {
| (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated(
allocated_value
.sub_constant(cs, constant_value)
.map_err(|e| FieldError::binary_operation(format!("+"), e, span))?,
.map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?,
)),
}
}
@ -125,7 +125,7 @@ impl<F: Field + PrimeField> FieldType<F> {
(FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => {
let result = self_value
.mul(cs, other_value)
.map_err(|e| FieldError::binary_operation(format!("*"), e, span))?;
.map_err(|e| FieldError::binary_operation("*".to_string(), e, span))?;
Ok(FieldType::Allocated(result))
}
@ -134,7 +134,7 @@ impl<F: Field + PrimeField> FieldType<F> {
| (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated(
allocated_value
.mul_by_constant(cs, constant_value)
.map_err(|e| FieldError::binary_operation(format!("*"), e, span))?,
.map_err(|e| FieldError::binary_operation("*".to_string(), e, span))?,
)),
}
}
@ -144,14 +144,14 @@ impl<F: Field + PrimeField> FieldType<F> {
FieldType::Constant(constant) => {
let constant_inverse = constant
.inverse()
.ok_or(FieldError::no_inverse(constant.to_string(), span.clone()))?;
.ok_or_else(|| FieldError::no_inverse(constant.to_string(), span.clone()))?;
FieldType::Constant(constant_inverse)
}
FieldType::Allocated(allocated) => {
let allocated_inverse = allocated
.inverse(&mut cs)
.map_err(|e| FieldError::binary_operation(format!("+"), e, span.clone()))?;
.map_err(|e| FieldError::binary_operation("+".to_string(), e, span.clone()))?;
FieldType::Allocated(allocated_inverse)
}

View File

@ -88,7 +88,7 @@ impl GroupType<Fq> for EdwardsGroupType {
cs,
other_value,
)
.map_err(|e| GroupError::binary_operation(format!("+"), e, span))?;
.map_err(|e| GroupError::binary_operation("+".to_string(), e, span))?;
Ok(EdwardsGroupType::Allocated(result))
}
@ -98,7 +98,7 @@ impl GroupType<Fq> for EdwardsGroupType {
Ok(EdwardsGroupType::Allocated(
allocated_value
.add_constant(cs, constant_value)
.map_err(|e| GroupError::binary_operation(format!("+"), e, span))?,
.map_err(|e| GroupError::binary_operation("+".to_string(), e, span))?,
))
}
}
@ -116,7 +116,7 @@ impl GroupType<Fq> for EdwardsGroupType {
cs,
other_value,
)
.map_err(|e| GroupError::binary_operation(format!("-"), e, span))?;
.map_err(|e| GroupError::binary_operation("-".to_string(), e, span))?;
Ok(EdwardsGroupType::Allocated(result))
}
@ -126,7 +126,7 @@ impl GroupType<Fq> for EdwardsGroupType {
Ok(EdwardsGroupType::Allocated(
allocated_value
.sub_constant(cs, constant_value)
.map_err(|e| GroupError::binary_operation(format!("-"), e, span))?,
.map_err(|e| GroupError::binary_operation("-".to_string(), e, span))?,
))
}
}
@ -294,10 +294,10 @@ impl EdwardsGroupType {
let x_value = allocated.x.get_value();
let y_value = allocated.y.get_value();
let x_allocated = FpGadget::alloc(cs.ns(|| format!("x")), || {
let x_allocated = FpGadget::alloc(cs.ns(|| "x"), || {
x_value.ok_or(SynthesisError::AssignmentMissing)
})?;
let y_allocated = FpGadget::alloc(cs.ns(|| format!("y")), || {
let y_allocated = FpGadget::alloc(cs.ns(|| "y"), || {
y_value.ok_or(SynthesisError::AssignmentMissing)
})?;

View File

@ -157,7 +157,7 @@ impl Integer {
let unsigned_integer = self;
let value_option: Option<String> = match_unsigned_integer!(unsigned_integer => unsigned_integer.get_value());
let value = value_option.ok_or(IntegerError::invalid_index(span.clone()))?;
let value = value_option.ok_or_else(|| IntegerError::invalid_index(span.clone()))?;
let value_usize = value
.parse::<usize>()
.map_err(|_| IntegerError::invalid_integer(value, span))?;
@ -395,7 +395,7 @@ impl Integer {
let result = match_integers_span!((a, b), s => a.add(cs.ns(|| unique_namespace), &b));
result.ok_or(IntegerError::binary_operation(format!("+"), span))
result.ok_or_else(|| IntegerError::binary_operation("+".to_string(), span))
}
pub fn sub<F: Field + PrimeField, CS: ConstraintSystem<F>>(
@ -412,7 +412,7 @@ impl Integer {
let result = match_integers_span!((a, b), s => a.sub(cs.ns(|| unique_namespace), &b));
result.ok_or(IntegerError::binary_operation(format!("-"), span))
result.ok_or_else(|| IntegerError::binary_operation("-".to_string(), span))
}
pub fn mul<F: Field + PrimeField, CS: ConstraintSystem<F>>(
@ -429,7 +429,7 @@ impl Integer {
let result = match_integers_span!((a, b), s => a.mul(cs.ns(|| unique_namespace), &b));
result.ok_or(IntegerError::binary_operation(format!("*"), span))
result.ok_or_else(|| IntegerError::binary_operation("*".to_string(), span))
}
pub fn div<F: Field + PrimeField, CS: ConstraintSystem<F>>(
@ -446,7 +446,7 @@ impl Integer {
let result = match_integers_span!((a, b), s => a.div(cs.ns(|| unique_namespace), &b));
result.ok_or(IntegerError::binary_operation(format!("÷"), span))
result.ok_or_else(|| IntegerError::binary_operation("÷".to_string(), span))
}
pub fn pow<F: Field + PrimeField, CS: ConstraintSystem<F>>(
@ -463,7 +463,7 @@ impl Integer {
let result = match_integers_span!((a, b), s => a.pow(cs.ns(|| unique_namespace), &b));
result.ok_or(IntegerError::binary_operation(format!("**"), span))
result.ok_or_else(|| IntegerError::binary_operation("**".to_string(), span))
}
}

View File

@ -239,7 +239,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
}
ConstrainedValue::Boolean(boolean) => {
let option = boolean.get_value();
let name = option.map(|b| b.to_string()).unwrap_or(format!("[allocated]"));
let name = option.map(|b| b.to_string()).unwrap_or("[allocated]".to_string());
*boolean = allocate_bool(&mut cs, name, option, span)?;
}
@ -256,7 +256,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
ConstrainedValue::Integer(integer) => {
let integer_type = integer.get_type();
let option = integer.get_value();
let name = option.clone().unwrap_or(format!("[allocated]"));
let name = option.clone().unwrap_or("[allocated]".to_string());
*integer = Integer::allocate_type(&mut cs, integer_type, name, option, span)?;
}
@ -328,7 +328,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> fmt::Display for ConstrainedValue<F
value
.get_value()
.map(|v| v.to_string())
.unwrap_or(format!("[allocated]"))
.unwrap_or("[allocated]".to_string())
),
ConstrainedValue::Field(ref value) => write!(f, "{:?}", value),
ConstrainedValue::Group(ref value) => write!(f, "{:?}", value),

View File

@ -35,7 +35,7 @@ impl CorePackageError {
}
pub fn core_package_star(span: Span) -> Self {
let message = format!("Cannot import star from leo-core");
let message = "Cannot import star from leo-core".to_string();
Self::new_from_span(message, span)
}

View File

@ -48,7 +48,7 @@ impl CorePackageListError {
}
pub fn core_package_star(span: Span) -> Self {
let message = format!("Cannot import star from leo-core");
let message = "Cannot import star from leo-core".to_string();
Self::new_from_span(message, span)
}

View File

@ -43,7 +43,7 @@ impl<F: Field> Neg<F> for Vec<Boolean> {
let mut one = vec![Boolean::constant(true)];
one.append(&mut vec![Boolean::Constant(false); self.len() - 1]);
let mut bits = flipped.add_bits(cs.ns(|| format!("add one")), &one)?;
let mut bits = flipped.add_bits(cs.ns(|| "add one"), &one)?;
let _carry = bits.pop(); // we already accounted for overflow above
Ok(bits)

View File

@ -44,12 +44,12 @@ impl<'a, F: Field> FullAdder<'a, F> for Boolean {
b: &'a Self,
carry: &'a Self,
) -> Result<(Self, Self), SynthesisError> {
let a_x_b = Boolean::xor(cs.ns(|| format!("a XOR b")), a, b)?;
let sum = Boolean::xor(cs.ns(|| format!("adder sum")), &a_x_b, carry)?;
let a_x_b = Boolean::xor(cs.ns(|| "a XOR b"), a, b)?;
let sum = Boolean::xor(cs.ns(|| "adder sum"), &a_x_b, carry)?;
let c1 = Boolean::and(cs.ns(|| format!("a AND b")), a, b)?;
let c2 = Boolean::and(cs.ns(|| format!("carry AND (a XOR b)")), carry, &a_x_b)?;
let carry = Boolean::or(cs.ns(|| format!("c1 OR c2")), &c1, &c2)?;
let c1 = Boolean::and(cs.ns(|| "a AND b"), a, b)?;
let c2 = Boolean::and(cs.ns(|| "carry AND (a XOR b)"), carry, &a_x_b)?;
let carry = Boolean::or(cs.ns(|| "c1 OR c2"), &c1, &c2)?;
Ok((sum, carry))
}

View File

@ -50,9 +50,6 @@ impl Gitignore {
}
fn template(&self) -> String {
format!(
r#"outputs/
"#,
)
"outputs/\n".to_string()
}
}

View File

@ -45,8 +45,8 @@ impl fmt::Display for RangeOrExpression {
RangeOrExpression::Range(ref from, ref to) => write!(
f,
"{}..{}",
from.as_ref().map(|e| format!("{}", e)).unwrap_or("".to_string()),
to.as_ref().map(|e| format!("{}", e)).unwrap_or("".to_string())
from.as_ref().map(|e| e.to_string()).unwrap_or("".to_string()),
to.as_ref().map(|e| e.to_string()).unwrap_or("".to_string())
),
RangeOrExpression::Expression(ref e) => write!(f, "{}", e),
}