Skip to content

Commit

Permalink
fix: derive Clone for ParseProgramError and lower-level errors (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow53 authored Sep 5, 2024
1 parent 61cca31 commit 2d5eda3
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 11 deletions.
7 changes: 4 additions & 3 deletions quil-rs/src/parser/error/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::parser::error::{ErrorInput, GenericParseError, InternalError};
use nom::error::{Error as NomError, ParseError};
use std::convert::Infallible;
use std::fmt;
use std::sync::Arc;
use thiserror::__private::AsDynError;

/// An error that may occur while parsing.
Expand All @@ -34,7 +35,7 @@ use thiserror::__private::AsDynError;
/// user-readable backtrace of the errors that caused this one.
///
/// When displaying errors to end-users, prefer the alternate format for easier debugging.
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct Error<E = Infallible>
where
E: std::error::Error + Send,
Expand All @@ -43,7 +44,7 @@ where
column: usize,
snippet: String,
kind: ErrorKind<E>,
previous: Option<Box<dyn std::error::Error + 'static + Send + Sync>>,
previous: Option<Arc<dyn std::error::Error + 'static + Send + Sync>>,
}

impl<I, E> From<InternalError<I, E>> for Error<E>
Expand Down Expand Up @@ -95,7 +96,7 @@ where
where
E2: std::error::Error + 'static + Send + Sync,
{
self.previous = Some(Box::new(previous));
self.previous = Some(Arc::new(previous));
self
}

Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/parser/error/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where
}

/// A parsing error that has not been converted to something more user-friendly.
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
#[derive(Clone, Debug, thiserror::Error, PartialEq, Eq)]
#[error("internal parsing error: {0:?}")]
pub struct GenericParseError(NomErrorKind);

Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/parser/error/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::parser::error::GenericParseError;

/// Kinds of errors that can occur while parsing.
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
#[derive(Clone, Debug, thiserror::Error, PartialEq, Eq)]
pub enum ErrorKind<E: std::error::Error> {
/// An internal error, i.e. one that does not have a more helpful error.
#[error(transparent)]
Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/parser/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub type ParseError = Error<ParserErrorKind>;

/// Parsing errors specific to Quil parsing.
#[allow(dead_code)]
#[derive(Debug, thiserror::Error, PartialEq)]
#[derive(Clone, Debug, thiserror::Error, PartialEq)]
pub enum ParserErrorKind {
/// Reached end of input, but expected something else.
#[error("expected {0}, found EOF")]
Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/parser/lexer/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) type InternalLexError<'a> = InternalError<super::LexInput<'a>, LexErr
pub type LexError = Error<LexErrorKind>;

/// Kinds of errors that may occur while lexing Quil input.
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
#[derive(Clone, Debug, thiserror::Error, PartialEq, Eq)]
pub enum LexErrorKind {
/// Expected this particular raw string.
#[error("expected {0:?}")]
Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/program/error/leftover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::fmt;
/// The parser returned success, but there was unexpected leftover input.
///
/// This error contains the parsed item, which can be accessed using [`LeftoverError::recover`].
#[derive(Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LeftoverError<O> {
line: u32,
column: usize,
Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/program/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use result::{disallow_leftover, map_parsed, recover};
pub use syntax::SyntaxError;

/// Errors that may occur while parsing a [`Program`](crate::program::Program).
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum ParseProgramError<T> {
InvalidCalibration {
instruction: Instruction,
Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/program/error/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use super::LeftoverError;
/// see a backtrace of errors that caused this one.
///
/// See also [`Error`](crate::parser::Error).
#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub enum SyntaxError<T> {
LexError(LexError),
ParseError(ParseError),
Expand Down
2 changes: 1 addition & 1 deletion quil-rs/src/program/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod memory;
pub mod scheduling;
pub mod type_check;

#[derive(Debug, thiserror::Error, PartialEq)]
#[derive(Clone, Debug, PartialEq, thiserror::Error)]
pub enum ProgramError {
#[error("{0}")]
ParsingError(#[from] ParseProgramError<Program>),
Expand Down

0 comments on commit 2d5eda3

Please sign in to comment.