Skip to content

Commit ee94996

Browse files
authored
api: add missing Debug impls for public types
In general, all public types should have a `Debug` impl. Some types didn't because it was just never needed, but it's good form to do it. PR #735
1 parent 8a81699 commit ee94996

File tree

11 files changed

+47
-6
lines changed

11 files changed

+47
-6
lines changed

regex-syntax/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ The following features are available:
155155
*/
156156

157157
#![deny(missing_docs)]
158+
#![warn(missing_debug_implementations)]
158159
#![forbid(unsafe_code)]
159160

160161
pub use error::{Error, Result};

regex-syntax/src/utf8.rs

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ which uses it for executing automata on their term index.
8484

8585
use std::char;
8686
use std::fmt;
87+
use std::iter::FusedIterator;
8788
use std::slice;
8889

8990
const MAX_UTF8_BYTES: usize = 4;
@@ -295,6 +296,7 @@ impl fmt::Debug for Utf8Range {
295296
/// illustrative. In practice, you could just try to decode your byte sequence
296297
/// and compare it with the scalar value range directly. However, this is not
297298
/// always possible (for example, in a byte based automaton).
299+
#[derive(Debug)]
298300
pub struct Utf8Sequences {
299301
range_stack: Vec<ScalarRange>,
300302
}
@@ -388,6 +390,8 @@ impl Iterator for Utf8Sequences {
388390
}
389391
}
390392

393+
impl FusedIterator for Utf8Sequences {}
394+
391395
impl ScalarRange {
392396
/// split splits this range if it overlaps with a surrogate codepoint.
393397
///

src/compile.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::collections::HashMap;
2+
use std::fmt;
23
use std::iter;
34
use std::result;
45
use std::sync::Arc;
@@ -25,6 +26,9 @@ struct Patch {
2526

2627
/// A compiler translates a regular expression AST to a sequence of
2728
/// instructions. The sequence of instructions represents an NFA.
29+
// `Compiler` is only public via the `internal` module, so avoid deriving
30+
// `Debug`.
31+
#[allow(missing_debug_implementations)]
2832
pub struct Compiler {
2933
insts: Vec<MaybeInst>,
3034
compiled: Program,
@@ -1051,6 +1055,7 @@ impl<'a, 'b> CompileClass<'a, 'b> {
10511055
/// This uses similar idea to [`SparseSet`](../sparse/struct.SparseSet.html),
10521056
/// except it uses hashes as original indices and then compares full keys for
10531057
/// validation against `dense` array.
1058+
#[derive(Debug)]
10541059
struct SuffixCache {
10551060
sparse: Box<[usize]>,
10561061
dense: Vec<SuffixCacheEntry>,
@@ -1159,6 +1164,12 @@ impl ByteClassSet {
11591164
}
11601165
}
11611166

1167+
impl fmt::Debug for ByteClassSet {
1168+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1169+
f.debug_tuple("ByteClassSet").field(&&self.0[..]).finish()
1170+
}
1171+
}
1172+
11621173
fn u32_to_usize(n: u32) -> usize {
11631174
// In case usize is less than 32 bits, we need to guard against overflow.
11641175
// On most platforms this compiles to nothing.

src/exec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use utf8::next_utf8;
3030
/// In particular, this manages the various compiled forms of a single regular
3131
/// expression and the choice of which matching engine to use to execute a
3232
/// regular expression.
33+
#[derive(Debug)]
3334
pub struct Exec {
3435
/// All read only state.
3536
ro: Arc<ExecReadOnly>,
@@ -49,6 +50,7 @@ pub struct ExecNoSync<'c> {
4950
}
5051

5152
/// `ExecNoSyncStr` is like `ExecNoSync`, but matches on &str instead of &[u8].
53+
#[derive(Debug)]
5254
pub struct ExecNoSyncStr<'c>(ExecNoSync<'c>);
5355

5456
/// `ExecReadOnly` comprises all read only state for a regex. Namely, all such
@@ -97,6 +99,9 @@ struct ExecReadOnly {
9799
/// Facilitates the construction of an executor by exposing various knobs
98100
/// to control how a regex is executed and what kinds of resources it's
99101
/// permitted to use.
102+
// `ExecBuilder` is only public via the `internal` module, so avoid deriving
103+
// `Debug`.
104+
#[allow(missing_debug_implementations)]
100105
pub struct ExecBuilder {
101106
options: RegexOptions,
102107
match_type: Option<MatchType>,

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ another matching engine with fixed memory requirements.
616616
#![deny(missing_docs)]
617617
#![cfg_attr(test, deny(warnings))]
618618
#![cfg_attr(feature = "pattern", feature(pattern))]
619+
#![warn(missing_debug_implementations)]
619620

620621
#[cfg(not(feature = "std"))]
621622
compile_error!("`std` feature is currently required to build this crate");

src/literal/imp.rs

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ impl Matcher {
232232
}
233233
}
234234

235+
#[derive(Debug)]
235236
pub enum LiteralIter<'a> {
236237
Empty,
237238
Bytes(&'a [u8]),

src/re_builder.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ macro_rules! define_builder {
4747
/// A builder can be used to configure how the regex is built, for example, by
4848
/// setting the default flags (which can be overridden in the expression
4949
/// itself) or setting various limits.
50+
#[derive(Debug)]
5051
pub struct RegexBuilder(RegexOptions);
5152

5253
impl RegexBuilder {
@@ -244,6 +245,7 @@ macro_rules! define_set_builder {
244245
/// A builder can be used to configure how the regexes are built, for example,
245246
/// by setting the default flags (which can be overridden in the expression
246247
/// itself) or setting various limits.
248+
#[derive(Debug)]
247249
pub struct RegexSetBuilder(RegexOptions);
248250

249251
impl RegexSetBuilder {

src/re_bytes.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,7 @@ impl Regex {
691691
///
692692
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
693693
/// lifetime of the matched byte string.
694+
#[derive(Debug)]
694695
pub struct Matches<'r, 't>(re_trait::Matches<'t, ExecNoSync<'r>>);
695696

696697
impl<'r, 't> Iterator for Matches<'r, 't> {
@@ -711,6 +712,7 @@ impl<'r, 't> FusedIterator for Matches<'r, 't> {}
711712
///
712713
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
713714
/// lifetime of the matched byte string.
715+
#[derive(Debug)]
714716
pub struct CaptureMatches<'r, 't>(
715717
re_trait::CaptureMatches<'t, ExecNoSync<'r>>,
716718
);
@@ -733,6 +735,7 @@ impl<'r, 't> FusedIterator for CaptureMatches<'r, 't> {}
733735
///
734736
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
735737
/// lifetime of the byte string being split.
738+
#[derive(Debug)]
736739
pub struct Split<'r, 't> {
737740
finder: Matches<'r, 't>,
738741
last: usize,
@@ -770,6 +773,7 @@ impl<'r, 't> FusedIterator for Split<'r, 't> {}
770773
///
771774
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
772775
/// lifetime of the byte string being split.
776+
#[derive(Debug)]
773777
pub struct SplitN<'r, 't> {
774778
splits: Split<'r, 't>,
775779
n: usize,
@@ -811,6 +815,7 @@ impl<'r, 't> FusedIterator for SplitN<'r, 't> {}
811815
/// whole matched region) is always unnamed.
812816
///
813817
/// `'r` is the lifetime of the compiled regular expression.
818+
#[derive(Clone, Debug)]
814819
pub struct CaptureNames<'r>(::std::slice::Iter<'r, Option<String>>);
815820

816821
impl<'r> Iterator for CaptureNames<'r> {
@@ -1078,7 +1083,7 @@ impl<'t, 'i> Index<&'i str> for Captures<'t> {
10781083
///
10791084
/// The lifetime `'c` corresponds to the lifetime of the `Captures` value, and
10801085
/// the lifetime `'t` corresponds to the originally matched text.
1081-
#[derive(Clone)]
1086+
#[derive(Clone, Debug)]
10821087
pub struct SubCaptureMatches<'c, 't: 'c> {
10831088
caps: &'c Captures<'t>,
10841089
it: SubCapturesPosIter<'c>,
@@ -1196,6 +1201,7 @@ where
11961201
/// and performant (since capture groups don't need to be found).
11971202
///
11981203
/// `'t` is the lifetime of the literal text.
1204+
#[derive(Clone, Debug)]
11991205
pub struct NoExpand<'t>(pub &'t [u8]);
12001206

12011207
impl<'t> Replacer for NoExpand<'t> {

src/re_set.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ impl<'a> IntoIterator for &'a SetMatches {
320320
/// This will always produces matches in ascending order of index, where the
321321
/// index corresponds to the index of the regex that matched with respect to
322322
/// its position when initially building the set.
323+
#[derive(Debug)]
323324
pub struct SetMatchesIntoIter(iter::Enumerate<vec::IntoIter<bool>>);
324325

325326
impl Iterator for SetMatchesIntoIter {
@@ -361,7 +362,7 @@ impl iter::FusedIterator for SetMatchesIntoIter {}
361362
/// This will always produces matches in ascending order of index, where the
362363
/// index corresponds to the index of the regex that matched with respect to
363364
/// its position when initially building the set.
364-
#[derive(Clone)]
365+
#[derive(Clone, Debug)]
365366
pub struct SetMatchesIter<'a>(iter::Enumerate<slice::Iter<'a, bool>>);
366367

367368
impl<'a> Iterator for SetMatchesIter<'a> {

src/re_trait.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt;
12
use std::iter::FusedIterator;
23

34
/// Slot is a single saved capture location. Note that there are two slots for
@@ -53,7 +54,7 @@ impl Locations {
5354
/// Positions are byte indices in terms of the original string matched.
5455
///
5556
/// `'c` is the lifetime of the captures.
56-
#[derive(Clone)]
57+
#[derive(Clone, Debug)]
5758
pub struct SubCapturesPosIter<'c> {
5859
idx: usize,
5960
locs: &'c Locations,
@@ -89,9 +90,9 @@ impl<'c> FusedIterator for SubCapturesPosIter<'c> {}
8990
/// somewhat reasonable. One particular thing this trait would expose would be
9091
/// the ability to start the search of a regex anywhere in a haystack, which
9192
/// isn't possible in the current public API.
92-
pub trait RegularExpression: Sized {
93+
pub trait RegularExpression: Sized + fmt::Debug {
9394
/// The type of the haystack.
94-
type Text: ?Sized;
95+
type Text: ?Sized + fmt::Debug;
9596

9697
/// The number of capture slots in the compiled regular expression. This is
9798
/// always two times the number of capture groups (two slots per group).
@@ -149,6 +150,7 @@ pub trait RegularExpression: Sized {
149150
}
150151

151152
/// An iterator over all non-overlapping successive leftmost-first matches.
153+
#[derive(Debug)]
152154
pub struct Matches<'t, R>
153155
where
154156
R: RegularExpression,
@@ -218,6 +220,7 @@ where
218220

219221
/// An iterator over all non-overlapping successive leftmost-first matches with
220222
/// captures.
223+
#[derive(Debug)]
221224
pub struct CaptureMatches<'t, R>(Matches<'t, R>)
222225
where
223226
R: RegularExpression,

src/re_unicode.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,7 @@ impl Regex {
748748
/// whole matched region) is always unnamed.
749749
///
750750
/// `'r` is the lifetime of the compiled regular expression.
751+
#[derive(Clone, Debug)]
751752
pub struct CaptureNames<'r>(::std::slice::Iter<'r, Option<String>>);
752753

753754
impl<'r> Iterator for CaptureNames<'r> {
@@ -777,6 +778,7 @@ impl<'r> FusedIterator for CaptureNames<'r> {}
777778
///
778779
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
779780
/// lifetime of the string being split.
781+
#[derive(Debug)]
780782
pub struct Split<'r, 't> {
781783
finder: Matches<'r, 't>,
782784
last: usize,
@@ -814,6 +816,7 @@ impl<'r, 't> FusedIterator for Split<'r, 't> {}
814816
///
815817
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
816818
/// lifetime of the string being split.
819+
#[derive(Debug)]
817820
pub struct SplitN<'r, 't> {
818821
splits: Split<'r, 't>,
819822
n: usize,
@@ -1076,7 +1079,7 @@ impl<'t, 'i> Index<&'i str> for Captures<'t> {
10761079
///
10771080
/// The lifetime `'c` corresponds to the lifetime of the `Captures` value, and
10781081
/// the lifetime `'t` corresponds to the originally matched text.
1079-
#[derive(Clone)]
1082+
#[derive(Clone, Debug)]
10801083
pub struct SubCaptureMatches<'c, 't: 'c> {
10811084
caps: &'c Captures<'t>,
10821085
it: SubCapturesPosIter<'c>,
@@ -1101,6 +1104,7 @@ impl<'c, 't> FusedIterator for SubCaptureMatches<'c, 't> {}
11011104
///
11021105
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
11031106
/// lifetime of the matched string.
1107+
#[derive(Debug)]
11041108
pub struct CaptureMatches<'r, 't>(
11051109
re_trait::CaptureMatches<'t, ExecNoSyncStr<'r>>,
11061110
);
@@ -1126,6 +1130,7 @@ impl<'r, 't> FusedIterator for CaptureMatches<'r, 't> {}
11261130
///
11271131
/// `'r` is the lifetime of the compiled regular expression and `'t` is the
11281132
/// lifetime of the matched string.
1133+
#[derive(Debug)]
11291134
pub struct Matches<'r, 't>(re_trait::Matches<'t, ExecNoSyncStr<'r>>);
11301135

11311136
impl<'r, 't> Iterator for Matches<'r, 't> {
@@ -1238,6 +1243,7 @@ where
12381243
/// and performant (since capture groups don't need to be found).
12391244
///
12401245
/// `'t` is the lifetime of the literal text.
1246+
#[derive(Clone, Debug)]
12411247
pub struct NoExpand<'t>(pub &'t str);
12421248

12431249
impl<'t> Replacer for NoExpand<'t> {

0 commit comments

Comments
 (0)