clippy: fix redundant_closure

Signed-off-by: ljedrz <ljedrz@gmail.com>
This commit is contained in:
ljedrz 2020-10-05 16:58:35 +02:00
parent e9b9c1f72f
commit bdfb6f5fb5
20 changed files with 32 additions and 31 deletions

View File

@ -55,7 +55,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
ConstrainedValue::Boolean(boolean) => boolean.get_value(), ConstrainedValue::Boolean(boolean) => boolean.get_value(),
_ => return Err(ConsoleError::assertion_must_be_boolean(expression_string, span)), _ => return Err(ConsoleError::assertion_must_be_boolean(expression_string, span)),
}; };
let result_bool = result_option.ok_or(ConsoleError::assertion_depends_on_input(span.clone()))?; let result_bool = result_option.ok_or_else(|| ConsoleError::assertion_depends_on_input(span.clone()))?;
if !result_bool { if !result_bool {
return Err(ConsoleError::assertion_failed(expression_string, span)); return Err(ConsoleError::assertion_failed(expression_string, span));

View File

@ -43,7 +43,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
if identifier.is_self() { if identifier.is_self() {
let circuit = self let circuit = self
.get(&file_scope) .get(&file_scope)
.ok_or(ExpressionError::self_keyword(identifier.span))?; .ok_or_else(|| ExpressionError::self_keyword(identifier.span))?;
circuit.to_owned() circuit.to_owned()
} else { } else {

View File

@ -52,7 +52,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
// Convert the core function returns into constrained values // Convert the core function returns into constrained values
let returns = res let returns = res
.into_iter() .into_iter()
.map(|value| ConstrainedValue::from(value)) .map(ConstrainedValue::from)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let return_value = if returns.len() == 1 { let return_value = if returns.len() == 1 {

View File

@ -54,7 +54,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
let name = input_model.identifier.name.clone(); let name = input_model.identifier.name.clone();
let input_option = input let input_option = input
.get(&name) .get(&name)
.ok_or(FunctionError::input_not_found(name.clone(), function.span.clone()))?; .ok_or_else(|| FunctionError::input_not_found(name.clone(), function.span.clone()))?;
let input_value = self.allocate_main_function_input( let input_value = self.allocate_main_function_input(
cs, cs,
input_model.type_, input_model.type_,

View File

@ -53,7 +53,7 @@ impl ImportParser {
let mut imports = Self::new(); let mut imports = Self::new();
// Find all imports relative to current directory // Find all imports relative to current directory
let path = current_dir().map_err(|error| ImportError::current_directory_error(error))?; let path = current_dir().map_err(ImportError::current_directory_error)?;
// Parse each imported file // Parse each imported file
program program

View File

@ -548,13 +548,13 @@ impl<F: Field + PrimeField, G: GroupType<F>> From<Value> for ConstrainedValue<F,
Value::Array(array) => ConstrainedValue::Array( Value::Array(array) => ConstrainedValue::Array(
array array
.into_iter() .into_iter()
.map(|element| ConstrainedValue::from(element)) .map(ConstrainedValue::from)
.collect(), .collect(),
), ),
Value::Tuple(tuple) => ConstrainedValue::Tuple( Value::Tuple(tuple) => ConstrainedValue::Tuple(
tuple tuple
.into_iter() .into_iter()
.map(|element| ConstrainedValue::from(element)) .map(ConstrainedValue::from)
.collect(), .collect(),
), ),
} }

View File

@ -141,7 +141,7 @@ impl CoreCircuit for Blake2sCircuit {
.to_bytes(cs) .to_bytes(cs)
.map_err(|e| CoreCircuitError::cannot_enforce("Vec<UInt8> ToBytes".to_owned(), e, span.clone()))?; .map_err(|e| CoreCircuitError::cannot_enforce("Vec<UInt8> ToBytes".to_owned(), e, span.clone()))?;
let return_value = bytes.into_iter().map(|byte| Value::U8(byte)).collect(); let return_value = bytes.into_iter().map(Value::U8).collect();
// Return one array digest value // Return one array digest value
Ok(vec![Value::Array(return_value)]) Ok(vec![Value::Array(return_value)])

View File

@ -32,7 +32,7 @@ impl<'ast> From<AstCircuit<'ast>> for Circuit {
let members = circuit let members = circuit
.members .members
.into_iter() .into_iter()
.map(|member| CircuitMember::from(member)) .map(CircuitMember::from)
.collect(); .collect();
Self { circuit_name, members } Self { circuit_name, members }

View File

@ -31,8 +31,8 @@ impl<'ast> From<AstRangeOrExpression<'ast>> for RangeOrExpression {
fn from(range_or_expression: AstRangeOrExpression<'ast>) -> Self { fn from(range_or_expression: AstRangeOrExpression<'ast>) -> Self {
match range_or_expression { match range_or_expression {
AstRangeOrExpression::Range(range) => RangeOrExpression::Range( AstRangeOrExpression::Range(range) => RangeOrExpression::Range(
range.from.map(|expression| Expression::from(expression)), range.from.map(Expression::from),
range.to.map(|expression| Expression::from(expression)), range.to.map(Expression::from),
), ),
AstRangeOrExpression::Expression(expression) => RangeOrExpression::Expression(Expression::from(expression)), AstRangeOrExpression::Expression(expression) => RangeOrExpression::Expression(Expression::from(expression)),
} }

View File

@ -32,10 +32,10 @@ impl<'ast> From<AstVariables<'ast>> for Variables {
let names = variables let names = variables
.names .names
.into_iter() .into_iter()
.map(|x| VariableName::from(x)) .map(VariableName::from)
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let type_ = variables.type_.map(|type_| Type::from(type_)); let type_ = variables.type_.map(Type::from);
Self { names, type_ } Self { names, type_ }
} }

View File

@ -35,12 +35,12 @@ impl<'ast> From<AstFormattedString<'ast>> for FormattedString {
let containers = formatted let containers = formatted
.containers .containers
.into_iter() .into_iter()
.map(|container| FormattedContainer::from(container)) .map(FormattedContainer::from)
.collect(); .collect();
let parameters = formatted let parameters = formatted
.parameters .parameters
.into_iter() .into_iter()
.map(|parameter| FormattedParameter::from(parameter)) .map(FormattedParameter::from)
.collect(); .collect();
Self { Self {

View File

@ -170,7 +170,7 @@ impl<'ast> Expression {
InputArrayDimensions::Multiple(multiple) => multiple InputArrayDimensions::Multiple(multiple) => multiple
.numbers .numbers
.into_iter() .into_iter()
.map(|number| Self::get_count_from_input_ast(number)) .map(Self::get_count_from_input_ast)
.collect(), .collect(),
} }
} }
@ -188,7 +188,7 @@ impl<'ast> Expression {
ArrayDimensions::Multiple(multiple) => multiple ArrayDimensions::Multiple(multiple) => multiple
.numbers .numbers
.into_iter() .into_iter()
.map(|number| Self::get_count_from_ast(number)) .map(Self::get_count_from_ast)
.collect(), .collect(),
} }
} }
@ -301,7 +301,7 @@ impl<'ast> From<CircuitInlineExpression<'ast>> for Expression {
let members = expression let members = expression
.members .members
.into_iter() .into_iter()
.map(|member| CircuitVariableDefinition::from(member)) .map(CircuitVariableDefinition::from)
.collect::<Vec<CircuitVariableDefinition>>(); .collect::<Vec<CircuitVariableDefinition>>();
Expression::Circuit(circuit_name, members, Span::from(expression.span)) Expression::Circuit(circuit_name, members, Span::from(expression.span))
@ -343,7 +343,7 @@ impl<'ast> From<PostfixExpression<'ast>> for Expression {
.expressions .expressions
.expressions .expressions
.into_iter() .into_iter()
.map(|expression| Expression::from(expression)) .map(Expression::from)
.collect(), .collect(),
span, span,
) )
@ -506,7 +506,7 @@ impl<'ast> From<ArrayInlineExpression<'ast>> for Expression {
array array
.expressions .expressions
.into_iter() .into_iter()
.map(|s_or_e| SpreadOrExpression::from(s_or_e)) .map(SpreadOrExpression::from)
.collect(), .collect(),
Span::from(array.span), Span::from(array.span),
) )
@ -543,7 +543,7 @@ impl<'ast> From<ArrayInitializerExpression<'ast>> for Expression {
impl<'ast> From<TupleExpression<'ast>> for Expression { impl<'ast> From<TupleExpression<'ast>> for Expression {
fn from(tuple: TupleExpression<'ast>) -> Self { fn from(tuple: TupleExpression<'ast>) -> Self {
Expression::Tuple( Expression::Tuple(
tuple.expressions.into_iter().map(|e| Expression::from(e)).collect(), tuple.expressions.into_iter().map(Expression::from).collect(),
Span::from(tuple.span), Span::from(tuple.span),
) )
} }

View File

@ -35,13 +35,13 @@ impl<'ast> From<AstFunction<'ast>> for Function {
let parameters = function let parameters = function
.parameters .parameters
.into_iter() .into_iter()
.map(|parameter| InputVariable::from(parameter)) .map(InputVariable::from)
.collect(); .collect();
let returns = function.returns.map(|type_| Type::from(type_)); let returns = function.returns.map(Type::from);
let statements = function let statements = function
.statements .statements
.into_iter() .into_iter()
.map(|statement| Statement::from(statement)) .map(Statement::from)
.collect(); .collect();
Function { Function {

View File

@ -31,7 +31,7 @@ impl<'ast> From<AstImportSymbol<'ast>> for ImportSymbol {
fn from(symbol: AstImportSymbol<'ast>) -> Self { fn from(symbol: AstImportSymbol<'ast>) -> Self {
ImportSymbol { ImportSymbol {
symbol: Identifier::from(symbol.value), symbol: Identifier::from(symbol.value),
alias: symbol.alias.map(|alias| Identifier::from(alias)), alias: symbol.alias.map(Identifier::from),
span: Span::from(symbol.span), span: Span::from(symbol.span),
} }
} }

View File

@ -35,7 +35,7 @@ impl<'ast> From<AstPackageAccess<'ast>> for PackageAccess {
AstPackageAccess::SubPackage(package) => PackageAccess::SubPackage(Box::new(Package::from(*package))), AstPackageAccess::SubPackage(package) => PackageAccess::SubPackage(Box::new(Package::from(*package))),
AstPackageAccess::Symbol(symbol) => PackageAccess::Symbol(ImportSymbol::from(symbol)), AstPackageAccess::Symbol(symbol) => PackageAccess::Symbol(ImportSymbol::from(symbol)),
AstPackageAccess::Multiple(accesses) => { AstPackageAccess::Multiple(accesses) => {
PackageAccess::Multiple(accesses.into_iter().map(|access| PackageAccess::from(access)).collect()) PackageAccess::Multiple(accesses.into_iter().map(PackageAccess::from).collect())
} }
} }
} }

View File

@ -25,6 +25,7 @@ pub struct PublicState {
state: State, state: State,
} }
#[allow(clippy::len_without_is_empty)]
impl PublicState { impl PublicState {
pub fn new() -> Self { pub fn new() -> Self {
Self::default() Self::default()

View File

@ -35,7 +35,7 @@ impl<'ast> From<AstConditionalNestedOrEndStatement<'ast>> for ConditionalNestedO
AstConditionalNestedOrEndStatement::End(statements) => ConditionalNestedOrEndStatement::End( AstConditionalNestedOrEndStatement::End(statements) => ConditionalNestedOrEndStatement::End(
statements statements
.into_iter() .into_iter()
.map(|statement| Statement::from(statement)) .map(Statement::from)
.collect(), .collect(),
), ),
} }

View File

@ -34,7 +34,7 @@ impl<'ast> From<AstConditionalStatement<'ast>> for ConditionalStatement {
statements: statement statements: statement
.statements .statements
.into_iter() .into_iter()
.map(|statement| Statement::from(statement)) .map(Statement::from)
.collect(), .collect(),
next: statement next: statement
.next .next

View File

@ -147,7 +147,7 @@ impl<'ast> From<ForStatement<'ast>> for Statement {
statement statement
.statements .statements
.into_iter() .into_iter()
.map(|statement| Statement::from(statement)) .map(Statement::from)
.collect(), .collect(),
Span::from(statement.span), Span::from(statement.span),
) )

View File

@ -143,7 +143,7 @@ impl<'ast> From<ArrayType<'ast>> for Type {
impl<'ast> From<TupleType<'ast>> for Type { impl<'ast> From<TupleType<'ast>> for Type {
fn from(tuple_type: TupleType<'ast>) -> Self { fn from(tuple_type: TupleType<'ast>) -> Self {
let types = tuple_type.types.into_iter().map(|type_| Type::from(type_)).collect(); let types = tuple_type.types.into_iter().map(Type::from).collect();
Type::Tuple(types) Type::Tuple(types)
} }
@ -192,7 +192,7 @@ impl<'ast> From<InputArrayType<'ast>> for Type {
impl<'ast> From<InputTupleType<'ast>> for Type { impl<'ast> From<InputTupleType<'ast>> for Type {
fn from(tuple_type: InputTupleType<'ast>) -> Self { fn from(tuple_type: InputTupleType<'ast>) -> Self {
let types = tuple_type.types_.into_iter().map(|type_| Type::from(type_)).collect(); let types = tuple_type.types_.into_iter().map(Type::from).collect();
Type::Tuple(types) Type::Tuple(types)
} }