Skip to content

Commit

Permalink
fix: apply cargo clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
alehander92 committed Jul 26, 2023
1 parent 1dbd791 commit 55755da
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
5 changes: 2 additions & 3 deletions crates/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ impl<'a> Resolver<'a> {
// If this was a fresh capture, we added it to the end of
// the captures vector:
self.lambda_stack[lambda_index].captures.len() - 1,
))
));
}
}
}
Expand Down Expand Up @@ -1076,8 +1076,7 @@ impl<'a> Resolver<'a> {
ExpressionKind::Lambda(lambda) => self.in_new_scope(|this| {
let scope_index = this.scopes.current_scope_index();

this.lambda_stack
.push(LambdaContext { captures: Vec::new(), scope_index: scope_index });
this.lambda_stack.push(LambdaContext { captures: Vec::new(), scope_index });

let parameters = vecmap(lambda.parameters, |(pattern, typ)| {
let parameter = DefinitionKind::Local(None);
Expand Down
27 changes: 21 additions & 6 deletions crates/noirc_frontend/src/hir/type_check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,8 @@ impl<'interner> TypeChecker<'interner> {
Type::Tuple(vecmap(&elements, |elem| self.check_expression(elem)))
}
HirExpression::Lambda(lambda) => {
let captured_vars = vecmap(lambda.captures, |capture| {
let typ = self.interner.id_type(capture.ident.id);
typ
});
let captured_vars =
vecmap(lambda.captures, |capture| self.interner.id_type(capture.ident.id));

let env_type = Type::Tuple(captured_vars);
let mut params = vec![env_type];
Expand Down Expand Up @@ -867,9 +865,26 @@ impl<'interner> TypeChecker<'interner> {
ret.as_ref(),
args.as_ref(),
span,
0,
0,
)
},
}
Type::Closure(closure) => match closure.as_ref() {
Type::Function(parameters, ret) => {
if parameters.is_empty() {
unreachable!("Closure type should always contain the captured variables tuple type: {}", closure.as_ref());
}
self.bind_function_type_impl(
parameters.as_ref(),
ret.as_ref(),
args.as_ref(),
span,
1,
)
},
_ => {
unreachable!("Closure type should have a function pointer inside: {}", closure.as_ref())
}
}
Type::Error => Type::Error,
found => {
self.errors.push(TypeCheckError::ExpectedFunction { found, span });
Expand Down
4 changes: 2 additions & 2 deletions crates/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ impl<'interner> Monomorphizer<'interner> {
match func.as_ref() {
HirType::Function(arguments, return_type) => {
let converted_args = vecmap(arguments, Self::convert_type);
let converted_ret = Box::new(Self::convert_type(&return_type));
let converted_ret = Box::new(Self::convert_type(return_type));
let fn_type = ast::Type::Function(converted_args, converted_ret);
let env_type = ast::Type::Tuple(vec![]); // TODO compute this
ast::Type::Tuple(vec![env_type, fn_type])
Expand Down Expand Up @@ -701,7 +701,7 @@ impl<'interner> Monomorphizer<'interner> {
}
}

let is_closure = self.is_function_closure(&*original_func);
let is_closure = self.is_function_closure(&original_func);

let func = if is_closure {
Box::new(ast::Expression::ExtractTupleField(Box::new((*original_func).clone()), 1usize))
Expand Down

0 comments on commit 55755da

Please sign in to comment.