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 changes code blocks to inline code in trait implementations #73474

Closed
nn1ks opened this issue Jun 18, 2020 · 0 comments · Fixed by #73819
Closed

Rustdoc changes code blocks to inline code in trait implementations #73474

nn1ks opened this issue Jun 18, 2020 · 0 comments · Fixed by #73819
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@nn1ks
Copy link
Contributor

nn1ks commented Jun 18, 2020

If a doc comment of a trait item begins with a code block, it will be changed to inline code in implementations of that trait, which leads to weird formatting.

Example

pub trait TraitExample {
    /// Some text.
    ///
    /// ```
    /// let a = 0;
    /// ```
    fn a() {}

    /// ```
    /// let b = 0;
    /// ```
    fn b() {}

    /// ```rust
    /// let c = 0;
    /// ```
    fn c() {}

    /// ```
    /// // Comment `example`.
    /// let d = 0;
    /// ```
    fn d() {}
}

pub struct StructExample;

impl TraitExample for StructExample {}

Here is what it looks like in the implementation for StructExample:

2020-06-18-154158_1542x547_scrot

  • The docs for the method a work as expected.

  • The code block of method b is changed to inline code.

  • The code block of method c is also changed to inline code and the word rust is shown in the inline code instead of specifying the syntax. There is also a trailing whitespace which is not present in the original code block.

  • In the docs of d the backticks of the word example end the main inline code.

While the inline code looks fine in simple examples (e.g. docs of method b), the format is confusing in most cases. The expected behaviour would probably be that the code block does not get converted to inline code.

Example in std

Another example for this behaviour can be seen in the description method of std::error::Error. The docs of the method begin with a code block and then get changed to inline code in the implementations.

Documentation in std::error::Error:

2020-06-18-160734_1537x305_scrot

Documentation of the implementation in std::io::Error:

2020-06-18-160528_1517x191_scrot

More examples: std::io::Error (stable, nightly), std::num::ParseIntError (stable, nightly).

Meta

I ran rustdoc/cargo doc in both stable and nightly which all generated the same result.

rustdoc --version --verbose:

rustdoc 1.44.1 (c7087fe00 2020-06-17)
binary: rustdoc
commit-hash: c7087fe00d2ba919df1d813c040a5d47e43b0fe7
commit-date: 2020-06-17
host: x86_64-unknown-linux-gnu
release: 1.44.1
LLVM version: 9.0

rustdoc --version --verbose:

rustdoc 1.46.0-nightly (2935d294f 2020-06-17)
binary: rustdoc
commit-hash: 2935d294ff862fdf96578d0cbbdc289e8e7ba81c
commit-date: 2020-06-17
host: x86_64-unknown-linux-gnu
release: 1.46.0-nightly
LLVM version: 10.0
@nn1ks nn1ks added the C-bug Category: This is a bug. label Jun 18, 2020
@jonas-schievink jonas-schievink added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jun 18, 2020
@nn1ks nn1ks changed the title Rustdoc generates weird formatting of code blocks in trait implementations Rustdoc changes code blocks to inline code in trait implementations Jun 18, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 3, 2020
…illaumeGomez

rustdoc: do not use plain summary for trait impls

Fixes rust-lang#38386.
Fixes rust-lang#48332.
Fixes rust-lang#49430.
Fixes rust-lang#62741.
Fixes rust-lang#73474.

Unfortunately this is not quite ready to go because the newly-working links trigger a bunch of linkcheck failures. The failures are tough to fix because the links are resolved relative to the implementor, which could be anywhere in the module hierarchy.

(In the current docs, these links end up rendering as uninterpreted markdown syntax, so I don't think these failures are any worse than the status quo. It might be acceptable to just add them to the linkchecker whitelist.)

Ideally this could be fixed with intra-doc links ~~but it isn't working for me: I am currently investigating if it's possible to solve it this way.~~ Opened rust-lang#73829.

EDIT: This is now ready!
@bors bors closed this as completed in e0822ec Sep 3, 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants