Skip to content

globset: add a concise Debug impl for GlobSet - #3582

Open
Jbansal2 wants to merge 1 commit into
BurntSushi:masterfrom
Jbansal2:globset-debug-impl
Open

Jbansal2 wants to merge 1 commit into
BurntSushi:masterfrom
Jbansal2:globset-debug-impl

Conversation

@Jbansal2

Copy link
Copy Markdown

Fixes #3274.

GlobSet currently derives Debug, which prints its internal
Vec<GlobSetMatchStrategy> representation. That's not very useful:
the match-strategy types are compiled matching structures (literal
tables, regex sets, etc.), not anything resembling the original glob
patterns, so {:?} on a GlobSet is noisy and uninformative.

GlobSetBuilder, by contrast, already has a readable Debug output,
simply because it derives Debug over its own Vec<Glob>, and Glob
has a concise custom Debug (Glob("pattern")).

This PR keeps the glob patterns around on GlobSet itself (a
Vec<Glob>, populated in GlobSet::new) purely for this purpose, and
gives GlobSet a custom Debug impl that prints just that list, e.g.:

GlobSet([Glob("src/**/*.rs"), Glob("*.c")])

matching the style the issue asked for from GlobSetBuilder.

Added a test (debug_impl_is_concise) asserting the exact output for
a small set and for GlobSet::empty().

Note on verification

I was able to verify this compiles cleanly with cargo check -p globset
(and cargo check -p globset --tests up to the point of lib-crate
type-checking). However, cargo test in my local environment fails
to link unrelated dev-dependencies (serde_json, zmij,
serde_core build scripts) due to a broken MSVC linker invocation
unrelated to this change, so I could not run the new test to
completion locally. The change itself is small and mechanical (adding
a field, populating it, and writing a Debug impl mirroring the
existing Glob/GlobSetBuilder pattern), and I'm confident in it,
but flagging this limitation for the reviewer.

GlobSet previously derived Debug, which printed the internal
GlobSetMatchStrategy representation instead of anything resembling
the original glob patterns. GlobSetBuilder's derived Debug is already
readable because it just stores the Vec<Glob> it was given.

Give GlobSet a custom Debug that mirrors this: retain the Vec<Glob>
used to build the set and print only that, e.g.
GlobSet([Glob("src/**/*.rs"), Glob("*.c")]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

globset: add a compact display or debug implementation for the GlobSet type

1 participant