clippy: fix or_fun_call

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-10-05 16:39:36 +02:00
parent ffef5089f7
commit 7c15eabd5e
10 changed files with 15 additions and 15 deletions

View File

@ -45,7 +45,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
// Find imported program
let program = imported_programs
.get_import(&package)
.ok_or(ImportError::unknown_package(import.package.name.clone()))?;
.ok_or_else(|| ImportError::unknown_package(import.package.name.clone()))?;
// Parse imported program
self.store_definitions(program.clone(), imported_programs)?;

View File

@ -80,7 +80,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
};
// take the alias if it is present
let id = symbol.alias.clone().unwrap_or(symbol.symbol.clone());
let id = symbol.alias.clone().unwrap_or_else(|| symbol.symbol.clone());
let name = new_scope(scope, id.to_string());
// store imported circuit under imported name

View File

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

View File

@ -201,7 +201,7 @@ impl EdwardsGroupType {
let x = Fq::from_str(&x_string).map_err(|_| GroupError::x_invalid(x_string, x_span))?;
match greatest {
// Sign provided
Some(greatest) => EdwardsAffine::from_x_coordinate(x, greatest).ok_or(GroupError::x_recover(element_span)),
Some(greatest) => EdwardsAffine::from_x_coordinate(x, greatest).ok_or_else(|| GroupError::x_recover(element_span)),
// Sign inferred
None => {
// Attempt to recover with a sign_low bit.
@ -230,7 +230,7 @@ impl EdwardsGroupType {
match greatest {
// Sign provided
Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or(GroupError::y_recover(element_span)),
Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or_else(|| GroupError::y_recover(element_span)),
// Sign inferred
None => {
// Attempt to recover with a sign_low bit.

View File

@ -378,7 +378,7 @@ impl Integer {
let result = match_signed_integer!(a, s => a.neg(cs.ns(|| unique_namespace)));
result.ok_or(IntegerError::negate_operation(span))
result.ok_or_else(|| IntegerError::negate_operation(span))
}
pub fn add<F: Field + PrimeField, CS: ConstraintSystem<F>>(

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("[allocated]".to_string());
let name = option.map(|b| b.to_string()).unwrap_or_else(|| "[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("[allocated]".to_string());
let name = option.clone().unwrap_or_else(|| "[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("[allocated]".to_string())
.unwrap_or_else(|| "[allocated]".to_string())
),
ConstrainedValue::Field(ref value) => write!(f, "{:?}", value),
ConstrainedValue::Group(ref value) => write!(f, "{:?}", value),

View File

@ -71,7 +71,7 @@ impl CorePackage {
let span = circuit.span.clone();
// take the alias if it is present
let id = circuit.alias.clone().unwrap_or(circuit.symbol.clone());
let id = circuit.alias.clone().unwrap_or_else(|| circuit.symbol.clone());
let name = id.name.clone();
let circuit = if self.unstable {

View File

@ -71,7 +71,7 @@ impl fmt::Display for Value {
}
};
let string = string_option.unwrap_or("[input]".to_owned());
let string = string_option.unwrap_or_else(|| "[input]".to_owned());
write!(f, "{}", string)
}

View File

@ -53,9 +53,9 @@ impl TryFrom<&PathBuf> for InputPairs {
let file_name = file
.file_stem()
.ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?
.ok_or_else(|| InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?
.to_str()
.ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?;
.ok_or_else(|| InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?;
if file_extension == INPUT_FILE_EXTENSION.trim_start_matches('.') {
let input_file = InputFile::new(file_name).read_from(&file)?.0;

View File

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