diff --git a/lib/src/compiler/errors.rs b/lib/src/compiler/errors.rs index 08227cfee..29fa76bbb 100644 --- a/lib/src/compiler/errors.rs +++ b/lib/src/compiler/errors.rs @@ -36,47 +36,16 @@ pub enum Error { ParseError(#[from] ParseError), #[error(transparent)] - CompileError(#[from] CompileError), + CompileError(#[from] Box), #[error(transparent)] VariableError(#[from] VariableError), } -/// Error produced while compiling rules. -#[derive(Eq, PartialEq)] -pub struct CompileError(Box); - -impl CompileError { - /// Returns additional information about the error. - pub fn info(&self) -> &CompileErrorInfo { - self.0.as_ref() - } -} - -impl Debug for CompileError { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{:?}", self.0) - } -} - -impl Display for CompileError { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} - -impl From for CompileError { - fn from(value: CompileErrorInfo) -> Self { - Self(Box::new(value)) - } -} - -impl std::error::Error for CompileError {} - /// An error occurred during the compilation process. #[derive(DeriveError, Eq, PartialEq)] #[non_exhaustive] -pub enum CompileErrorInfo { +pub enum CompileError { #[error("wrong type")] #[label( "expression should be {expected_types}, but is `{actual_type}`", diff --git a/lib/src/compiler/ir/ast2ir.rs b/lib/src/compiler/ir/ast2ir.rs index c966a4d82..7ef06eb9d 100644 --- a/lib/src/compiler/ir/ast2ir.rs +++ b/lib/src/compiler/ir/ast2ir.rs @@ -17,7 +17,7 @@ use crate::compiler::ir::{ MatchAnchor, Of, OfItems, Pattern, PatternFlagSet, PatternFlags, PatternIdx, PatternInRule, Quantifier, Range, RegexpPattern, }; -use crate::compiler::{CompileContext, CompileError, CompileErrorInfo}; +use crate::compiler::{CompileContext, CompileError}; use crate::modules::BUILTIN_MODULES; use crate::re; use crate::re::parser::Error; @@ -27,18 +27,18 @@ use crate::types::{Map, Regexp, Type, TypeValue, Value}; pub(in crate::compiler) fn patterns_from_ast<'src>( report_builder: &ReportBuilder, patterns: Option<&Vec>>, -) -> Result>, CompileError> { +) -> Result>, Box> { patterns .into_iter() .flatten() .map(|p| pattern_from_ast(report_builder, p)) - .collect::>, CompileError>>() + .collect::>, Box>>() } fn pattern_from_ast<'src>( report_builder: &ReportBuilder, pattern: &ast::Pattern<'src>, -) -> Result, CompileError> { +) -> Result, Box> { match pattern { ast::Pattern::Text(pattern) => { Ok(text_pattern_from_ast(report_builder, pattern)?) @@ -55,7 +55,7 @@ fn pattern_from_ast<'src>( pub(in crate::compiler) fn text_pattern_from_ast<'src>( _report_builder: &ReportBuilder, pattern: &ast::TextPattern<'src>, -) -> Result, CompileError> { +) -> Result, Box> { let mut flags = PatternFlagSet::none(); if pattern.modifiers.ascii().is_some() @@ -108,7 +108,6 @@ pub(in crate::compiler) fn text_pattern_from_ast<'src>( base64_alphabet: base64_alphabet.map(String::from), base64wide_alphabet: base64wide_alphabet.map(String::from), anchored_at: None, - text: pattern.text.as_ref().into(), }), }) @@ -117,7 +116,7 @@ pub(in crate::compiler) fn text_pattern_from_ast<'src>( pub(in crate::compiler) fn hex_pattern_from_ast<'src>( _report_builder: &ReportBuilder, pattern: &ast::HexPattern<'src>, -) -> Result, CompileError> { +) -> Result, Box> { Ok(PatternInRule { identifier: pattern.identifier.name, pattern: Pattern::Regexp(RegexpPattern { @@ -131,7 +130,7 @@ pub(in crate::compiler) fn hex_pattern_from_ast<'src>( pub(in crate::compiler) fn regexp_pattern_from_ast<'src>( report_builder: &ReportBuilder, pattern: &ast::RegexpPattern<'src>, -) -> Result, CompileError> { +) -> Result, Box> { let mut flags = PatternFlagSet::none(); if pattern.modifiers.ascii().is_some() @@ -206,10 +205,10 @@ pub(in crate::compiler) fn regexp_pattern_from_ast<'src>( pub(in crate::compiler) fn expr_from_ast( ctx: &mut CompileContext, expr: &ast::Expr, -) -> Result { +) -> Result> { match expr { ast::Expr::Entrypoint { span } => { - Err(CompileError::from(CompileErrorInfo::entrypoint_unsupported( + Err(Box::new(CompileError::entrypoint_unsupported( ctx.report_builder, *span, Some("use `pe.entry_point`, `elf.entry_point` or `macho.entry_point`".to_string()), @@ -344,8 +343,7 @@ pub(in crate::compiler) fn expr_from_ast( }; if symbol.is_none() { - return Err(CompileError::from( - CompileErrorInfo::unknown_identifier( + return Err(Box::new(CompileError::unknown_identifier( ctx.report_builder, ident.name.to_string(), ident.span(), @@ -380,8 +378,7 @@ pub(in crate::compiler) fn expr_from_ast( let current_rule = ctx.get_current_rule(); let used_rule = ctx.get_rule(*rule_id); if current_rule.is_global && !used_rule.is_global { - return Err(CompileError::from( - CompileErrorInfo::wrong_rule_dependency( + return Err(Box::new(CompileError::wrong_rule_dependency( ctx.report_builder, ctx.ident_pool .get(current_rule.ident_id) @@ -588,8 +585,7 @@ pub(in crate::compiler) fn expr_from_ast( // The type of the key/index expression should correspond // with the type of the map's keys. if key_ty != ty { - return Err(CompileError::from( - CompileErrorInfo::wrong_type( + return Err(Box::new(CompileError::wrong_type( ctx.report_builder, format!("`{}`", key_ty), ty.to_string(), @@ -605,7 +601,7 @@ pub(in crate::compiler) fn expr_from_ast( }))) } type_value => { - Err(CompileError::from(CompileErrorInfo::wrong_type( + Err(Box::new(CompileError::wrong_type( ctx.report_builder, format!("`{}` or `{}`", Type::Array, Type::Map), type_value.ty().to_string(), @@ -620,7 +616,7 @@ pub(in crate::compiler) fn expr_from_ast( pub(in crate::compiler) fn bool_expr_from_ast( ctx: &mut CompileContext, ast: &ast::Expr, -) -> Result { +) -> Result> { let expr = expr_from_ast(ctx, ast)?; warn_if_not_bool(ctx, expr.ty(), ast.span()); Ok(expr) @@ -629,7 +625,7 @@ pub(in crate::compiler) fn bool_expr_from_ast( fn of_expr_from_ast( ctx: &mut CompileContext, of: &ast::Of, -) -> Result { +) -> Result> { let quantifier = quantifier_from_ast(ctx, &of.quantifier)?; // Create new stack frame with 5 slots: // 1 slot for the loop variable, a bool in this case. @@ -646,7 +642,7 @@ fn of_expr_from_ast( check_type(ctx, expr.ty(), e.span(), &[Type::Bool])?; Ok(expr) }) - .collect::, CompileError>>()?; + .collect::, Box>>()?; let num_items = tuple.len(); (OfItems::BoolExprTuple(tuple), num_items) @@ -734,7 +730,7 @@ fn of_expr_from_ast( fn for_of_expr_from_ast( ctx: &mut CompileContext, for_of: &ast::ForOf, -) -> Result { +) -> Result> { let quantifier = quantifier_from_ast(ctx, &for_of.quantifier)?; let pattern_set = pattern_set_from_ast(ctx, &for_of.pattern_set)?; // Create new stack frame with 5 slots: @@ -771,7 +767,7 @@ fn for_of_expr_from_ast( fn for_in_expr_from_ast( ctx: &mut CompileContext, for_in: &ast::ForIn, -) -> Result { +) -> Result> { let quantifier = quantifier_from_ast(ctx, &for_in.quantifier)?; let iterable = iterable_from_ast(ctx, &for_in.iterable)?; @@ -782,7 +778,7 @@ fn for_in_expr_from_ast( // the type of the first item in the tuple as the type of the // loop variable. Notice that we are using `clone_without_value` // instead of `clone`, because we want a TypeValue with the same - // type than the first item in the tuple, but we don't want to + // type as the first item in the tuple, but we don't want to // clone its actual value if known. The actual value for the // loop variable is not known until the loop is executed. vec![expressions @@ -814,15 +810,13 @@ fn for_in_expr_from_ast( if loop_vars.len() != expected_vars.len() { let span = loop_vars.first().unwrap().span(); let span = span.combine(&loop_vars.last().unwrap().span()); - return Err(CompileError::from( - CompileErrorInfo::assignment_mismatch( - ctx.report_builder, - loop_vars.len() as u8, - expected_vars.len() as u8, - for_in.iterable.span(), - span, - ), - )); + return Err(Box::new(CompileError::assignment_mismatch( + ctx.report_builder, + loop_vars.len() as u8, + expected_vars.len() as u8, + for_in.iterable.span(), + span, + ))); } // Create stack frame with capacity for the loop variables, plus 4 @@ -866,7 +860,7 @@ fn for_in_expr_from_ast( fn iterable_from_ast( ctx: &mut CompileContext, iter: &ast::Iterable, -) -> Result { +) -> Result> { match iter { ast::Iterable::Range(range) => { Ok(Iterable::Range(range_from_ast(ctx, range)?)) @@ -898,8 +892,8 @@ fn iterable_from_ast( // type mismatch. if let Some((prev_ty, prev_span)) = prev { if prev_ty != ty { - return Err(CompileError::from( - CompileErrorInfo::mismatching_types( + return Err(Box::new( + CompileError::mismatching_types( ctx.report_builder, prev_ty.to_string(), ty.to_string(), @@ -920,7 +914,7 @@ fn iterable_from_ast( fn anchor_from_ast( ctx: &mut CompileContext, anchor: &Option, -) -> Result { +) -> Result> { match anchor { Some(ast::MatchAnchor::At(at_)) => Ok(MatchAnchor::At(Box::new( non_negative_integer_from_ast(ctx, &at_.expr)?, @@ -935,7 +929,7 @@ fn anchor_from_ast( fn range_from_ast( ctx: &mut CompileContext, range: &ast::Range, -) -> Result { +) -> Result> { let lower_bound = Box::new(non_negative_integer_from_ast(ctx, &range.lower_bound)?); @@ -952,7 +946,7 @@ fn range_from_ast( ) = (lower_bound.type_value(), upper_bound.type_value()) { if lower_bound > upper_bound { - return Err(CompileError::from(CompileErrorInfo::invalid_range( + return Err(Box::new(CompileError::invalid_range( ctx.report_builder, range.span, ))); @@ -965,7 +959,7 @@ fn range_from_ast( fn non_negative_integer_from_ast( ctx: &mut CompileContext, expr: &ast::Expr, -) -> Result { +) -> Result> { let span = expr.span(); let expr = expr_from_ast(ctx, expr)?; let type_value = expr.type_value(); @@ -974,12 +968,10 @@ fn non_negative_integer_from_ast( if let TypeValue::Integer(Value::Const(value)) = type_value { if value < 0 { - return Err(CompileError::from( - CompileErrorInfo::unexpected_negative_number( - ctx.report_builder, - span, - ), - )); + return Err(Box::new(CompileError::unexpected_negative_number( + ctx.report_builder, + span, + ))); } } @@ -990,7 +982,7 @@ fn integer_in_range_from_ast( ctx: &mut CompileContext, expr: &ast::Expr, range: RangeInclusive, -) -> Result { +) -> Result> { let span = expr.span(); let expr = expr_from_ast(ctx, expr)?; let type_value = expr.type_value(); @@ -1001,14 +993,12 @@ fn integer_in_range_from_ast( // the given range. if let TypeValue::Integer(Value::Const(value)) = type_value { if !range.contains(&value) { - return Err(CompileError::from( - CompileErrorInfo::number_out_of_range( - ctx.report_builder, - *range.start(), - *range.end(), - span, - ), - )); + return Err(Box::new(CompileError::number_out_of_range( + ctx.report_builder, + *range.start(), + *range.end(), + span, + ))); } } @@ -1018,7 +1008,7 @@ fn integer_in_range_from_ast( fn quantifier_from_ast( ctx: &mut CompileContext, quantifier: &ast::Quantifier, -) -> Result { +) -> Result> { match quantifier { ast::Quantifier::None { .. } => Ok(Quantifier::None), ast::Quantifier::All { .. } => Ok(Quantifier::All), @@ -1040,7 +1030,7 @@ fn quantifier_from_ast( fn pattern_set_from_ast( ctx: &mut CompileContext, pattern_set: &ast::PatternSet, -) -> Result, CompileError> { +) -> Result, Box> { let pattern_indexes = match pattern_set { // `x of them` ast::PatternSet::Them { span } => { @@ -1050,16 +1040,11 @@ fn pattern_set_from_ast( .collect(); if pattern_indexes.is_empty() { - return Err(CompileError::from( - CompileErrorInfo::empty_pattern_set( - ctx.report_builder, - *span, - Some( - "this rule doesn't define any patterns" - .to_string(), - ), - ), - )); + return Err(Box::new(CompileError::empty_pattern_set( + ctx.report_builder, + *span, + Some("this rule doesn't define any patterns".to_string()), + ))); } // Make all the patterns in the set non-anchorable. @@ -1077,16 +1062,14 @@ fn pattern_set_from_ast( .iter() .any(|pattern| item.matches(pattern.identifier())) { - return Err(CompileError::from( - CompileErrorInfo::empty_pattern_set( - ctx.report_builder, - item.span(), - Some(format!( - "`{}` doesn't match any pattern identifier", - item.identifier, - )), - ), - )); + return Err(Box::new(CompileError::empty_pattern_set( + ctx.report_builder, + item.span(), + Some(format!( + "`{}` doesn't match any pattern identifier", + item.identifier, + )), + ))); } } let mut pattern_indexes = Vec::new(); @@ -1111,7 +1094,7 @@ fn pattern_set_from_ast( fn func_call_from_ast( ctx: &mut CompileContext, func_call: &ast::FuncCall, -) -> Result { +) -> Result> { let callable = expr_from_ast(ctx, &func_call.callable)?; let type_value = callable.type_value(); @@ -1126,7 +1109,7 @@ fn func_call_from_ast( .args .iter() .map(|arg| expr_from_ast(ctx, arg)) - .collect::, CompileError>>()?; + .collect::, Box>>()?; let arg_types: Vec = args.iter().map(|arg| arg.ty()).collect(); @@ -1158,7 +1141,7 @@ fn func_call_from_ast( // No matching signature was found, that means that the arguments // provided were incorrect. if matching_signature.is_none() { - return Err(CompileError::from(CompileErrorInfo::wrong_arguments( + return Err(Box::new(CompileError::wrong_arguments( ctx.report_builder, func_call.args_span, Some(format!( @@ -1193,7 +1176,7 @@ fn func_call_from_ast( fn matches_expr_from_ast( ctx: &mut CompileContext, expr: &ast::BinaryExpr, -) -> Result { +) -> Result> { let lhs_span = expr.lhs.span(); let rhs_span = expr.rhs.span(); @@ -1217,11 +1200,11 @@ fn check_type( ty: Type, span: Span, accepted_types: &[Type], -) -> Result<(), CompileError> { +) -> Result<(), Box> { if accepted_types.contains(&ty) { Ok(()) } else { - Err(CompileError::from(CompileErrorInfo::wrong_type( + Err(Box::new(CompileError::wrong_type( ctx.report_builder, ErrorInfo::join_with_or(accepted_types, true), ty.to_string(), @@ -1235,11 +1218,11 @@ fn check_type2( expr: &ast::Expr, ty: Type, accepted_types: &[Type], -) -> Result<(), CompileError> { +) -> Result<(), Box> { if accepted_types.contains(&ty) { Ok(()) } else { - Err(CompileError::from(CompileErrorInfo::wrong_type( + Err(Box::new(CompileError::wrong_type( ctx.report_builder, ErrorInfo::join_with_or(accepted_types, true), ty.to_string(), @@ -1256,7 +1239,7 @@ fn check_operands( rhs_span: Span, accepted_types: &[Type], compatible_types: &[Type], -) -> Result<(), CompileError> { +) -> Result<(), Box> { // Both types must be known. assert!(!matches!(lhs_ty, Type::Unknown)); assert!(!matches!(rhs_ty, Type::Unknown)); @@ -1276,7 +1259,7 @@ fn check_operands( }; if !types_are_compatible { - return Err(CompileError::from(CompileErrorInfo::mismatching_types( + return Err(Box::new(CompileError::mismatching_types( ctx.report_builder, lhs_ty.to_string(), rhs_ty.to_string(), @@ -1295,27 +1278,27 @@ fn re_error_to_compile_error( ) -> CompileError { match err { Error::SyntaxError { msg, span } => { - CompileError::from(CompileErrorInfo::invalid_regexp( + CompileError::invalid_regexp( report_builder, msg, // the error span is relative to the start of the regexp, not to // the start of the source file, here we make it relative to the // source file. regexp.span.subspan(span.start.offset, span.end.offset), - )) + ) } Error::MixedGreediness { is_greedy_1, is_greedy_2, span_1, span_2, - } => CompileError::from(CompileErrorInfo::mixed_greediness( + } => CompileError::mixed_greediness( report_builder, if is_greedy_1 { "greedy" } else { "non-greedy" }.to_string(), if is_greedy_2 { "greedy" } else { "non-greedy" }.to_string(), regexp.span.subspan(span_1.start.offset, span_1.end.offset), regexp.span.subspan(span_2.start.offset, span_2.end.offset), - )), + ), } } @@ -1356,7 +1339,7 @@ macro_rules! gen_unary_op { fn $name( ctx: &mut CompileContext, expr: &ast::UnaryExpr, - ) -> Result { + ) -> Result> { let operand = Box::new(expr_from_ast(ctx, &expr.operand)?); // The `not` operator accepts integers, floats and strings because @@ -1369,7 +1352,7 @@ macro_rules! gen_unary_op { )?; let check_fn: - Option Result<(), CompileError>> + Option Result<(), Box>> = $check_fn; if let Some(check_fn) = check_fn { @@ -1392,7 +1375,7 @@ macro_rules! gen_binary_op { fn $name( ctx: &mut CompileContext, expr: &ast::BinaryExpr, - ) -> Result { + ) -> Result> { let lhs_span = expr.lhs.span(); let rhs_span = expr.rhs.span(); @@ -1410,7 +1393,7 @@ macro_rules! gen_binary_op { )?; let check_fn: - Option Result<(), CompileError>> + Option Result<(), Box>> = $check_fn; if let Some(check_fn) = check_fn { @@ -1433,7 +1416,7 @@ macro_rules! gen_string_op { fn $name( ctx: &mut CompileContext, expr: &ast::BinaryExpr, - ) -> Result { + ) -> Result> { let lhs_span = expr.lhs.span(); let rhs_span = expr.rhs.span(); @@ -1466,17 +1449,17 @@ macro_rules! gen_n_ary_operation { fn $name( ctx: &mut CompileContext, expr: &ast::NAryExpr, - ) -> Result { + ) -> Result> { let accepted_types = &[$( $accepted_types ),+]; let compatible_types = &[$( $compatible_types ),+]; let operands_hir: Vec = expr .operands() .map(|expr| expr_from_ast(ctx, expr)) - .collect::, CompileError>>()?; + .collect::, Box>>()?; let check_fn: - Option Result<(), CompileError>> + Option Result<(), Box>> = $check_fn; // Make sure that all operands have one of the accepted types. @@ -1507,8 +1490,7 @@ macro_rules! gen_n_ary_operation { }; if !types_are_compatible { - return Err(CompileError::from( - CompileErrorInfo::mismatching_types( + return Err(Box::new(CompileError::mismatching_types( ctx.report_builder, lhs_ty.to_string(), rhs_ty.to_string(), @@ -1630,8 +1612,8 @@ gen_binary_op!( Some(|ctx, _lhs, rhs, _lhs_span, rhs_span| { if let TypeValue::Integer(Value::Const(value)) = rhs.type_value() { if value < 0 { - return Err(CompileError::from( - CompileErrorInfo::unexpected_negative_number( + return Err(Box::new( + CompileError::unexpected_negative_number( ctx.report_builder, rhs_span, ), @@ -1650,8 +1632,8 @@ gen_binary_op!( Some(|ctx, _lhs, rhs, _lhs_span, rhs_span| { if let TypeValue::Integer(Value::Const(value)) = rhs.type_value() { if value < 0 { - return Err(CompileError::from( - CompileErrorInfo::unexpected_negative_number( + return Err(Box::new( + CompileError::unexpected_negative_number( ctx.report_builder, rhs_span, ), diff --git a/lib/src/compiler/mod.rs b/lib/src/compiler/mod.rs index 3283d943d..303b5ee9c 100644 --- a/lib/src/compiler/mod.rs +++ b/lib/src/compiler/mod.rs @@ -558,24 +558,22 @@ impl<'a> Compiler<'a> { fn check_for_existing_identifier( &self, ident: &Ident, - ) -> Result<(), CompileError> { + ) -> Result<(), Box> { if let Some(symbol) = self.symbol_table.lookup(ident.name) { return match symbol.kind() { SymbolKind::Rule(rule_id) => { - Err(CompileError::from(CompileErrorInfo::duplicate_rule( + Err(Box::new(CompileError::duplicate_rule( &self.report_builder, ident.name.to_string(), ident.span, self.rules.get(rule_id.0 as usize).unwrap().ident_span, ))) } - _ => Err(CompileError::from( - CompileErrorInfo::conflicting_rule_identifier( - &self.report_builder, - ident.name.to_string(), - ident.span, - ), - )), + _ => Err(Box::new(CompileError::conflicting_rule_identifier( + &self.report_builder, + ident.name.to_string(), + ident.span, + ))), }; } Ok(()) @@ -635,14 +633,17 @@ impl<'a> Compiler<'a> { /// creates a new field with the same name than the module in the /// top-level structure `self.root_struct` that contains all the /// imported modules. This field is created only if it don't exist yet. - fn import_module(&mut self, import: &Import) -> Result<(), CompileError> { + fn import_module( + &mut self, + import: &Import, + ) -> Result<(), Box> { let module_name = import.module_name.as_str(); let module = BUILTIN_MODULES.get(module_name); // Does a module with the given name actually exist? ... if module.is_none() { // The module does not exist, that's an error. - return Err(CompileError::from(CompileErrorInfo::unknown_module( + return Err(Box::new(CompileError::unknown_module( &self.report_builder, module_name.to_string(), import.span(), @@ -703,7 +704,7 @@ impl<'a> Compiler<'a> { } impl<'a> Compiler<'a> { - fn c_rule(&mut self, rule: &ast::Rule) -> Result<(), CompileError> { + fn c_rule(&mut self, rule: &ast::Rule) -> Result<(), Box> { // Check if another rule, module or variable has the same identifier // and return an error in that case. self.check_for_existing_identifier(&rule.identifier)?; @@ -1064,7 +1065,7 @@ impl<'a> Compiler<'a> { pattern: RegexpPattern, anchored_at: Option, span: Span, - ) -> Result<(), CompileError> { + ) -> Result<(), Box> { // Try splitting the regexp into multiple chained sub-patterns if it // contains large gaps. For example, `{ 01 02 03 [-] 04 05 06 }` is // split into `{ 01 02 03 }` and `{ 04 05 06 }`, where `{ 04 05 06 }` @@ -1227,7 +1228,7 @@ impl<'a> Compiler<'a> { trailing: &[ChainedPattern], flags: PatternFlagSet, span: Span, - ) -> Result<(), CompileError> { + ) -> Result<(), Box> { let ascii = flags.contains(PatternFlags::Ascii); let wide = flags.contains(PatternFlags::Wide); let case_insensitive = flags.contains(PatternFlags::Nocase); @@ -1371,7 +1372,7 @@ impl<'a> Compiler<'a> { &mut self, hir: &re::hir::Hir, span: Span, - ) -> Result<(Vec, bool), CompileError> { + ) -> Result<(Vec, bool), Box> { // When the `fast-regexp` feature is enabled, try to compile the regexp // for `FastVM` first, if the it fails with `Error::FastIncompatible`, // the regexp is not compatible for `FastVM` and `PikeVM` must be used @@ -1394,18 +1395,16 @@ impl<'a> Compiler<'a> { ); let mut atoms = result.map_err(|err| match err { - re::Error::TooLarge => { - CompileError::from(CompileErrorInfo::invalid_regexp( - &self.report_builder, - "regexp is too large".to_string(), - span, - )) - } + re::Error::TooLarge => Box::new(CompileError::invalid_regexp( + &self.report_builder, + "regexp is too large".to_string(), + span, + )), _ => unreachable!(), })?; if matches!(hir.minimum_len(), Some(0)) { - return Err(CompileError::from(CompileErrorInfo::invalid_regexp( + return Err(Box::new(CompileError::invalid_regexp( &self.report_builder, "this regexp can match empty strings".to_string(), span, @@ -1473,7 +1472,10 @@ impl<'a> Compiler<'a> { ) } - fn c_imports(&mut self, imports: &[Import]) -> Result<(), CompileError> { + fn c_imports( + &mut self, + imports: &[Import], + ) -> Result<(), Box> { for import in imports { // Import the module. This updates `self.root_struct` if // necessary. diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 1e94ed762..51e666fb4 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -43,7 +43,6 @@ assert_eq!(results.matching_rules().len(), 1); pub use compiler::compile; pub use compiler::CompileError; -pub use compiler::CompileErrorInfo; pub use compiler::Compiler; pub use compiler::Error; pub use compiler::Rules;