Skip to content

Commit

Permalink
syntax: remove 'std::error::Error::description' impls
Browse files Browse the repository at this point in the history
This method was deprecated a while ago, but we kept it around because it
wasn't worth a breaking release to remove them.

This also simplifies some imports.
  • Loading branch information
BurntSushi committed Apr 15, 2023
1 parent 425d6b0 commit 8312175
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 82 deletions.
42 changes: 1 addition & 41 deletions regex-syntax/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Defines an abstract syntax for regular expressions.
*/

use std::cmp::Ordering;
use std::error;
use std::fmt;

pub use crate::ast::visitor::{visit, Visitor};
Expand Down Expand Up @@ -178,46 +177,7 @@ pub enum ErrorKind {
__Nonexhaustive,
}

impl error::Error for Error {
// TODO: Remove this method entirely on the next breaking semver release.
#[allow(deprecated)]
fn description(&self) -> &str {
use self::ErrorKind::*;
match self.kind {
CaptureLimitExceeded => "capture group limit exceeded",
ClassEscapeInvalid => "invalid escape sequence in character class",
ClassRangeInvalid => "invalid character class range",
ClassRangeLiteral => "invalid range boundary, must be a literal",
ClassUnclosed => "unclosed character class",
DecimalEmpty => "empty decimal literal",
DecimalInvalid => "invalid decimal literal",
EscapeHexEmpty => "empty hexadecimal literal",
EscapeHexInvalid => "invalid hexadecimal literal",
EscapeHexInvalidDigit => "invalid hexadecimal digit",
EscapeUnexpectedEof => "unexpected eof (escape sequence)",
EscapeUnrecognized => "unrecognized escape sequence",
FlagDanglingNegation => "dangling flag negation operator",
FlagDuplicate { .. } => "duplicate flag",
FlagRepeatedNegation { .. } => "repeated negation",
FlagUnexpectedEof => "unexpected eof (flag)",
FlagUnrecognized => "unrecognized flag",
GroupNameDuplicate { .. } => "duplicate capture group name",
GroupNameEmpty => "empty capture group name",
GroupNameInvalid => "invalid capture group name",
GroupNameUnexpectedEof => "unclosed capture group name",
GroupUnclosed => "unclosed group",
GroupUnopened => "unopened group",
NestLimitExceeded(_) => "nest limit exceeded",
RepetitionCountInvalid => "invalid repetition count range",
RepetitionCountUnclosed => "unclosed counted repetition",
RepetitionMissing => "repetition operator missing expression",
UnicodeClassInvalid => "invalid Unicode character class",
UnsupportedBackreference => "backreferences are not supported",
UnsupportedLookAround => "look-around is not supported",
_ => unreachable!(),
}
}
}
impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
13 changes: 1 addition & 12 deletions regex-syntax/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::cmp;
use std::error;
use std::fmt;
use std::result;

Expand Down Expand Up @@ -39,17 +38,7 @@ impl From<hir::Error> for Error {
}
}

impl error::Error for Error {
// TODO: Remove this method entirely on the next breaking semver release.
#[allow(deprecated)]
fn description(&self) -> &str {
match *self {
Error::Parse(ref x) => x.description(),
Error::Translate(ref x) => x.description(),
_ => unreachable!(),
}
}
}
impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
43 changes: 14 additions & 29 deletions regex-syntax/src/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Defines a high-level intermediate representation for regular expressions.
*/
use std::char;
use std::cmp;
use std::error;
use std::fmt;
use std::result;
use std::u8;
Expand Down Expand Up @@ -97,12 +96,19 @@ pub enum ErrorKind {
// Simplify repetitions (get rid of ZeroOrOne, OneOrMore etc)
// Get rid of deprecated things

impl ErrorKind {
// TODO: Remove this method entirely on the next breaking semver release.
#[allow(deprecated)]
fn description(&self) -> &str {
impl std::error::Error for Error {}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
crate::error::Formatter::from(self).fmt(f)
}
}

impl fmt::Display for ErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
use self::ErrorKind::*;
match *self {

let msg = match *self {
UnicodeNotAllowed => "Unicode not allowed here",
InvalidUtf8 => "pattern can match invalid UTF-8",
UnicodePropertyNotFound => "Unicode property not found",
Expand All @@ -117,29 +123,8 @@ impl ErrorKind {
}
EmptyClassNotAllowed => "empty character classes are not allowed",
__Nonexhaustive => unreachable!(),
}
}
}

impl error::Error for Error {
// TODO: Remove this method entirely on the next breaking semver release.
#[allow(deprecated)]
fn description(&self) -> &str {
self.kind.description()
}
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
crate::error::Formatter::from(self).fmt(f)
}
}

impl fmt::Display for ErrorKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Remove this on the next breaking semver release.
#[allow(deprecated)]
f.write_str(self.description())
};
f.write_str(msg)
}
}

Expand Down

0 comments on commit 8312175

Please sign in to comment.