Deprecate Error::description.
This commit is contained in:
37
src/error.rs
37
src/error.rs
@@ -20,18 +20,7 @@ pub enum LexError {
|
||||
InputError(String),
|
||||
}
|
||||
|
||||
impl Error for LexError {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
Self::UnexpectedChar(_) => "Unexpected character",
|
||||
Self::UnterminatedString => "Open string is not terminated",
|
||||
Self::MalformedEscapeSequence(_) => "Unexpected values in escape sequence",
|
||||
Self::MalformedNumber(_) => "Unexpected characters in number",
|
||||
Self::MalformedChar(_) => "Char constant not a single character",
|
||||
Self::InputError(_) => "Input error",
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Error for LexError {}
|
||||
|
||||
impl fmt::Display for LexError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
@@ -41,7 +30,7 @@ impl fmt::Display for LexError {
|
||||
Self::MalformedNumber(s) => write!(f, "Invalid number: '{}'", s),
|
||||
Self::MalformedChar(s) => write!(f, "Invalid character: '{}'", s),
|
||||
Self::InputError(s) => write!(f, "{}", s),
|
||||
_ => write!(f, "{}", self.description()),
|
||||
Self::UnterminatedString => write!(f, "Open string is not terminated"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,10 +93,8 @@ impl ParseError {
|
||||
pub fn position(&self) -> Position {
|
||||
self.1
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ParseError {
|
||||
fn description(&self) -> &str {
|
||||
pub(crate) fn desc(&self) -> &str {
|
||||
match self.0 {
|
||||
ParseErrorType::BadInput(ref p) => p,
|
||||
ParseErrorType::InputPastEndOfFile => "Script is incomplete",
|
||||
@@ -128,39 +115,35 @@ impl Error for ParseError {
|
||||
ParseErrorType::AssignmentToConstant(_) => "Cannot assign to a constant variable."
|
||||
}
|
||||
}
|
||||
|
||||
fn cause(&self) -> Option<&dyn Error> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ParseError {}
|
||||
|
||||
impl fmt::Display for ParseError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self.0 {
|
||||
ParseErrorType::BadInput(ref s)
|
||||
| ParseErrorType::MalformedIndexExpr(ref s)
|
||||
| ParseErrorType::MalformedCallExpr(ref s) => {
|
||||
write!(f, "{}", if s.is_empty() { self.description() } else { s })?
|
||||
write!(f, "{}", if s.is_empty() { self.desc() } else { s })?
|
||||
}
|
||||
ParseErrorType::ForbiddenConstantExpr(ref s) => {
|
||||
write!(f, "Expecting a constant to assign to '{}'", s)?
|
||||
}
|
||||
ParseErrorType::UnknownOperator(ref s) => write!(f, "{}: '{}'", self.description(), s)?,
|
||||
ParseErrorType::UnknownOperator(ref s) => write!(f, "{}: '{}'", self.desc(), s)?,
|
||||
ParseErrorType::FnMissingParams(ref s) => {
|
||||
write!(f, "Expecting parameters for function '{}'", s)?
|
||||
}
|
||||
ParseErrorType::MissingRightParen(ref s)
|
||||
| ParseErrorType::MissingRightBrace(ref s)
|
||||
| ParseErrorType::MissingRightBracket(ref s) => {
|
||||
write!(f, "{} for {}", self.description(), s)?
|
||||
}
|
||||
| ParseErrorType::MissingRightBracket(ref s) => write!(f, "{} for {}", self.desc(), s)?,
|
||||
ParseErrorType::AssignmentToConstant(ref s) if s.is_empty() => {
|
||||
write!(f, "{}", self.description())?
|
||||
write!(f, "{}", self.desc())?
|
||||
}
|
||||
ParseErrorType::AssignmentToConstant(ref s) => {
|
||||
write!(f, "Cannot assign to constant '{}'", s)?
|
||||
}
|
||||
_ => write!(f, "{}", self.description())?,
|
||||
_ => write!(f, "{}", self.desc())?,
|
||||
}
|
||||
|
||||
if !self.1.is_eof() {
|
||||
|
Reference in New Issue
Block a user