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(),
_ => 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 {
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() {
let circuit = self
.get(&file_scope)
.ok_or(ExpressionError::self_keyword(identifier.span))?;
.ok_or_else(|| ExpressionError::self_keyword(identifier.span))?;
circuit.to_owned()
} 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
let returns = res
.into_iter()
.map(|value| ConstrainedValue::from(value))
.map(ConstrainedValue::from)
.collect::<Vec<_>>();
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 input_option = input
.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(
cs,
input_model.type_,

View File

@ -53,7 +53,7 @@ impl ImportParser {
let mut imports = Self::new();
// 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
program

View File

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

View File

@ -141,7 +141,7 @@ impl CoreCircuit for Blake2sCircuit {
.to_bytes(cs)
.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
Ok(vec![Value::Array(return_value)])

View File

@ -32,7 +32,7 @@ impl<'ast> From<AstCircuit<'ast>> for Circuit {
let members = circuit
.members
.into_iter()
.map(|member| CircuitMember::from(member))
.map(CircuitMember::from)
.collect();
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 {
match range_or_expression {
AstRangeOrExpression::Range(range) => RangeOrExpression::Range(
range.from.map(|expression| Expression::from(expression)),
range.to.map(|expression| Expression::from(expression)),
range.from.map(Expression::from),
range.to.map(Expression::from),
),
AstRangeOrExpression::Expression(expression) => RangeOrExpression::Expression(Expression::from(expression)),
}

View File

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

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ impl<'ast> From<AstImportSymbol<'ast>> for ImportSymbol {
fn from(symbol: AstImportSymbol<'ast>) -> Self {
ImportSymbol {
symbol: Identifier::from(symbol.value),
alias: symbol.alias.map(|alias| Identifier::from(alias)),
alias: symbol.alias.map(Identifier::from),
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::Symbol(symbol) => PackageAccess::Symbol(ImportSymbol::from(symbol)),
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,
}
#[allow(clippy::len_without_is_empty)]
impl PublicState {
pub fn new() -> Self {
Self::default()

View File

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

View File

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

View File

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

View File

@ -143,7 +143,7 @@ impl<'ast> From<ArrayType<'ast>> for Type {
impl<'ast> From<TupleType<'ast>> for Type {
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)
}
@ -192,7 +192,7 @@ impl<'ast> From<InputArrayType<'ast>> for Type {
impl<'ast> From<InputTupleType<'ast>> for Type {
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)
}