diff --git a/compiler/src/import/store/import.rs b/compiler/src/import/store/import.rs index a9aec1f1c7..9188c566c8 100644 --- a/compiler/src/import/store/import.rs +++ b/compiler/src/import/store/import.rs @@ -45,7 +45,7 @@ impl> ConstrainedProgram { // 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)?; diff --git a/compiler/src/import/store/symbol.rs b/compiler/src/import/store/symbol.rs index f640f05e0c..b98dc6be0f 100644 --- a/compiler/src/import/store/symbol.rs +++ b/compiler/src/import/store/symbol.rs @@ -80,7 +80,7 @@ impl> ConstrainedProgram { }; // 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 diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index 260f7213b4..3a19f2737a 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -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> ConstrainedProgram { diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 3bf59c5380..5b29441c7f 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -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. diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index c93fe097b2..ef47e00cc5 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -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>( diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index d51c1752dd..3664c7fa8f 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -239,7 +239,7 @@ impl> ConstrainedValue { } 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> ConstrainedValue { 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> fmt::Display for ConstrainedValue write!(f, "{:?}", value), ConstrainedValue::Group(ref value) => write!(f, "{:?}", value), diff --git a/core/src/types/core_package.rs b/core/src/types/core_package.rs index 339a048cc9..bc7a01e477 100644 --- a/core/src/types/core_package.rs +++ b/core/src/types/core_package.rs @@ -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 { diff --git a/core/src/types/value.rs b/core/src/types/value.rs index 1a511e3ec0..e08d584769 100644 --- a/core/src/types/value.rs +++ b/core/src/types/value.rs @@ -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) } diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index b2165fe5dd..e2076a6764 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -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; diff --git a/typed/src/common/range_or_expression.rs b/typed/src/common/range_or_expression.rs index 5c0998b431..97c13b350d 100644 --- a/typed/src/common/range_or_expression.rs +++ b/typed/src/common/range_or_expression.rs @@ -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), }