-
Notifications
You must be signed in to change notification settings - Fork 698
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
Intelligently convert C/C++ comments to Rust #791
Intelligently convert C/C++ comments to Rust #791
Conversation
a68f9a1
to
37f5d85
Compare
Note that this does not implement the As far as I can tell, this is currently already broken and is causing us to emit the wrong doc comments off by one on struct fields/enum variants which use the syntax. |
I need to modify this so that it also treats regular comments ( |
This is lovely, thank you! Could we also add the test-case from #426? |
I can do that. Also, I'm going to refactor this so that rather than doing the C++ -> Rust comment conversion at the codegen level, we do it when building the AST. As far as I understand it, that would be a more appropriate place and (depending on how we build the AST - I haven't looked at it yet), we may be able to have a single call which converts comments rather than having multiple over the place. |
Yeah, I think that's fine, though if it gets nasty we could also move the |
78d2166
to
233f5db
Compare
I've added the test case from #426 and also moved the preprocessing to the IR stage. Let me know if you'd like me to change anything in order to merge :) |
ae79118
to
aefffc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking that handling comment processing in code generation makes sense, actually, because we can re-indent depending on the nesting level of the item, etc... However, that's followup work in any case, and it's easy enough to move it so... This can land with r=me with Travis fixed:
error: missing documentation for a module
--> src/ir/mod.rs:8:1
|
8 | pub mod comment;
| ^^^^^^^^^^^^^^^^
|
Thanks again for doing this btw! :) |
bc15759
to
4dca1b1
Compare
No problem, thanks for working on the project :) I've fixed the comment issue but I can't get the Here is a part of the diff from the travis run It seems as if it's related to environment differences between my computer and CI, but I can't really replicate the exact same build setup as them.
Does this ring any bells @emilio? |
@@ -0,0 +1,16 @@ | |||
#include <stddef.h> | |||
#include <stdint.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, tests can't have system includes to pass, since these are machine-dependent.
#include <stddef.h> | ||
#include <stdint.h> | ||
|
||
typedef uint32_t mbedtls_mpi_uint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead you can remove them and, let's say, replace uint32_t
for unsigned
, and size_t
for unsigned long
. they're irrelevant to the test-case anyway, so it seems sensible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very helpful, thanks!
With this change, we can correctly parse C++ block comments. ``` /** * Does a thing * * More documentation. This test does something * useful. */ ``` into ``` /// Does a thing /// /// More documentation. This test does something /// useful. ``` Fixes rust-lang#426.
4dca1b1
to
239a015
Compare
Tests are now green @emilio, thanks for the help! |
Looks great, thanks again for this! @bors-servo r+ |
📌 Commit 239a015 has been approved by |
Intelligently convert C/C++ comments to Rust With this change, we can correctly parse C++ block comments. ```cpp /** * Does a thing * * More documentation. This test does something * useful. */ ``` into ```rust /// Does a thing /// /// More documentation. This test does something /// useful. ``` Fixes #426.
☀️ Test successful - status-travis |
Author of #426 here. I didn't get a notification when this PR was opened. Why are you converting into Rust doc comments? It seems highly unlikely that |
Well, sure, but that's followup work anyway. I think it's nice to have the comment in a processable format, which is what this PR enables. This PR also fixes the most common cases where people doesn't use markdown for their C/C++ docs. If we want to support fully rustdoc, etc, there may be more followup work needed. An easy way to generate comments and make rustdoc not complain is making comments normal Anyway, I've followed up in #799 with fixes and a few features that this PR enabled. I think Markdown/Doxygen support can be discussed in a new issue. Will file one to that effect. |
I opened #800 for that. |
@emilio would it be possible for a new revision to be published so I can use this in one of my own crates? |
@dylanmckay sure, though I'd wait for #799 to merge to fix the panic when a class is documented with an empty multiline comment ( |
Sounds good to me, thanks @emilio :) |
With this change, we can correctly parse C++ block comments.
into
Fixes #426.