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

[Feature Request] Skip formatting doc comments altogether when mixing sugared and de-sugared doc comments #6017

Open
stepancheg opened this issue Jan 10, 2024 · 3 comments

Comments

@stepancheg
Copy link
Contributor

Input:

//! <details open>
//!     <summary>Example 1</summary>
//!
//! ```
#![doc = "test()"]
//! ```
//!
//! </details>
//!
//! <details open>
//!     <summary>Example 2</summary>
//!
//! ```
//! example(2);
//! ```
//!
//! </details>
rustfmt +nightly --config format_code_in_doc_comments=true

Outputs:

//! <details open>
//!     <summary>Example 1</summary>
//!
//! ```
#![doc = "test()"]
//! ```
//!
//! </details>
//!
//! <details open>
//!     <summary>Example 2</summary>
//! ```
//! example(2);
//! ```
//!
//! </details>

Note no empty line before second example. So rustdoc of output looks like this:

image

Empty lines before backticks are important for Markdown.

Rustdoc uses commonmark

HTML blocks in commonmark must end with empty line:

End condition: line is followed by a blank line

rustfmt 1.7.0-nightly (ca663b06 2024-01-08)
@ytmimi
Copy link
Contributor

ytmimi commented Jan 10, 2024

I'm pretty sure the use of #![doc = "test()"] is throwing rustfmt off. This feels very similar to #5420.

//! <details open>
//!     <summary>Example 1</summary>
//!
//! ```
//! test()
//! ```
//!
//! </details>
//!
//! <details open>
//!     <summary>Example 2</summary>
//! ```
//! example(2);
//! ```
//!
//! </details>

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2024
@stepancheg
Copy link
Contributor Author

@ytmimi that issue you linked is closed.

The problem with this case is that it rustfmt damages valid code, so I believe some solution is needed (for example, just skip formatting of comments if they have #[doc]).

@ytmimi
Copy link
Contributor

ytmimi commented Jan 10, 2024

The linked issue is closed because of technical limitations on rustfmt's side. Maybe it's possible to skip formatting altogether if there's a mix of sugared and de-sugard doc comments. I'll reopen this one for now as a feature request, but I'll be honest this is pretty low priority, and I don't anticipate the rustfmt team working on this directly.

@ytmimi ytmimi reopened this Jan 10, 2024
@ytmimi ytmimi changed the title format_code_in_doc_comments HTML tags break when #[doc] is used [Feature Request] Skip formatting doc comments altogether when mixing sugared and de-sugared doc comments Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants