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

Use /// for all docs #44

Open
pvdrz opened this issue Mar 24, 2023 · 4 comments
Open

Use /// for all docs #44

pvdrz opened this issue Mar 24, 2023 · 4 comments

Comments

@pvdrz
Copy link

pvdrz commented Mar 24, 2023

Hi! Is there any reason why multi-line docs are formatted using /**?

For example, the following code:

#[doc = " This is a single line doc"]
pub type foo = ::std::os::raw::c_int;
#[doc = " This is a multi line doc.\n With way too many lines"]
pub type bar = ::std::os::raw::c_int;

is being formatted as

/// This is a single line doc
pub type foo = ::std::os::raw::c_int;
/** This is a multi line doc.
 With way too many lines*/
pub type bar = ::std::os::raw::c_int;

and I'd like it to be

/// This is a single line doc
pub type foo = ::std::os::raw::c_int;
/// This is a multi line doc.
/// With way too many lines
pub type bar = ::std::os::raw::c_int;
@jdygert-spok
Copy link

prettyplease maybe could fix this for you, but this is a consequence of how line doc comments are represented as separate doc attributes. These two are equivalent:

/// a
/// b
struct Foo;

#[doc = " a"]
#[doc = " b"]
struct Foo;

So as a result, if you want to generate line doc comments with quote, you can do something like this:

let doc = " a\n b";
let lines = doc.lines();
quote! {
    #( #[doc = #lines] )*
    struct Foo;
}

@dtolnay
Copy link
Owner

dtolnay commented Jan 18, 2024

The rules for turning an arbitrary multi-line doc into multiple single-line doc, without breaking rustdoc's or markdown's interpretation of the text, is absurdly complicated. Eventually it would be good to develop logic to handle that but it will be an extremely involved change -- not a matter of .lines() in prettyplease.

@jdygert-spok
Copy link

Understood, the example above is just a workaround that is often usable "downstream".

@dtolnay
Copy link
Owner

dtolnay commented Jan 18, 2024

Makes sense, thanks! Yeah it's a useful suggestion especially if someone is just concerned with a subset of possible markdown, such as paragraphs of text with no indented lists or code blocks.

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

No branches or pull requests

3 participants