cargo fmt

This commit is contained in:
collin 2022-07-02 14:08:17 -07:00
parent 0a4069fe39
commit ecc1fff7fd
5 changed files with 11 additions and 22 deletions

View File

@ -395,7 +395,6 @@ impl<'a> ExpressionVisitor<'a> for TypeChecker<'a> {
} }
} }
fn visit_unary(&mut self, input: &'a UnaryExpression, destination: &Self::AdditionalInput) -> Self::Output { fn visit_unary(&mut self, input: &'a UnaryExpression, destination: &Self::AdditionalInput) -> Self::Output {
match input.op { match input.op {
UnaryOperation::Abs => { UnaryOperation::Abs => {

View File

@ -18,8 +18,8 @@ use crate::{Declaration, TypeChecker, VariableSymbol};
use leo_ast::*; use leo_ast::*;
use leo_errors::TypeCheckerError; use leo_errors::TypeCheckerError;
use std::collections::HashSet;
use leo_span::sym; use leo_span::sym;
use std::collections::HashSet;
impl<'a> ProgramVisitor<'a> for TypeChecker<'a> { impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
fn visit_function(&mut self, input: &'a Function) { fn visit_function(&mut self, input: &'a Function) {
@ -54,12 +54,11 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
// Check for conflicting circuit member names. // Check for conflicting circuit member names.
let mut used = HashSet::new(); let mut used = HashSet::new();
if !input.members.iter().all(|member| used.insert(member.name())) { if !input.members.iter().all(|member| used.insert(member.name())) {
self.handler self.handler.emit_err(if input.is_record {
.emit_err(if input.is_record { TypeCheckerError::duplicate_record_variable(input.name(), input.span()).into()
TypeCheckerError::duplicate_record_variable(input.name(), input.span()).into() } else {
} else { TypeCheckerError::duplicate_circuit_member(input.name(), input.span()).into()
TypeCheckerError::duplicate_circuit_member(input.name(), input.span()).into() });
});
} }
// For records, enforce presence of `owner: Address` and `balance: u64` members. // For records, enforce presence of `owner: Address` and `balance: u64` members.
@ -67,22 +66,16 @@ impl<'a> ProgramVisitor<'a> for TypeChecker<'a> {
let check_has_field = |need, expected_ty: Type| match input let check_has_field = |need, expected_ty: Type| match input
.members .members
.iter() .iter()
.find_map(|CircuitMember::CircuitVariable(v, t) | (v.name == need).then(|| (v, t))) .find_map(|CircuitMember::CircuitVariable(v, t)| (v.name == need).then(|| (v, t)))
{ {
Some((_, actual_ty)) if expected_ty.eq_flat(actual_ty) => {} // All good, found + right type! Some((_, actual_ty)) if expected_ty.eq_flat(actual_ty) => {} // All good, found + right type!
Some((field, _)) => { Some((field, _)) => {
self.handler.emit_err(TypeCheckerError::record_var_wrong_type( self.handler
field, .emit_err(TypeCheckerError::record_var_wrong_type(field, expected_ty, input.span()).into());
expected_ty,
input.span(),
).into());
} }
None => { None => {
self.handler.emit_err(TypeCheckerError::required_record_variable( self.handler
need, .emit_err(TypeCheckerError::required_record_variable(need, expected_ty, input.span()).into());
expected_ty,
input.span(),
).into());
} }
}; };
check_has_field(sym::owner, Type::Address); check_has_field(sym::owner, Type::Address);

View File

@ -16,7 +16,6 @@
// Copyright Rust project developers under MIT or APACHE-2.0. // Copyright Rust project developers under MIT or APACHE-2.0.
use core::alloc::Layout; use core::alloc::Layout;
use core::cell::{Cell, RefCell}; use core::cell::{Cell, RefCell};
use core::mem::{self, MaybeUninit}; use core::mem::{self, MaybeUninit};

View File

@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
//! Defines the `Span` type used to track where code comes from. //! Defines the `Span` type used to track where code comes from.
use core::ops::{Add, Sub}; use core::ops::{Add, Sub};

View File

@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>. // along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::dropless::DroplessArena; use crate::dropless::DroplessArena;
use crate::source_map::SourceMap; use crate::source_map::SourceMap;