From c7dcda473e53bc09c76c881f7612d94263880525 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:27:20 +0100 Subject: [PATCH] chore: use `push_err` more in elaborator (#5336) # Description ## Problem\* Resolves ## Summary\* Quick PR to make more use of the `push_err` helper when creating errors in the elaborator. ## Additional Context ## Documentation\* Check one: - [x] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- compiler/noirc_frontend/src/elaborator/mod.rs | 18 ++++++------------ .../noirc_frontend/src/elaborator/types.rs | 12 +++++------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/compiler/noirc_frontend/src/elaborator/mod.rs b/compiler/noirc_frontend/src/elaborator/mod.rs index d0fdea50572..d18b9e34dc5 100644 --- a/compiler/noirc_frontend/src/elaborator/mod.rs +++ b/compiler/noirc_frontend/src/elaborator/mod.rs @@ -484,12 +484,11 @@ impl<'context> Elaborator<'context> { self.resolve_type(typ.clone()) }; if !matches!(typ, Type::FieldElement | Type::Integer(_, _)) { - let unsupported_typ_err = - CompilationError::ResolverError(ResolverError::UnsupportedNumericGenericType { - ident: ident.clone(), - typ: typ.clone(), - }); - self.errors.push((unsupported_typ_err, self.file)); + let unsupported_typ_err = ResolverError::UnsupportedNumericGenericType { + ident: ident.clone(), + typ: typ.clone(), + }; + self.push_err(unsupported_typ_err); } Kind::Numeric(Box::new(typ)) } else { @@ -788,12 +787,7 @@ impl<'context> Elaborator<'context> { let definition = DefinitionKind::GenericType(type_variable); self.add_variable_decl_inner(ident.clone(), false, false, false, definition); - self.errors.push(( - CompilationError::ResolverError(ResolverError::UseExplicitNumericGeneric { - ident, - }), - self.file, - )); + self.push_err(ResolverError::UseExplicitNumericGeneric { ident }); } } } diff --git a/compiler/noirc_frontend/src/elaborator/types.rs b/compiler/noirc_frontend/src/elaborator/types.rs index 514d5786d56..63cab40f9d3 100644 --- a/compiler/noirc_frontend/src/elaborator/types.rs +++ b/compiler/noirc_frontend/src/elaborator/types.rs @@ -11,7 +11,6 @@ use crate::{ }, hir::{ comptime::{Interpreter, Value}, - def_collector::dc_crate::CompilationError, def_map::ModuleDefId, resolution::{ errors::ResolverError, @@ -170,12 +169,11 @@ impl<'context> Elaborator<'context> { // } if let Type::NamedGeneric(_, name, resolved_kind) = &resolved_type { if matches!(resolved_kind, Kind::Numeric { .. }) && matches!(kind, Kind::Normal) { - let expected_typ_err = - CompilationError::ResolverError(ResolverError::NumericGenericUsedForType { - name: name.to_string(), - span: span.expect("Type should have span"), - }); - self.errors.push((expected_typ_err, self.file)); + let expected_typ_err = ResolverError::NumericGenericUsedForType { + name: name.to_string(), + span: span.expect("Type should have span"), + }; + self.push_err(expected_typ_err); return Type::Error; } }