Skip to content

Commit

Permalink
Mark error ctors as #[cold]
Browse files Browse the repository at this point in the history
  • Loading branch information
Phantomical committed Feb 2, 2024
1 parent e74866b commit 89e8e4b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ pub(crate) struct LexerError {
}

impl LexerError {
#[cold]
pub(crate) fn unexpected_token(found: &str, expected: impl Into<Expected>) -> Self {
Self {
found: found.into(),
expected: expected.into(),
}
}

#[cold]
pub(crate) fn unexpected_eof(expected: impl Into<Expected>) -> Self {
Self {
found: "".into(),
Expand Down Expand Up @@ -69,27 +71,31 @@ pub(crate) use self::detail::Error as ErrorDetail;
pub struct Error(ErrorDetail);

impl Error {
#[cold]
pub(crate) fn parse_int(value: &str, error: std::num::ParseIntError) -> Self {
Self(ErrorDetail::ParseInt {
value: value.into(),
error,
})
}

#[cold]
pub(crate) fn parse_float(value: &str, error: std::num::ParseFloatError) -> Self {
Self(ErrorDetail::ParseFloat {
value: value.into(),
error,
})
}

#[cold]
pub(crate) fn unexpected_token(token: Token, expected: impl Into<Expected>) -> Self {
Self(ErrorDetail::Lexer(LexerError::unexpected_token(
token.value,
expected,
)))
}

#[cold]
pub(crate) fn invalid_string_literal(
_value: &str,
message: impl Into<Cow<'static, str>>,
Expand Down

0 comments on commit 89e8e4b

Please sign in to comment.