From 6ac6d81843e728fddd79cb64fd401115b9a3cbea Mon Sep 17 00:00:00 2001 From: Yordan Madzhunkov Date: Mon, 25 Sep 2023 18:36:33 +0300 Subject: [PATCH] Apply cargo fmt --- .../src/hir/def_collector/dc_crate.rs | 7 ++---- .../src/hir/def_collector/dc_mod.rs | 22 ++++++++++--------- .../src/hir/def_collector/errors.rs | 8 +++---- .../noirc_frontend/src/hir/def_map/mod.rs | 14 +++++++----- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs b/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs index ae652164be1..0a4b3bc2a70 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs @@ -25,8 +25,8 @@ use crate::{ }; use fm::FileId; use iter_extended::vecmap; -use noirc_errors::Span; use noirc_errors::CustomDiagnostic; +use noirc_errors::Span; use std::collections::{BTreeMap, HashMap}; use std::rc::Rc; use std::vec; @@ -100,7 +100,6 @@ pub enum CompilationError { TypeError(TypeCheckError), } - impl From for CustomDiagnostic { fn from(value: CompilationError) -> Self { match value { @@ -135,8 +134,6 @@ impl From for CompilationError { } } - - /// Maps the type and the module id in which the impl is defined to the functions contained in that /// impl along with the generics declared on the impl itself. This also contains the Span /// of the object_type of the impl, used to issue an error if the object type fails to resolve. @@ -328,7 +325,7 @@ fn collect_impls( ) -> Vec<(CompilationError, FileId)> { let interner = &mut context.def_interner; let def_maps = &mut context.def_maps; - let mut errors :Vec<(CompilationError, FileId)> =vec![]; + let mut errors: Vec<(CompilationError, FileId)> = vec![]; for ((unresolved_type, module_id), methods) in collected_impls { let path_resolver = diff --git a/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs b/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs index b492e2f64be..99b7ed9a7f6 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs @@ -18,8 +18,8 @@ use crate::{ use super::{ dc_crate::{ - CompilationError, DefCollector, UnresolvedFunctions, UnresolvedGlobal, - UnresolvedTraitImpl, UnresolvedTypeAlias, + CompilationError, DefCollector, UnresolvedFunctions, UnresolvedGlobal, UnresolvedTraitImpl, + UnresolvedTypeAlias, }, errors::{DefCollectorErrorKind, DuplicateType}, }; @@ -503,7 +503,7 @@ impl<'a> ModCollector<'a> { submodules: Vec, file_id: FileId, ) -> Vec<(CompilationError, FileId)> { - let mut errors :Vec<(CompilationError, FileId)> = vec![]; + let mut errors: Vec<(CompilationError, FileId)> = vec![]; for submodule in submodules { match self.push_child_module(&submodule.name, file_id, true, submodule.is_contract) { Ok(child) => { @@ -539,7 +539,8 @@ impl<'a> ModCollector<'a> { Ok(child_file_id) => child_file_id, Err(expected_path) => { let mod_name = mod_name.clone(); - let err = DefCollectorErrorKind::UnresolvedModuleDecl { mod_name, expected_path }; + let err = + DefCollectorErrorKind::UnresolvedModuleDecl { mod_name, expected_path }; errors.push((err.into(), self.file_id)); return errors; } @@ -550,13 +551,13 @@ impl<'a> ModCollector<'a> { if let Some(old_location) = context.visited_files.get(&child_file_id) { let error = DefCollectorErrorKind::ModuleAlreadyPartOfCrate { mod_name: mod_name.clone(), - span: location.span, + span: location.span, }; errors.push((error.into(), location.file)); - let error2 = DefCollectorErrorKind::ModuleOrignallyDefined { - mod_name: mod_name.clone(), - span: old_location.span + let error2 = DefCollectorErrorKind::ModuleOrignallyDefined { + mod_name: mod_name.clone(), + span: old_location.span, }; errors.push((error2.into(), old_location.file)); return errors; @@ -568,8 +569,9 @@ impl<'a> ModCollector<'a> { //let ast = parse_file(&context.file_manager, child_file_id, errors); let (ast, parsing_errors) = parse_file(&context.file_manager, child_file_id); - errors - .extend(parsing_errors.iter().map(|e| (e.clone().into(), child_file_id)).collect::>()); + errors.extend( + parsing_errors.iter().map(|e| (e.clone().into(), child_file_id)).collect::>(), + ); // Add module into def collector and get a ModuleId match self.push_child_module(mod_name, child_file_id, true, false) { diff --git a/compiler/noirc_frontend/src/hir/def_collector/errors.rs b/compiler/noirc_frontend/src/hir/def_collector/errors.rs index f0510fd284c..3c611baa379 100644 --- a/compiler/noirc_frontend/src/hir/def_collector/errors.rs +++ b/compiler/noirc_frontend/src/hir/def_collector/errors.rs @@ -49,9 +49,9 @@ pub enum DefCollectorErrorKind { #[error("Missing Trait method implementation")] TraitMissingMethod { trait_name: Ident, method_name: Ident, trait_impl_span: Span }, #[error("Module is already part of the crate")] - ModuleAlreadyPartOfCrate {mod_name: Ident, span: Span}, + ModuleAlreadyPartOfCrate { mod_name: Ident, span: Span }, #[error("Module was originally declared here")] - ModuleOrignallyDefined {mod_name: Ident, span: Span }, + ModuleOrignallyDefined { mod_name: Ident, span: Span }, #[cfg(feature = "aztec")] #[error("Aztec dependency not found. Please add aztec as a dependency in your Cargo.toml")] AztecNotFound {}, @@ -173,12 +173,12 @@ impl From for Diagnostic { span, ) } - DefCollectorErrorKind::ModuleAlreadyPartOfCrate {mod_name, span } => { + DefCollectorErrorKind::ModuleAlreadyPartOfCrate { mod_name, span } => { let message = format!("Module '{mod_name}' is already part of the crate"); let secondary = String::new(); Diagnostic::simple_error(message, secondary, span) } - DefCollectorErrorKind::ModuleOrignallyDefined {mod_name, span } => { + DefCollectorErrorKind::ModuleOrignallyDefined { mod_name, span } => { let message = format!("Note: {mod_name} was originally declared here"); let secondary = String::new(); Diagnostic::simple_error(message, secondary, span) diff --git a/compiler/noirc_frontend/src/hir/def_map/mod.rs b/compiler/noirc_frontend/src/hir/def_map/mod.rs index 0140ad76588..4226454f903 100644 --- a/compiler/noirc_frontend/src/hir/def_map/mod.rs +++ b/compiler/noirc_frontend/src/hir/def_map/mod.rs @@ -1,5 +1,5 @@ use crate::graph::CrateId; -use crate::hir::def_collector::dc_crate::{DefCollector, CompilationError}; +use crate::hir::def_collector::dc_crate::{CompilationError, DefCollector}; use crate::hir::Context; use crate::node_interner::{FuncId, NodeInterner}; use crate::parser::{parse_program, ParsedModule, ParserError}; @@ -17,7 +17,6 @@ pub use module_data::*; mod namespace; pub use namespace::*; - #[cfg(feature = "aztec")] mod aztec_library; @@ -70,13 +69,16 @@ pub struct CrateDefMap { impl CrateDefMap { /// Collect all definitions in the crate - pub fn collect_defs(crate_id: CrateId, context: &mut Context) -> Vec<(CompilationError, FileId)> { + pub fn collect_defs( + crate_id: CrateId, + context: &mut Context, + ) -> Vec<(CompilationError, FileId)> { // Check if this Crate has already been compiled // XXX: There is probably a better alternative for this. // Without this check, the compiler will panic as it does not // expect the same crate to be processed twice. It would not // make the implementation wrong, if the same crate was processed twice, it just makes it slow. - let mut errors :Vec<(CompilationError, FileId)> = vec![]; + let mut errors: Vec<(CompilationError, FileId)> = vec![]; if context.def_map(&crate_id).is_some() { return errors; } @@ -108,7 +110,9 @@ impl CrateDefMap { // Now we want to populate the CrateDefMap using the DefCollector errors.extend(DefCollector::collect(def_map, context, ast, root_file_id)); - errors.extend(parsing_errors.iter().map(|e| (e.clone().into(), root_file_id)).collect::>()); + errors.extend( + parsing_errors.iter().map(|e| (e.clone().into(), root_file_id)).collect::>(), + ); errors }