Skip to content

Add --no-debug <regex> flag #1858

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

Merged
merged 1 commit into from
Aug 3, 2020

Conversation

varphone
Copy link
Contributor

@varphone varphone commented Aug 2, 2020

This patch based on [Close #961] Add --no-debug flag #1190, thanks ivanovaleksey

Add --no-debug <regex> and Builder::no_debug(String) to supply regexes for matching against types that we should not derive or implement Debug for.

Adding this feature involves:

  • Adding a new RegexSet member to bindgen::Builder (similar to the whitelisted_types set).
  • A Builder method to add strings to that RegexSet.
  • Plumbing in src/options.rs to convert --no-debug <regex> CLI flags into invocations of the builder method.
  • Making the MonotoneFramework::constrain function in src/ir/analysis/derive_debug.rs check if the given item is explicitly marked not to be Debug, and if so, inserting it into the self.cannot_derive_debug set via return self.insert(id).
  • Skipping any item explicitly marked not to be Debug in src/codegen/derive_debug.rs so that we don't generate an impl Debug for ... for these types when --impl-debug is passed.
  • Tests!
    • When --impl-debug is also supplied
    • When --impl-debug is not also supplied
    • When the no-debug type is transitively referenced by a whitelisted item
    • When the no-debug type is explicitly whitelisted
    • When the no-debug type is marked opaque

@highfive
Copy link

highfive commented Aug 2, 2020

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@varphone varphone force-pushed the feature/add-no-debug-flag branch from 75fc081 to 00e6c2e Compare August 2, 2020 05:18
Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!

Mind fixing the struct name in the test? We can merge this with that.


/** <div rustbindgen nodebug></div> */
template<typename T>
class CopiableButWait {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name seems copy-pasted, but inaccurate for this test, mind fixing it?

@emilio emilio force-pushed the feature/add-no-debug-flag branch from 00e6c2e to 3c2813e Compare August 3, 2020 16:29
@emilio emilio merged commit ff36981 into rust-lang:master Aug 3, 2020
@emilio
Copy link
Contributor

emilio commented Aug 3, 2020

I did that tweak and merged. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants