nightly cargo fmt

This commit is contained in:
Zk 2024-06-08 01:50:58 +08:00
parent 79cfd9b88e
commit dbea7f7f8c
No known key found for this signature in database
GPG Key ID: 1B985204A7D26DE6
46 changed files with 444 additions and 246 deletions

View File

@ -21,9 +21,13 @@ use snarkvm::console::program::Identifier as IdentifierCore;
use crate::{simple_node_impl, Node, NodeID};
use serde::{
de::{
Visitor, {self},
Visitor,
{self},
},
Deserialize, Deserializer, Serialize, Serializer,
Deserialize,
Deserializer,
Serialize,
Serializer,
};
use snarkvm::prelude::Network;
use std::{

View File

@ -86,42 +86,38 @@ pub enum BinaryOperation {
impl fmt::Display for BinaryOperation {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Self::Add => "+",
Self::AddWrapped => "add_wrapped",
Self::And => "&&",
Self::BitwiseAnd => "&",
Self::Div => "/",
Self::DivWrapped => "div_wrapped",
Self::Eq => "==",
Self::Gte => ">=",
Self::Gt => ">",
Self::Lte => "<=",
Self::Lt => "<",
Self::Mod => "mod",
Self::Mul => "*",
Self::MulWrapped => "mul_wrapped",
Self::Nand => "NAND",
Self::Neq => "!=",
Self::Nor => "NOR",
Self::Or => "||",
Self::BitwiseOr => "|",
Self::Pow => "**",
Self::PowWrapped => "pow_wrapped",
Self::Rem => "%",
Self::RemWrapped => "rem_wrapped",
Self::Shl => "<<",
Self::ShlWrapped => "shl_wrapped",
Self::Shr => ">>",
Self::ShrWrapped => "shr_wrapped",
Self::Sub => "-",
Self::SubWrapped => "sub_wrapped",
Self::Xor => "^",
}
)
write!(f, "{}", match self {
Self::Add => "+",
Self::AddWrapped => "add_wrapped",
Self::And => "&&",
Self::BitwiseAnd => "&",
Self::Div => "/",
Self::DivWrapped => "div_wrapped",
Self::Eq => "==",
Self::Gte => ">=",
Self::Gt => ">",
Self::Lte => "<=",
Self::Lt => "<",
Self::Mod => "mod",
Self::Mul => "*",
Self::MulWrapped => "mul_wrapped",
Self::Nand => "NAND",
Self::Neq => "!=",
Self::Nor => "NOR",
Self::Or => "||",
Self::BitwiseOr => "|",
Self::Pow => "**",
Self::PowWrapped => "pow_wrapped",
Self::Rem => "%",
Self::RemWrapped => "rem_wrapped",
Self::Shl => "<<",
Self::ShlWrapped => "shl_wrapped",
Self::Shr => ">>",
Self::ShrWrapped => "shr_wrapped",
Self::Sub => "-",
Self::SubWrapped => "sub_wrapped",
Self::Xor => "^",
})
}
}

View File

@ -15,8 +15,21 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use crate::{
Annotation, CompositeType, Function, FutureType, Identifier, Input, Location, Mode, Node, NodeID, Output,
ProgramId, TupleType, Type, Variant,
Annotation,
CompositeType,
Function,
FutureType,
Identifier,
Input,
Location,
Mode,
Node,
NodeID,
Output,
ProgramId,
TupleType,
Type,
Variant,
};
use leo_span::{sym, Span, Symbol};

View File

@ -20,7 +20,8 @@ use itertools::Itertools;
use leo_span::Symbol;
use serde::{Deserialize, Serialize};
use snarkvm::prelude::{
Network, PlaintextType,
Network,
PlaintextType,
PlaintextType::{Array, Literal, Struct},
};
use std::fmt;

View File

@ -16,8 +16,16 @@
mod utilities;
use utilities::{
compile_and_process, get_build_options, get_cwd_option, hash_asts, hash_content, hash_symbol_tables, parse_program,
BufferEmitter, CompileOutput, CurrentNetwork,
compile_and_process,
get_build_options,
get_cwd_option,
hash_asts,
hash_content,
hash_symbol_tables,
parse_program,
BufferEmitter,
CompileOutput,
CurrentNetwork,
};
use leo_compiler::{CompilerOptions, OutputOptions};
@ -26,7 +34,8 @@ use leo_errors::{emitter::Handler, LeoError};
use leo_span::symbol::create_session_if_not_set_then;
use leo_test_framework::{
runner::{Namespace, ParseType, Runner},
Test, PROGRAM_DELIMITER,
Test,
PROGRAM_DELIMITER,
};
use snarkvm::console::prelude::*;

View File

@ -16,8 +16,18 @@
mod utilities;
use utilities::{
buffer_if_err, compile_and_process, get_build_options, get_cwd_option, hash_asts, hash_content, hash_symbol_tables,
parse_program, BufferEmitter, CompileOutput, CurrentNetwork, ExecuteOutput,
buffer_if_err,
compile_and_process,
get_build_options,
get_cwd_option,
hash_asts,
hash_content,
hash_symbol_tables,
parse_program,
BufferEmitter,
CompileOutput,
CurrentNetwork,
ExecuteOutput,
};
use leo_compiler::{CompilerOptions, OutputOptions};
@ -26,7 +36,8 @@ use leo_span::symbol::create_session_if_not_set_then;
use leo_test_framework::{
runner::{Namespace, ParseType, Runner},
test::TestExpectationMode,
Test, PROGRAM_DELIMITER,
Test,
PROGRAM_DELIMITER,
};
use aleo_std_storage::StorageMode;

View File

@ -23,7 +23,8 @@ pub use output::*;
use leo_compiler::{BuildOptions, Compiler, CompilerOptions};
use leo_errors::{
emitter::{Buffer, Emitter, Handler},
LeoError, LeoWarning,
LeoError,
LeoWarning,
};
use leo_package::root::env::Env;
use leo_span::source_map::FileName;
@ -37,7 +38,8 @@ use leo_span::Symbol;
use snarkvm::{file::Manifest, package::Package};
use std::{
cell::RefCell,
fmt, fs,
fmt,
fs,
fs::File,
path::{Path, PathBuf},
rc::Rc,

View File

@ -188,11 +188,7 @@ impl<'a, N: Network> ParserContext<'a, N> {
/// Eats the expected `token`, or errors.
pub(super) fn expect(&mut self, token: &Token) -> Result<Span> {
if self.eat(token) {
Ok(self.prev_token.span)
} else {
self.unexpected(token)
}
if self.eat(token) { Ok(self.prev_token.span) } else { self.unexpected(token) }
}
/// Eats one of the expected `tokens`, or errors.

View File

@ -145,18 +145,15 @@ impl<N: Network> ParserContext<'_, N> {
}
Token::RightCurly => break,
_ => {
return Err(Self::unexpected_item(
&self.token,
&[
Token::Struct,
Token::Record,
Token::Mapping,
Token::At,
Token::Function,
Token::Transition,
Token::Inline,
],
)
return Err(Self::unexpected_item(&self.token, &[
Token::Struct,
Token::Record,
Token::Mapping,
Token::At,
Token::Function,
Token::Transition,
Token::Inline,
])
.into());
}
}
@ -242,17 +239,14 @@ impl<N: Network> ParserContext<'_, N> {
// Only provide a program name for records.
let external = if is_record { self.program_name } else { None };
Ok((
struct_name.name,
Composite {
identifier: struct_name,
members,
external,
is_record,
span: start + end,
id: self.node_builder.next_id(),
},
))
Ok((struct_name.name, Composite {
identifier: struct_name,
members,
external,
is_record,
span: start + end,
id: self.node_builder.next_id(),
}))
}
/// Parses a mapping declaration, e.g. `mapping balances: address => u128`.
@ -264,10 +258,13 @@ impl<N: Network> ParserContext<'_, N> {
self.expect(&Token::BigArrow)?;
let (value_type, _) = self.parse_type()?;
let end = self.expect(&Token::Semicolon)?;
Ok((
identifier.name,
Mapping { identifier, key_type, value_type, span: start + end, id: self.node_builder.next_id() },
))
Ok((identifier.name, Mapping {
identifier,
key_type,
value_type,
span: start + end,
id: self.node_builder.next_id(),
}))
}
// TODO: Return a span associated with the mode.

View File

@ -16,10 +16,30 @@
use crate::CodeGenerator;
use leo_ast::{
AccessExpression, ArrayAccess, ArrayExpression, AssociatedConstant, AssociatedFunction, BinaryExpression,
BinaryOperation, CallExpression, CastExpression, ErrExpression, Expression, Identifier, Literal, Location,
LocatorExpression, MemberAccess, StructExpression, TernaryExpression, TupleExpression, Type, UnaryExpression,
UnaryOperation, UnitExpression, Variant,
AccessExpression,
ArrayAccess,
ArrayExpression,
AssociatedConstant,
AssociatedFunction,
BinaryExpression,
BinaryOperation,
CallExpression,
CastExpression,
ErrExpression,
Expression,
Identifier,
Literal,
Location,
LocatorExpression,
MemberAccess,
StructExpression,
TernaryExpression,
TupleExpression,
Type,
UnaryExpression,
UnaryOperation,
UnitExpression,
Variant,
};
use leo_span::sym;
use std::borrow::Borrow;

View File

@ -137,11 +137,7 @@ impl<'a> CodeGenerator<'a> {
}
fn visit_struct_or_record(&mut self, struct_: &'a Composite) -> String {
if struct_.is_record {
self.visit_record(struct_)
} else {
self.visit_struct(struct_)
}
if struct_.is_record { self.visit_record(struct_) } else { self.visit_struct(struct_) }
}
fn visit_struct(&mut self, struct_: &'a Composite) -> String {

View File

@ -17,8 +17,20 @@
use crate::CodeGenerator;
use leo_ast::{
AssertStatement, AssertVariant, AssignStatement, Block, ConditionalStatement, ConsoleStatement,
DefinitionStatement, Expression, ExpressionStatement, IterationStatement, Mode, ReturnStatement, Statement, Type,
AssertStatement,
AssertVariant,
AssignStatement,
Block,
ConditionalStatement,
ConsoleStatement,
DefinitionStatement,
Expression,
ExpressionStatement,
IterationStatement,
Mode,
ReturnStatement,
Statement,
Type,
};
use itertools::Itertools;

View File

@ -77,11 +77,7 @@ impl ConstantPropagationTable {
/// Returns true if the constant exists in any parent scope
pub fn constant_in_parent_scope(&self, symbol: Symbol) -> bool {
if let Some(parent) = self.parent.as_ref() {
if parent.constants.contains_key(&symbol) {
true
} else {
parent.constant_in_parent_scope(symbol)
}
if parent.constants.contains_key(&symbol) { true } else { parent.constant_in_parent_scope(symbol) }
} else {
false
}

View File

@ -68,11 +68,7 @@ impl SymbolTable {
} else if self.variables.contains_key(location) {
return Err(AstError::shadowed_variable(location.name, span).into());
}
if let Some(parent) = self.parent.as_ref() {
parent.check_shadowing(location, is_struct, span)
} else {
Ok(())
}
if let Some(parent) = self.parent.as_ref() { parent.check_shadowing(location, is_struct, span) } else { Ok(()) }
}
/// Returns the current scope index.
@ -192,11 +188,7 @@ impl SymbolTable {
return Some(struct_);
}
}
if let Some(parent) = self.parent.as_ref() {
parent.lookup_struct(location, main_program)
} else {
None
}
if let Some(parent) = self.parent.as_ref() { parent.lookup_struct(location, main_program) } else { None }
}
/// Attempts to lookup a variable in the symbol table.
@ -306,23 +298,21 @@ mod tests {
)
.unwrap();
symbol_table
.insert_struct(
Location::new(Some(Symbol::intern("credits")), Symbol::intern("token")),
&Composite {
is_record: false,
span: Default::default(),
id: 0,
identifier: Identifier::new(Symbol::intern("token"), Default::default()),
members: Vec::new(),
external: None,
},
)
.insert_struct(Location::new(Some(Symbol::intern("credits")), Symbol::intern("token")), &Composite {
is_record: false,
span: Default::default(),
id: 0,
identifier: Identifier::new(Symbol::intern("token"), Default::default()),
members: Vec::new(),
external: None,
})
.unwrap();
symbol_table
.insert_variable(
Location::new(None, Symbol::intern("foo")),
VariableSymbol { type_: Type::Address, span: Default::default(), declaration: VariableType::Const },
)
.insert_variable(Location::new(None, Symbol::intern("foo")), VariableSymbol {
type_: Type::Address,
span: Default::default(),
declaration: VariableType::Const,
})
.unwrap();
let json = symbol_table.to_json_string().unwrap();
let deserialized = SymbolTable::from_json_string(&json).unwrap();

View File

@ -17,7 +17,12 @@
use crate::DeadCodeEliminator;
use leo_ast::{
AccessExpression, AssociatedFunction, Expression, ExpressionReconstructor, Identifier, StructExpression,
AccessExpression,
AssociatedFunction,
Expression,
ExpressionReconstructor,
Identifier,
StructExpression,
StructVariableInitializer,
};
use leo_span::sym;

View File

@ -17,9 +17,21 @@
use crate::DeadCodeEliminator;
use leo_ast::{
AccessExpression, AssertStatement, AssertVariant, AssignStatement, Block, ConditionalStatement, ConsoleStatement,
DefinitionStatement, Expression, ExpressionReconstructor, ExpressionStatement, IterationStatement, ReturnStatement,
Statement, StatementReconstructor,
AccessExpression,
AssertStatement,
AssertVariant,
AssignStatement,
Block,
ConditionalStatement,
ConsoleStatement,
DefinitionStatement,
Expression,
ExpressionReconstructor,
ExpressionStatement,
IterationStatement,
ReturnStatement,
Statement,
StatementReconstructor,
};
impl StatementReconstructor for DeadCodeEliminator<'_> {

View File

@ -17,7 +17,14 @@
use crate::Destructurer;
use leo_ast::{
AccessExpression, ArrayAccess, Expression, ExpressionReconstructor, IntegerType, Literal, Statement, TupleAccess,
AccessExpression,
ArrayAccess,
Expression,
ExpressionReconstructor,
IntegerType,
Literal,
Statement,
TupleAccess,
Type,
};

View File

@ -17,9 +17,21 @@
use crate::Destructurer;
use leo_ast::{
AssignStatement, Block, ConditionalStatement, ConsoleStatement, DefinitionStatement, Expression,
ExpressionReconstructor, Identifier, IterationStatement, Node, ReturnStatement, Statement, StatementReconstructor,
TupleExpression, Type,
AssignStatement,
Block,
ConditionalStatement,
ConsoleStatement,
DefinitionStatement,
Expression,
ExpressionReconstructor,
Identifier,
IterationStatement,
Node,
ReturnStatement,
Statement,
StatementReconstructor,
TupleExpression,
Type,
};
use itertools::Itertools;

View File

@ -17,8 +17,15 @@
use crate::Flattener;
use leo_ast::{
Expression, ExpressionReconstructor, Location, Node, Statement, StructExpression, StructVariableInitializer,
TernaryExpression, Type,
Expression,
ExpressionReconstructor,
Location,
Node,
Statement,
StructExpression,
StructVariableInitializer,
TernaryExpression,
Type,
};
impl ExpressionReconstructor for Flattener<'_> {

View File

@ -17,9 +17,25 @@
use crate::Flattener;
use leo_ast::{
AssertStatement, AssertVariant, AssignStatement, BinaryExpression, BinaryOperation, Block, ConditionalStatement,
ConsoleStatement, DefinitionStatement, Expression, ExpressionReconstructor, IterationStatement, Node,
ReturnStatement, Statement, StatementReconstructor, Type, UnaryExpression, UnaryOperation,
AssertStatement,
AssertVariant,
AssignStatement,
BinaryExpression,
BinaryOperation,
Block,
ConditionalStatement,
ConsoleStatement,
DefinitionStatement,
Expression,
ExpressionReconstructor,
IterationStatement,
Node,
ReturnStatement,
Statement,
StatementReconstructor,
Type,
UnaryExpression,
UnaryOperation,
};
use itertools::Itertools;

View File

@ -17,10 +17,35 @@
use crate::{Assigner, SymbolTable, TypeTable};
use leo_ast::{
AccessExpression, ArrayAccess, ArrayExpression, ArrayType, BinaryExpression, BinaryOperation, Block, Composite,
CompositeType, Expression, ExpressionReconstructor, Identifier, IntegerType, Literal, Member, MemberAccess, Node,
NodeBuilder, NonNegativeNumber, ReturnStatement, Statement, StructExpression, StructVariableInitializer,
TernaryExpression, TupleAccess, TupleExpression, TupleType, Type, UnitExpression,
AccessExpression,
ArrayAccess,
ArrayExpression,
ArrayType,
BinaryExpression,
BinaryOperation,
Block,
Composite,
CompositeType,
Expression,
ExpressionReconstructor,
Identifier,
IntegerType,
Literal,
Member,
MemberAccess,
Node,
NodeBuilder,
NonNegativeNumber,
ReturnStatement,
Statement,
StructExpression,
StructVariableInitializer,
TernaryExpression,
TupleAccess,
TupleExpression,
TupleType,
Type,
UnitExpression,
};
use leo_span::Symbol;

View File

@ -16,8 +16,19 @@
use crate::{Assigner, RenameTable};
use leo_ast::{
AssignStatement, ConditionalStatement, ConsoleStatement, DefinitionStatement, Expression, ExpressionReconstructor,
Identifier, IterationStatement, NodeID, ProgramReconstructor, Statement, StatementReconstructor, StructExpression,
AssignStatement,
ConditionalStatement,
ConsoleStatement,
DefinitionStatement,
Expression,
ExpressionReconstructor,
Identifier,
IterationStatement,
NodeID,
ProgramReconstructor,
Statement,
StatementReconstructor,
StructExpression,
StructVariableInitializer,
};
use leo_span::Symbol;

View File

@ -17,8 +17,16 @@
use crate::{FunctionInliner, Replacer};
use leo_ast::{
CallExpression, Expression, ExpressionReconstructor, Identifier, ReturnStatement, Statement,
StatementReconstructor, Type, UnitExpression, Variant,
CallExpression,
Expression,
ExpressionReconstructor,
Identifier,
ReturnStatement,
Statement,
StatementReconstructor,
Type,
UnitExpression,
Variant,
};
use indexmap::IndexMap;

View File

@ -17,8 +17,17 @@
use crate::FunctionInliner;
use leo_ast::{
AssignStatement, Block, ConditionalStatement, ConsoleStatement, DefinitionStatement, Expression,
ExpressionReconstructor, ExpressionStatement, IterationStatement, Statement, StatementReconstructor,
AssignStatement,
Block,
ConditionalStatement,
ConsoleStatement,
DefinitionStatement,
Expression,
ExpressionReconstructor,
ExpressionStatement,
IterationStatement,
Statement,
StatementReconstructor,
};
impl StatementReconstructor for FunctionInliner<'_> {

View File

@ -77,10 +77,13 @@ impl StatementReconstructor for Unroller<'_> {
fn reconstruct_definition(&mut self, input: DefinitionStatement) -> (Statement, Self::AdditionalOutput) {
// Helper function to add variables to symbol table
let insert_variable = |symbol: Symbol, type_: Type, span: Span| {
if let Err(err) = self.symbol_table.borrow_mut().insert_variable(
Location::new(None, symbol),
VariableSymbol { type_, span, declaration: VariableType::Mut },
) {
if let Err(err) =
self.symbol_table.borrow_mut().insert_variable(Location::new(None, symbol), VariableSymbol {
type_,
span,
declaration: VariableType::Mut,
})
{
self.handler.emit_err(err);
}
};

View File

@ -15,7 +15,15 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
use leo_ast::{
Block, Expression, IntegerType, IterationStatement, Literal, NodeBuilder, Statement, StatementReconstructor, Type,
Block,
Expression,
IntegerType,
IterationStatement,
Literal,
NodeBuilder,
Statement,
StatementReconstructor,
Type,
Value,
};
use std::cell::RefCell;
@ -24,7 +32,12 @@ use leo_errors::{emitter::Handler, loop_unroller::LoopUnrollerError};
use leo_span::Symbol;
use crate::{
constant_propagation_table::ConstantPropagationTable, Clusivity, LoopBound, RangeIterator, SymbolTable, TypeTable,
constant_propagation_table::ConstantPropagationTable,
Clusivity,
LoopBound,
RangeIterator,
SymbolTable,
TypeTable,
};
pub struct Unroller<'a> {
@ -68,11 +81,7 @@ impl<'a> Unroller<'a> {
/// Returns the index of the current scope.
/// Note that if we are in the midst of unrolling an IterationStatement, a new scope is created.
pub(crate) fn current_scope_index(&mut self) -> usize {
if self.is_unrolling {
self.symbol_table.borrow_mut().insert_block()
} else {
self.scope_index
}
if self.is_unrolling { self.symbol_table.borrow_mut().insert_block() } else { self.scope_index }
}
/// Enters a child scope.

View File

@ -17,10 +17,29 @@
use crate::StaticSingleAssigner;
use leo_ast::{
AccessExpression, ArrayAccess, ArrayExpression, AssociatedFunction, BinaryExpression, CallExpression,
CastExpression, Composite, Expression, ExpressionConsumer, Identifier, Literal, Location, LocatorExpression,
MemberAccess, Statement, StructExpression, StructVariableInitializer, TernaryExpression, TupleAccess,
TupleExpression, UnaryExpression, UnitExpression,
AccessExpression,
ArrayAccess,
ArrayExpression,
AssociatedFunction,
BinaryExpression,
CallExpression,
CastExpression,
Composite,
Expression,
ExpressionConsumer,
Identifier,
Literal,
Location,
LocatorExpression,
MemberAccess,
Statement,
StructExpression,
StructVariableInitializer,
TernaryExpression,
TupleAccess,
TupleExpression,
UnaryExpression,
UnitExpression,
};
use leo_span::{sym, Symbol};

View File

@ -17,8 +17,17 @@
use crate::StaticSingleAssigner;
use leo_ast::{
Block, Composite, Function, FunctionConsumer, Member, Program, ProgramConsumer, ProgramScope, ProgramScopeConsumer,
StatementConsumer, StructConsumer,
Block,
Composite,
Function,
FunctionConsumer,
Member,
Program,
ProgramConsumer,
ProgramScope,
ProgramScopeConsumer,
StatementConsumer,
StructConsumer,
};
use leo_span::{sym, Symbol};

View File

@ -17,10 +17,29 @@
use crate::{RenameTable, StaticSingleAssigner};
use leo_ast::{
AccessExpression, AssertStatement, AssertVariant, AssignStatement, AssociatedFunction, Block, CallExpression,
ConditionalStatement, ConsoleStatement, ConstDeclaration, DefinitionStatement, Expression, ExpressionConsumer,
ExpressionStatement, Identifier, IterationStatement, Node, ReturnStatement, Statement, StatementConsumer,
TernaryExpression, TupleExpression, Type,
AccessExpression,
AssertStatement,
AssertVariant,
AssignStatement,
AssociatedFunction,
Block,
CallExpression,
ConditionalStatement,
ConsoleStatement,
ConstDeclaration,
DefinitionStatement,
Expression,
ExpressionConsumer,
ExpressionStatement,
Identifier,
IterationStatement,
Node,
ReturnStatement,
Statement,
StatementConsumer,
TernaryExpression,
TupleExpression,
Type,
};
use leo_span::Symbol;

View File

@ -84,9 +84,8 @@ impl<'a> ProgramVisitor<'a> for SymbolTableCreator<'a> {
false => None,
};
// Add the variable associated with the mapping to the symbol table.
if let Err(err) = self.symbol_table.insert_variable(
Location::new(program, input.identifier.name),
VariableSymbol {
if let Err(err) =
self.symbol_table.insert_variable(Location::new(program, input.identifier.name), VariableSymbol {
type_: Type::Mapping(MappingType {
key: Box::new(input.key_type.clone()),
value: Box::new(input.value_type.clone()),
@ -94,8 +93,8 @@ impl<'a> ProgramVisitor<'a> for SymbolTableCreator<'a> {
}),
span: input.span,
declaration: VariableType::Mut,
},
) {
})
{
self.handler.emit_err(err);
}
}

View File

@ -92,11 +92,7 @@ impl AwaitChecker {
parent_nodes: Vec<ConditionalTreeNode>,
) -> Vec<ConditionalTreeNode> {
// Check if a nested conditional statement signaled their existence.
if is_finalize && self.enabled {
core::mem::replace(&mut self.to_await, parent_nodes)
} else {
Vec::new()
}
if is_finalize && self.enabled { core::mem::replace(&mut self.to_await, parent_nodes) } else { Vec::new() }
}
/// Exit scope for conditional statement at current depth.

View File

@ -30,11 +30,7 @@ fn return_incorrect_type(t1: Option<Type>, t2: Option<Type>, expected: &Option<T
(Some(t1), Some(t2)) if t1 == t2 => Some(t1),
(Some(t1), Some(t2)) => {
if let Some(expected) = expected {
if &t1 != expected {
Some(t1)
} else {
Some(t2)
}
if &t1 != expected { Some(t1) } else { Some(t2) }
} else {
Some(t1)
}

View File

@ -270,11 +270,7 @@ impl<'a, N: Network> ProgramVisitor<'a> for TypeChecker<'a, N> {
.input
.iter()
.filter_map(|input| {
if let Type::Future(_) = input.type_.clone() {
Some(input.identifier.name)
} else {
None
}
if let Type::Future(_) = input.type_.clone() { Some(input.identifier.name) } else { None }
})
.collect(),
);

View File

@ -224,10 +224,13 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> {
self.visit_expression(&input.value, &Some(input.type_.clone()));
// Add constants to symbol table so that any references to them in later statements will pass TC
if let Err(err) = self.symbol_table.borrow_mut().insert_variable(
Location::new(None, input.place.name),
VariableSymbol { type_: input.type_.clone(), span: input.place.span, declaration: VariableType::Const },
) {
if let Err(err) =
self.symbol_table.borrow_mut().insert_variable(Location::new(None, input.place.name), VariableSymbol {
type_: input.type_.clone(),
span: input.place.span,
declaration: VariableType::Const,
})
{
self.handler.emit_err(err);
}
}
@ -319,10 +322,13 @@ impl<'a, N: Network> StatementVisitor<'a> for TypeChecker<'a, N> {
let scope_index = self.create_child_scope();
// Add the loop variable to the scope of the loop body.
if let Err(err) = self.symbol_table.borrow_mut().insert_variable(
Location::new(None, input.variable.name),
VariableSymbol { type_: input.type_.clone(), span: input.span(), declaration: VariableType::Const },
) {
if let Err(err) =
self.symbol_table.borrow_mut().insert_variable(Location::new(None, input.variable.name), VariableSymbol {
type_: input.type_.clone(),
span: input.span(),
declaration: VariableType::Const,
})
{
self.handler.emit_err(err);
}

View File

@ -16,7 +16,12 @@
use crate::{
type_checking::{await_checker::AwaitChecker, scope_state::ScopeState},
CallGraph, StructGraph, SymbolTable, TypeTable, VariableSymbol, VariableType,
CallGraph,
StructGraph,
SymbolTable,
TypeTable,
VariableSymbol,
VariableType,
};
use leo_ast::*;
@ -1351,10 +1356,13 @@ impl<'a, N: Network> TypeChecker<'a, N> {
type_
};
// Insert the variable into the symbol table.
if let Err(err) = self.symbol_table.borrow_mut().insert_variable(
Location::new(None, name.name),
VariableSymbol { type_: ty, span, declaration: VariableType::Mut },
) {
if let Err(err) =
self.symbol_table.borrow_mut().insert_variable(Location::new(None, name.name), VariableSymbol {
type_: ty,
span,
declaration: VariableType::Mut,
})
{
self.handler.emit_err(err);
}
}

View File

@ -17,7 +17,9 @@
use crate::span::{BytePos, CharPos, Pos, Span};
use std::{
cell::RefCell,
fmt, fs, io,
fmt,
fs,
io,
path::{Path, PathBuf},
rc::Rc,
};

View File

@ -21,7 +21,8 @@ use crate::Span;
use serde::{
de::{MapAccess, Visitor},
ser::SerializeMap,
Deserializer, Serializer,
Deserializer,
Serializer,
};
use std::fmt;

View File

@ -118,13 +118,10 @@ pub fn handle_error<T>(res: Result<T>) -> T {
pub fn run_with_args(cli: CLI) -> Result<()> {
if !cli.quiet {
// Init logger with optional debug flag.
logger::init_logger(
"leo",
match cli.debug {
false => 1,
true => 2,
},
)?;
logger::init_logger("leo", match cli.debug {
false => 1,
true => 2,
})?;
}
// Get custom root folder and create context for it.
@ -150,7 +147,8 @@ pub fn run_with_args(cli: CLI) -> Result<()> {
mod tests {
use crate::cli::{
cli::{test_helpers, Commands},
run_with_args, CLI,
run_with_args,
CLI,
};
use leo_span::symbol::create_session_if_not_set_then;
use serial_test::serial;

View File

@ -58,11 +58,7 @@ impl Command for Transaction {
format!("find/transactionID/deployment/{}", check_valid_program_name(program))
} else if let Some(id) = self.id {
is_valid_transaction_id(&id)?;
if self.confirmed {
format!("transaction/confirmed/{}", id)
} else {
format!("transaction/{}", id)
}
if self.confirmed { format!("transaction/confirmed/{}", id) } else { format!("transaction/{}", id) }
} else {
unreachable!("All command paths covered.")
};

View File

@ -58,11 +58,7 @@ pub fn is_valid_transition_id(transition: &str) -> Result<(), LeoError> {
// A valid numerical input is a u32.
pub fn is_valid_numerical_input(num: &str) -> Result<(), LeoError> {
if num.parse::<u32>().is_err() {
Err(UtilError::invalid_numerical_input(num).into())
} else {
Ok(())
}
if num.parse::<u32>().is_err() { Err(UtilError::invalid_numerical_input(num).into()) } else { Ok(()) }
}
// A valid height or hash.

View File

@ -33,16 +33,12 @@ pub enum Snapshot {
impl fmt::Display for Snapshot {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"{}",
match self {
Self::Initial => "initial_ast",
Self::ImportsResolved => "imports_resolved_ast",
Self::TypeInference => "type_inferenced_ast",
Self::Canonicalization => "canonicalization_ast",
}
)
write!(f, "{}", match self {
Self::Initial => "initial_ast",
Self::ImportsResolved => "imports_resolved_ast",
Self::TypeInference => "type_inferenced_ast",
Self::Canonicalization => "canonicalization_ast",
})
}
}

View File

@ -23,7 +23,8 @@ use serde::Deserialize;
use std::{
borrow::Cow,
fs::{
File, {self},
File,
{self},
},
io::Write,
path::Path,

View File

@ -23,7 +23,8 @@ use serde::Deserialize;
use std::{
borrow::Cow,
fs::{
File, {self},
File,
{self},
},
io::Write,
path::Path,

View File

@ -38,13 +38,8 @@ pub enum TestError {
impl fmt::Display for TestError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let format_test = |test: &str| -> String {
if test.len() > 50 {
String::new()
} else {
format!("\n\n{test}\n\n")
}
};
let format_test =
|test: &str| -> String { if test.len() > 50 { String::new() } else { format!("\n\n{test}\n\n") } };
match self {
TestError::Panicked { test, index, error } => {
write!(f, "test #{}: {}encountered a rust panic:\n{}", index + 1, format_test(test), error)

View File

@ -244,14 +244,11 @@ pub fn run_tests<T: Runner>(runner: &T, expectation_category: &str) {
if errors.is_empty() {
if expectations.is_none() {
outputs.push((
expectation_path,
TestExpectation {
namespace: config.namespace,
expectation: config.expectation,
outputs: new_outputs,
},
));
outputs.push((expectation_path, TestExpectation {
namespace: config.namespace,
expectation: config.expectation,
outputs: new_outputs,
}));
}
pass_categories += 1;
} else {