Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing fmt::Debug impls for public structs and enums #735

Merged
merged 2 commits into from Dec 29, 2020

Conversation

@lopopolo
Copy link
Contributor

@lopopolo lopopolo commented Dec 29, 2020

The Rust API guidelines advise that all public types implement common std traits for interoperability, of which fmt::Debug is one.

This PR adds fmt::Debug implementations for all public types in regex and regex-syntax crates. This PR also adds #![warn(missing_debug_implementations)] to lib.rs in each crate.

This PR also opportunistically implements Clone on iterators that wrap slice::Iter.

Context: I'm building an implementation of Ruby Regexp on top of the regex crate, and having all public types implement fmt::Debug will allow me to #[derive(Debug)] on types that wrap e.g. iterators in this crate.

Copy link
Member

@BurntSushi BurntSushi left a comment

LGTM, but like the other PR, my sense is that some of these impls aren't needed to pass the lint? Or does the lint apply to internal types too?

The reason why I'm being a stickler about this is that I'd rather not add impls for things that we don't need because they likely increase compile times. And the compile times for this crate are already pretty poor.

src/dfa.rs Outdated Show resolved Hide resolved
.field("last_match", &self.last_match)
.finish()
}
}

This comment has been minimized.

@BurntSushi

BurntSushi Dec 29, 2020
Member

I suspect you're writing out this impl because Matches is generic and doesn't require its type parameters to impl Debug? The RegularExpression trait is an internal construct, so adding a requirement to impl Debug seems fine to me. (For both Self and for its Text associated type.) Then you should be able to derive Debug impls here.

This comment has been minimized.

@lopopolo

lopopolo Dec 29, 2020
Author Contributor

I also made the same change to CaptureMatches.

src/exec.rs Outdated Show resolved Hide resolved
src/exec.rs Outdated
@@ -97,6 +99,7 @@ struct ExecReadOnly {
/// Facilitates the construction of an executor by exposing various knobs
/// to control how a regex is executed and what kinds of resources it's
/// permitted to use.
#[derive(Debug)]

This comment has been minimized.

@BurntSushi

BurntSushi Dec 29, 2020
Member

Is this Debug impl necessary?

This comment has been minimized.

@lopopolo

lopopolo Dec 29, 2020
Author Contributor

ExecBuilder is public via the internal module which "exists to support suspicious activity".

I'll remove the debug impl and allow the lint.

@@ -25,6 +26,7 @@ struct Patch {

/// A compiler translates a regular expression AST to a sequence of
/// instructions. The sequence of instructions represents an NFA.
#[derive(Debug)]

This comment has been minimized.

@BurntSushi

BurntSushi Dec 29, 2020
Member

Is this Debug impl necessary?

This comment has been minimized.

@lopopolo

lopopolo Dec 29, 2020
Author Contributor

Compiler is public via the internal module which "exists to support suspicious activity".

I'll remove the debug impl and allow the lint.

This comment has been minimized.

@BurntSushi

BurntSushi Dec 29, 2020
Member

Haha right. Yeah, it's technically public, but is doc(hidden) and not a stable part of the API. I'm hoping to remove that quirk in the move to regex-automata.

Thanks.

Copy link
Member

@BurntSushi BurntSushi left a comment

Whoops, I meant to "request changes."

@lopopolo lopopolo force-pushed the lopopolo:missing-debug-impls branch from 77becd0 to 8207873 Dec 29, 2020
@lopopolo
Copy link
Contributor Author

@lopopolo lopopolo commented Dec 29, 2020

@BurntSushi I've made the requested changes. I squashed these into the commit for the regex crate.

For types that are only public via the hidden internal module, I've added an #[allow(missing_debug_implementations)] and avoid implementing Debug.

lopopolo added 2 commits Dec 29, 2020
@lopopolo
Copy link
Contributor Author

@lopopolo lopopolo commented Dec 29, 2020

rebase incoming.

@lopopolo lopopolo force-pushed the lopopolo:missing-debug-impls branch from 8207873 to 1c60951 Dec 29, 2020
@lopopolo
Copy link
Contributor Author

@lopopolo lopopolo commented Dec 29, 2020

LGTM, but like the other PR

For reference, the other PR is #734.

Copy link
Member

@BurntSushi BurntSushi left a comment

OK, LGTM, thanks!

@BurntSushi BurntSushi merged commit ee94996 into rust-lang:master Dec 29, 2020
10 checks passed
10 checks passed
test (pinned)
Details
test (stable)
Details
test (stable-32)
Details
test (stable-mips)
Details
test (beta)
Details
test (nightly)
Details
test (macos)
Details
test (win-msvc)
Details
test (win-gnu)
Details
rustfmt
Details
@lopopolo
Copy link
Contributor Author

@lopopolo lopopolo commented Dec 30, 2020

Whoops looks like I accidentally didn't split out the iterator traits bits from regex-syntax properly when splitting apart the two PRs.

Thanks for merging.

Would it be possible to get these two PRs packaged into a release soon?

@BurntSushi
Copy link
Member

@BurntSushi BurntSushi commented Dec 30, 2020

Yeah I saw that, but that's okay. No biggie.

I'll try to do a release in the next couple days. Please ping me again if it doesn't happen.

@lopopolo
Copy link
Contributor Author

@lopopolo lopopolo commented Jan 6, 2021

hi @BurntSushi following up with a friendly ping for a release.

@BurntSushi
Copy link
Member

@BurntSushi BurntSushi commented Jan 8, 2021

@lopopolo OK, regex 1.4.3 is on crates.io.

@lopopolo
Copy link
Contributor Author

@lopopolo lopopolo commented Jan 8, 2021

Thank you!

This was referenced Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants