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

Rustdoc treats indentations in the consecutive syntactically same doc-comments and doc-attributes differently #77764

Closed
zheland opened this issue Oct 9, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@zheland
Copy link

zheland commented Oct 9, 2020

According to https://doc.rust-lang.org/rustdoc/the-doc-attribute.html
the lines below are the same:

/// This is a doc comment.
#[doc = " This is a doc comment."]

But when mixing doc-comments and doc-attributes indentation in the next comment or attribute is ignored.

For example cargo doc generate different doc pages for

///Header
///
///    assert!(true);
pub fn func() {}

and

///Header
///
#[doc = "    assert!(true);"]
pub fn func() {}

where ///____assert!(true); produce CodeBlock for the first function (generated docs), but #[doc = "____assert!(true);"] produce plain text paragraph for the second function (generated docs).

This behavior might be usefull for saving identical indents in documentation declared in comments and attributes:

/// Some docs
#[cfg_attr(feature = "foo", doc = #"
    continuation with visually the same indentation
"#)]
/// continuation with visually the same indentation

but in general this behavior is not explicit.

For example syn crate produce exactly the same output when parsing docs both functions with syn::parse_file and preserves all the spaces.

If this behavior is intentional it should be docummented.

More examples:

Reproduced with cargo doc on rustc 1.47.0 (18bf6b4f0 2020-10-07) and rustc 1.49.0-nightly (91a79fb29 2020-10-07)

@zheland zheland added the C-bug Category: This is a bug. label Oct 9, 2020
@jyn514
Copy link
Member

jyn514 commented Oct 9, 2020

Duplicate of #70732 (but I like your title better, I might steal it).

@jyn514 jyn514 closed this as completed Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants