Skip to content

Commit

Permalink
chore: box ParserErrors in InterpreterError (#7373)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Feb 14, 2025
1 parent 3878037 commit 2b6db07
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/comptime/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub enum InterpreterError {
location: Location,
},
FailedToParseMacro {
error: ParserError,
error: Box<ParserError>,
tokens: String,
rule: &'static str,
file: FileId,
Expand Down Expand Up @@ -539,7 +539,7 @@ impl<'a> From<&'a InterpreterError> for CustomDiagnostic {

let push_the_problem_on_the_library_author = "To avoid this error in the future, try adding input validation to your macro. Erroring out early with an `assert` can be a good way to provide a user-friendly error message".into();

let mut diagnostic = CustomDiagnostic::from(error);
let mut diagnostic = CustomDiagnostic::from(error.as_ref());
// Swap the parser's primary note to become the secondary note so that it is
// more clear this error originates from failing to parse a macro.
let secondary = std::mem::take(&mut diagnostic.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ where
F: FnOnce(&mut Parser<'a>) -> T,
{
Parser::for_tokens(quoted).parse_result(parsing_function).map_err(|mut errors| {
let error = errors.swap_remove(0);
let error = Box::new(errors.swap_remove(0));
let tokens = tokens_to_string(tokens, interner);
InterpreterError::FailedToParseMacro { error, tokens, rule, file: location.file }
})
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/comptime/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl Value {
Ok(expr)
}
Err(mut errors) => {
let error = errors.swap_remove(0);
let error = Box::new(errors.swap_remove(0));
let file = location.file;
let rule = "an expression";
let tokens = tokens_to_string(tokens, elaborator.interner);
Expand Down Expand Up @@ -608,7 +608,7 @@ where
Ok(expr)
}
Err(mut errors) => {
let error = errors.swap_remove(0);
let error = Box::new(errors.swap_remove(0));
let file = location.file;
let tokens = tokens_to_string(tokens, elaborator.interner);
Err(InterpreterError::FailedToParseMacro { error, file, tokens, rule })
Expand Down

0 comments on commit 2b6db07

Please sign in to comment.