Skip to content

[Close #961] Add --no-debug <regex> flag #1190

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

Closed
wants to merge 1 commit into from

Conversation

ivanovaleksey
Copy link

@ivanovaleksey ivanovaleksey commented Dec 11, 2017

Close #961

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

warning Warning warning

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

@ivanovaleksey
Copy link
Author

r? @pepyakin

@pepyakin
Copy link
Contributor

Thanks for your pull request! Sorry for not getting to this earlier!

Looks like there are some tests are failing because of headers differs from expectations, but the only difference I can see is formatting! Looks strange, do you know guys what's going on @emilio / @fitzgen ?

Also, looks like --impl-debug thing is not there, is there any particular reason for that?

Aside of that, your PR looks great!

@fitzgen
Copy link
Member

fitzgen commented Dec 13, 2017

Its possible that we need to re-run rustfmt on the test expectations, and after that there won't be formatting differences between the generated code and the expectations.

@ivanovaleksey
Copy link
Author

Thanks guys,

I have just opened this PR to ensure I am on the right way.
--impl-debug is going to be done.
I will check failing specs.

@ivanovaleksey
Copy link
Author

I am not sure about why tests failed.
According to the job there was installed rustfmt-nightly v0.3.1.

I installed the same version locally and experimented on a file tests/headers/func_ptr_in_struct.h.
After cargo test it becomes reformatted with the following diff:

index 290a148c..3d3439ab 100644
--- a/tests/expectations/tests/func_ptr_in_struct.rs
+++ b/tests/expectations/tests/func_ptr_in_struct.rs
@@ -1,11 +1,10 @@
 /* automatically generated by rust-bindgen */
                 concat!("Alignment of ", stringify!(Type))
             );
         }
     }
     #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
-    pub enum a {}
+    pub enum a {
+}
 }

But if I run rustfmt directly:

rustfmt tests/expectations/tests/func_ptr_in_struct.rs --config-path tests/rustfmt.toml

it doesn't reformat enum a at all.

I don't know where rustfmt is getting run by bindgen but I found something similar in tests/tests.rs. But it invoke the same nightly version. Maybe these formatting differences might be due to some additional configuration I have missed?

@bors-servo
Copy link

☔ The latest upstream changes (presumably #1330) made this pull request unmergeable. Please resolve the merge conflicts.

@pvdrz
Copy link
Contributor

pvdrz commented Aug 31, 2022

I'm closing this PR as the merged PR #1858 was based over this one..

@pvdrz pvdrz closed this Aug 31, 2022
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.

Allow specifying certain types we shouldn't derive/impl Debug for
6 participants