diff --git a/compiler/src/import/parser/import_parser.rs b/compiler/src/import/parser/import_parser.rs index c870f8670f..5bf3386498 100644 --- a/compiler/src/import/parser/import_parser.rs +++ b/compiler/src/import/parser/import_parser.rs @@ -21,7 +21,7 @@ use std::{collections::HashMap, env::current_dir}; /// Parses all relevant import files for a program. /// Stores compiled program structs. -#[derive(Clone)] +#[derive(Clone, Default)] pub struct ImportParser { imports: HashMap, core_packages: Vec, @@ -29,10 +29,7 @@ pub struct ImportParser { impl ImportParser { pub fn new() -> Self { - Self { - imports: HashMap::new(), - core_packages: vec![], - } + Self::default() } pub(crate) fn insert_import(&mut self, file_name: String, program: Program) { diff --git a/compiler/src/program/program.rs b/compiler/src/program/program.rs index cc9ca62f7b..24981cc59f 100644 --- a/compiler/src/program/program.rs +++ b/compiler/src/program/program.rs @@ -27,6 +27,14 @@ pub struct ConstrainedProgram> { pub identifiers: HashMap>, } +impl> Default for ConstrainedProgram { + fn default() -> Self { + Self { + identifiers: HashMap::new(), + } + } +} + pub fn new_scope(outer: String, inner: String) -> String { format!("{}_{}", outer, inner) } @@ -37,9 +45,7 @@ pub fn is_in_scope(current_scope: &String, desired_scope: &String) -> bool { impl> ConstrainedProgram { pub fn new() -> Self { - Self { - identifiers: HashMap::new(), - } + Self::default() } pub(crate) fn store(&mut self, name: String, value: ConstrainedValue) { diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index 375bf8fdcc..b2165fe5dd 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -21,6 +21,7 @@ use crate::{ use std::{collections::HashMap, convert::TryFrom, path::PathBuf}; +#[derive(Default)] pub struct InputPairs { /// Maps file names to input file pairs pub pairs: HashMap, @@ -33,7 +34,7 @@ pub struct InputPair { impl InputPairs { pub fn new() -> Self { - Self { pairs: HashMap::new() } + Self::default() } } diff --git a/package/src/root/gitignore.rs b/package/src/root/gitignore.rs index c8f03703d7..c7dddc9161 100644 --- a/package/src/root/gitignore.rs +++ b/package/src/root/gitignore.rs @@ -23,12 +23,12 @@ use std::{fs::File, io::Write, path::PathBuf}; pub static GITIGNORE_FILENAME: &str = ".gitignore"; -#[derive(Deserialize)] +#[derive(Deserialize, Default)] pub struct Gitignore; impl Gitignore { pub fn new() -> Self { - Self + Self::default() } pub fn exists_at(path: &PathBuf) -> bool { diff --git a/typed/src/input/input.rs b/typed/src/input/input.rs index 0ed2bdbf1c..823e8b6896 100644 --- a/typed/src/input/input.rs +++ b/typed/src/input/input.rs @@ -27,14 +27,20 @@ pub struct Input { program_state: ProgramState, } -impl Input { - pub fn new() -> Self { +impl Default for Input { + fn default() -> Self { Self { name: "default".to_owned(), program_input: ProgramInput::new(), program_state: ProgramState::new(), } } +} + +impl Input { + pub fn new() -> Self { + Self::default() + } /// Returns an empty version of this struct with `None` values. /// Called during constraint synthesis to provide private input variables. diff --git a/typed/src/input/macros.rs b/typed/src/input/macros.rs index 565236ad30..16276d4e1d 100644 --- a/typed/src/input/macros.rs +++ b/typed/src/input/macros.rs @@ -19,7 +19,7 @@ macro_rules! input_section_impl { ($($name: ident), *) => ($( /// An input section declared in an input file with `[$name]` - #[derive(Clone, PartialEq, Eq)] + #[derive(Clone, PartialEq, Eq, Default)] pub struct $name { is_present: bool, values: HashMap>, @@ -27,10 +27,7 @@ macro_rules! input_section_impl { impl $name { pub fn new() -> Self { - Self { - is_present: false, - values: HashMap::new(), - } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_input/main_input.rs b/typed/src/input/program_input/main_input.rs index 61f7a3fc67..90c2b1a940 100644 --- a/typed/src/input/program_input/main_input.rs +++ b/typed/src/input/program_input/main_input.rs @@ -18,14 +18,14 @@ use crate::InputValue; use leo_input::{definitions::Definition, InputParserError}; use std::collections::HashMap; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct MainInput { input: HashMap>, } impl MainInput { pub fn new() -> Self { - Self { input: HashMap::new() } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_input/program_input.rs b/typed/src/input/program_input/program_input.rs index ba823d784c..94418ba949 100644 --- a/typed/src/input/program_input/program_input.rs +++ b/typed/src/input/program_input/program_input.rs @@ -20,7 +20,7 @@ use leo_input::{ InputParserError, }; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct ProgramInput { pub main: MainInput, registers: Registers, @@ -28,10 +28,7 @@ pub struct ProgramInput { impl ProgramInput { pub fn new() -> Self { - Self { - main: MainInput::new(), - registers: Registers::new(), - } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_state/private_state/private_state.rs b/typed/src/input/program_state/private_state/private_state.rs index 28ad9070ff..489a6ff74e 100644 --- a/typed/src/input/program_state/private_state/private_state.rs +++ b/typed/src/input/program_state/private_state/private_state.rs @@ -20,7 +20,7 @@ use leo_input::{ InputParserError, }; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct PrivateState { record: Record, state_leaf: StateLeaf, @@ -28,10 +28,7 @@ pub struct PrivateState { impl PrivateState { pub fn new() -> Self { - Self { - record: Record::new(), - state_leaf: StateLeaf::new(), - } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_state/program_state.rs b/typed/src/input/program_state/program_state.rs index 8e1fbf1309..35284c700e 100644 --- a/typed/src/input/program_state/program_state.rs +++ b/typed/src/input/program_state/program_state.rs @@ -20,7 +20,7 @@ use leo_input::{ InputParserError, }; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct ProgramState { public: PublicState, private: PrivateState, @@ -28,10 +28,7 @@ pub struct ProgramState { impl ProgramState { pub fn new() -> Self { - Self { - public: PublicState::new(), - private: PrivateState::new(), - } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_state/public_state/public_state.rs b/typed/src/input/program_state/public_state/public_state.rs index 403eb48c89..3730c4bea3 100644 --- a/typed/src/input/program_state/public_state/public_state.rs +++ b/typed/src/input/program_state/public_state/public_state.rs @@ -20,14 +20,14 @@ use leo_input::{ InputParserError, }; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct PublicState { state: State, } impl PublicState { pub fn new() -> Self { - Self { state: State::new() } + Self::default() } /// Returns an empty version of this struct with `None` values.