Skip to content
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

Fix: Generated Rust docstring no longer crashes cargo doc #6085

Merged
merged 3 commits into from
Jan 29, 2025

Conversation

MikaelMayer
Copy link
Member

Fixes #6084

What was changed?

Previously, Dafny docstring was literally transformed to Rust docstring. However, Rust docstring follows a markdown syntax where non-labelled code blocks are interpreted and checked as Rust code when running cargo doc. Rather than creating a flag to avoid the docstring, this PR does a lightweight parsing on the docstring to ensures that:

  • In docstrings, code blocks without label are written using the "dafny" label so that they are not interpreted as Rust
  • In docstrings, code blocks with the rs are written without this label to ensure it's possible to write tested Rust docstring that can be executed with cargo test --doc
  • In docstrings, text that has a certain level of indentation has its first space replaced by a vertical bar so that we make sure it's not interpreted as Rust code.

How has this been tested?

I added Dafny tests for the new function that converts docstrings, and also an integration test that verifies that 'cargo doc' works on the already existing but modified docstring.dfy test.

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

MikaelMayer and others added 3 commits January 28, 2025 08:22
Fixes #6084

Previously, Dafny docstring was literally transformed to Rust docstring. However, Rust docstring follows a markdown syntax where non-labelled code blocks are interpreted and checked as Rust code when running `cargo doc`.
Rather than creating a flag to avoid the docstring, this PR does a lightweight parsing on the docstring to ensures that:
* In docstrings, Code blocks without label are written using the "dafny" label so that they are not interpreted as Rust
* In docstrings, text that has a certain level of indentation has its first space replaced by a vertical bar so that we make sure it's not interpreted as Rust code.

I added Dafny tests for the new function that converts docstrings, and also an integration test that verifies that 'cargo doc' works on the already existing but modified docstring.dfy test.
@MikaelMayer MikaelMayer enabled auto-merge (squash) January 29, 2025 14:35
Copy link
Contributor

@ssomayyajula ssomayyajula left a comment

Choose a reason for hiding this comment

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

Approved, didn't know docstrings came this far into the backend!

@MikaelMayer MikaelMayer merged commit 00cae51 into master Jan 29, 2025
22 checks passed
@MikaelMayer MikaelMayer deleted the fix-6084-rust-doc branch January 29, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rust docstring does not always compile
2 participants