Skip to content

Commit 23dd51e

Browse files
committed
syntax: remove 'std::error::Error::description' impls
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.
1 parent cb22d85 commit 23dd51e

File tree

3 files changed

+16
-82
lines changed

3 files changed

+16
-82
lines changed

regex-syntax/src/ast/mod.rs

+1-41
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Defines an abstract syntax for regular expressions.
33
*/
44

55
use std::cmp::Ordering;
6-
use std::error;
76
use std::fmt;
87

98
pub use crate::ast::visitor::{visit, Visitor};
@@ -178,46 +177,7 @@ pub enum ErrorKind {
178177
__Nonexhaustive,
179178
}
180179

181-
impl error::Error for Error {
182-
// TODO: Remove this method entirely on the next breaking semver release.
183-
#[allow(deprecated)]
184-
fn description(&self) -> &str {
185-
use self::ErrorKind::*;
186-
match self.kind {
187-
CaptureLimitExceeded => "capture group limit exceeded",
188-
ClassEscapeInvalid => "invalid escape sequence in character class",
189-
ClassRangeInvalid => "invalid character class range",
190-
ClassRangeLiteral => "invalid range boundary, must be a literal",
191-
ClassUnclosed => "unclosed character class",
192-
DecimalEmpty => "empty decimal literal",
193-
DecimalInvalid => "invalid decimal literal",
194-
EscapeHexEmpty => "empty hexadecimal literal",
195-
EscapeHexInvalid => "invalid hexadecimal literal",
196-
EscapeHexInvalidDigit => "invalid hexadecimal digit",
197-
EscapeUnexpectedEof => "unexpected eof (escape sequence)",
198-
EscapeUnrecognized => "unrecognized escape sequence",
199-
FlagDanglingNegation => "dangling flag negation operator",
200-
FlagDuplicate { .. } => "duplicate flag",
201-
FlagRepeatedNegation { .. } => "repeated negation",
202-
FlagUnexpectedEof => "unexpected eof (flag)",
203-
FlagUnrecognized => "unrecognized flag",
204-
GroupNameDuplicate { .. } => "duplicate capture group name",
205-
GroupNameEmpty => "empty capture group name",
206-
GroupNameInvalid => "invalid capture group name",
207-
GroupNameUnexpectedEof => "unclosed capture group name",
208-
GroupUnclosed => "unclosed group",
209-
GroupUnopened => "unopened group",
210-
NestLimitExceeded(_) => "nest limit exceeded",
211-
RepetitionCountInvalid => "invalid repetition count range",
212-
RepetitionCountUnclosed => "unclosed counted repetition",
213-
RepetitionMissing => "repetition operator missing expression",
214-
UnicodeClassInvalid => "invalid Unicode character class",
215-
UnsupportedBackreference => "backreferences are not supported",
216-
UnsupportedLookAround => "look-around is not supported",
217-
_ => unreachable!(),
218-
}
219-
}
220-
}
180+
impl std::error::Error for Error {}
221181

222182
impl fmt::Display for Error {
223183
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

regex-syntax/src/error.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::cmp;
2-
use std::error;
32
use std::fmt;
43
use std::result;
54

@@ -39,17 +38,7 @@ impl From<hir::Error> for Error {
3938
}
4039
}
4140

42-
impl error::Error for Error {
43-
// TODO: Remove this method entirely on the next breaking semver release.
44-
#[allow(deprecated)]
45-
fn description(&self) -> &str {
46-
match *self {
47-
Error::Parse(ref x) => x.description(),
48-
Error::Translate(ref x) => x.description(),
49-
_ => unreachable!(),
50-
}
51-
}
52-
}
41+
impl std::error::Error for Error {}
5342

5443
impl fmt::Display for Error {
5544
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

regex-syntax/src/hir/mod.rs

+14-29
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Defines a high-level intermediate representation for regular expressions.
33
*/
44
use std::char;
55
use std::cmp;
6-
use std::error;
76
use std::fmt;
87
use std::result;
98
use std::u8;
@@ -97,12 +96,19 @@ pub enum ErrorKind {
9796
// Simplify repetitions (get rid of ZeroOrOne, OneOrMore etc)
9897
// Get rid of deprecated things
9998

100-
impl ErrorKind {
101-
// TODO: Remove this method entirely on the next breaking semver release.
102-
#[allow(deprecated)]
103-
fn description(&self) -> &str {
99+
impl std::error::Error for Error {}
100+
101+
impl fmt::Display for Error {
102+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
103+
crate::error::Formatter::from(self).fmt(f)
104+
}
105+
}
106+
107+
impl fmt::Display for ErrorKind {
108+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104109
use self::ErrorKind::*;
105-
match *self {
110+
111+
let msg = match *self {
106112
UnicodeNotAllowed => "Unicode not allowed here",
107113
InvalidUtf8 => "pattern can match invalid UTF-8",
108114
UnicodePropertyNotFound => "Unicode property not found",
@@ -117,29 +123,8 @@ impl ErrorKind {
117123
}
118124
EmptyClassNotAllowed => "empty character classes are not allowed",
119125
__Nonexhaustive => unreachable!(),
120-
}
121-
}
122-
}
123-
124-
impl error::Error for Error {
125-
// TODO: Remove this method entirely on the next breaking semver release.
126-
#[allow(deprecated)]
127-
fn description(&self) -> &str {
128-
self.kind.description()
129-
}
130-
}
131-
132-
impl fmt::Display for Error {
133-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
134-
crate::error::Formatter::from(self).fmt(f)
135-
}
136-
}
137-
138-
impl fmt::Display for ErrorKind {
139-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
140-
// TODO: Remove this on the next breaking semver release.
141-
#[allow(deprecated)]
142-
f.write_str(self.description())
126+
};
127+
f.write_str(msg)
143128
}
144129
}
145130

0 commit comments

Comments
 (0)