-
Notifications
You must be signed in to change notification settings - Fork 718
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
Add option to replace proc macro #[doc = "..."]
with the more usable /// ...
#2348
Comments
I think that this could just happen during Add a check for the CLI option and run the regex replacer if so. |
Proposed changes:
If this sounds good to admins, I will get a PR going |
Hi! Thanks for your submission. Even though I agree that |
Hey, thanks for the feedback. I don't disagree that it's not a super complicated step, but the regex isn't totally trivial (could be documented somewhere ofc), and it would be much nicer for CLI users to be able to Is your disposition more neutral or more against this feature? If you're neutral, I'll do the PR and you can review then. If you're against it, I suppose we could close this issue |
While the change might be doable it's still a component/feature to maintain that it's slightly out of scope since the generated code is valid. I was looking into some way to change the way a token stream is displayed to get the While doing this I found https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#normalize_doc_attributes a rustfmt configuration option to write doc attributes in the more readable way. However this feature is not yet stabilized. What would you say about using rust-fmt to get this instead. This way, the burden of the correct writing of a token stream falls on rustfmt, but until stabilization it would need nightly |
That's awesome! We could certainly add a section in the user guide mentioning how to use rustfmt for this. Bindgen uses rustfmt internally too so we might be able to do it from there if the user is using nightly as the rust target. Edit: focus on the "might" because I'm not sure if we can actually accomplish that |
After tinkering a bit with both normalize_doc_attributes = true
Given that the However, if you are using any stable release of When using
|
That’s a great find! And a docs update definitely works for me. I didn’t realize rustfmt had that option, that’s an awesome time saver |
Currently, bindgen generates doc comments using the proc macro style like the following:
This is very OK for
build.rs
-generated output that the user may never directly see. However, it is a bit unwieldy when you need to interact with the output - difficult to read and very cumbersome to edit.It was pointed out in this comment that the main reason for this is a limitation of the
quote
crate, which makes sense. But I was wondering if a--replace-doc-macros
flag would be considered that postprocesses the output text.My first pass attempt at a regex sequence to do this is:
(playground)
I usually run something like this after output generation when I need to cache the file, but I think that quite a few users would be happy to have this as a builtin option.
The text was updated successfully, but these errors were encountered: