-
Notifications
You must be signed in to change notification settings - Fork 892
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
Format code block in doc comment #554
Comments
I asked on IRC, it's probably not possible to have an escaped newline in doc comments. Options include:
|
Option 3 seems to be the right solution here, but it is also a bit hard - it would mean re-parsing and so forth. Not impossible, but certainly a bit of work. In the short term, we could just detect and skip code blocks in comments. Perhaps we should have more fine-grained options for skipping doc comments too? |
Given how frequent (in a good way) code-in-comments is, I do think we should do something special for it. Am I right that we can depend on code blocks in comments looking like
And that we should use the algorithm from rustdoc:
To produce code from examples that compiles. Then we'd format that, and then remove anything added by 1-4 to end up with the original code, formatted properly. If any step fails, we leave the code as is and don't format the code within the block. |
From 0.3.0 rustfmt leaves code blocks as is. |
Closes rust-lang#554. Closes rust-lang#1695.
Closes rust-lang#554. Closes rust-lang#1695.
Now the generated documentation looks like this:
The text was updated successfully, but these errors were encountered: