Coverage Report

Created: 2026-06-30 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/regex-1.5.6/src/error.rs
Line
Count
Source
1
use std::fmt;
2
use std::iter::repeat;
3
4
/// An error that occurred during parsing or compiling a regular expression.
5
#[derive(Clone, PartialEq)]
6
pub enum Error {
7
    /// A syntax error.
8
    Syntax(String),
9
    /// The compiled program exceeded the set size limit.
10
    /// The argument is the size limit imposed.
11
    CompiledTooBig(usize),
12
    /// Hints that destructuring should not be exhaustive.
13
    ///
14
    /// This enum may grow additional variants, so this makes sure clients
15
    /// don't count on exhaustive matching. (Otherwise, adding a new variant
16
    /// could break existing code.)
17
    #[doc(hidden)]
18
    __Nonexhaustive,
19
}
20
21
impl ::std::error::Error for Error {
22
    // TODO: Remove this method entirely on the next breaking semver release.
23
    #[allow(deprecated)]
24
0
    fn description(&self) -> &str {
25
0
        match *self {
26
0
            Error::Syntax(ref err) => err,
27
0
            Error::CompiledTooBig(_) => "compiled program too big",
28
0
            Error::__Nonexhaustive => unreachable!(),
29
        }
30
0
    }
Unexecuted instantiation: <regex::error::Error as core::error::Error>::description
Unexecuted instantiation: <regex::error::Error as core::error::Error>::description
31
}
32
33
impl fmt::Display for Error {
34
0
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35
0
        match *self {
36
0
            Error::Syntax(ref err) => err.fmt(f),
37
0
            Error::CompiledTooBig(limit) => write!(
38
0
                f,
39
0
                "Compiled regex exceeds size limit of {} bytes.",
40
                limit
41
            ),
42
0
            Error::__Nonexhaustive => unreachable!(),
43
        }
44
0
    }
Unexecuted instantiation: <regex::error::Error as core::fmt::Display>::fmt
Unexecuted instantiation: <regex::error::Error as core::fmt::Display>::fmt
45
}
46
47
// We implement our own Debug implementation so that we show nicer syntax
48
// errors when people use `Regex::new(...).unwrap()`. It's a little weird,
49
// but the `Syntax` variant is already storing a `String` anyway, so we might
50
// as well format it nicely.
51
impl fmt::Debug for Error {
52
0
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
53
0
        match *self {
54
0
            Error::Syntax(ref err) => {
55
0
                let hr: String = repeat('~').take(79).collect();
56
0
                writeln!(f, "Syntax(")?;
57
0
                writeln!(f, "{}", hr)?;
58
0
                writeln!(f, "{}", err)?;
59
0
                writeln!(f, "{}", hr)?;
60
0
                write!(f, ")")?;
61
0
                Ok(())
62
            }
63
0
            Error::CompiledTooBig(limit) => {
64
0
                f.debug_tuple("CompiledTooBig").field(&limit).finish()
65
            }
66
            Error::__Nonexhaustive => {
67
0
                f.debug_tuple("__Nonexhaustive").finish()
68
            }
69
        }
70
0
    }
Unexecuted instantiation: <regex::error::Error as core::fmt::Debug>::fmt
Unexecuted instantiation: <regex::error::Error as core::fmt::Debug>::fmt
71
}