Skip to content

Rustdoc does not compile code pieces if they are not separated from the surrounding text #28712

Closed
@netvl

Description

@netvl
Contributor

The following is a perfectly valid Markdown, however, Rustdoc does not compile the piece of code (and, naturally, it is not run as a test with cargo test):

/// This is a test:
/// ```rust
/// let x = SomeUnknownStructure::new();
/// ```

This, however, does work:

/// This is a test:
///
/// ```rust
/// let x = SomeUnknownStructure::new();
/// ```

(that is, it fails to compile due to unknown symbol SomeUnknownStructure).

Note the empty line before the code block in the doc comment.

Activity

added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Sep 29, 2015
Aatch

Aatch commented on Sep 30, 2015

@Aatch
Contributor

Does it render correctly? If not it may be a bug in the mardown parser.

netvl

netvl commented on Sep 30, 2015

@netvl
ContributorAuthor

It looks like that it also renders incorrectly:
screen shot 2015-09-30 at 12 05 49
This is for the first snippet from the original post, the second snippet looks correctly.

sfackler

sfackler commented on Sep 30, 2015

@sfackler
Member

This is how at least some markdown parsers work - without a double line break before the tick marks, it's treated as part of the previous paragraph.

Aatch

Aatch commented on Oct 2, 2015

@Aatch
Contributor

The decision now then is whether we consider this working-as-expected or an actual bug?

steveklabnik

steveklabnik commented on Oct 2, 2015

@steveklabnik
Member

CommonMark says

A fenced code block may interrupt a paragraph, and does not require a blank line either before or after.

http://spec.commonmark.org/0.22/#code-fence

So I would argue it is a bug.

cjsut

cjsut commented on Mar 8, 2016

@cjsut
Contributor

Also affects lists.

In CommonMark, a list can interrupt a paragraph. That is, no blank line is needed to separate a paragraph from a following list:

http://spec.commonmark.org/0.24/#lists

added
T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
and removed on May 18, 2017
Mark-Simulacrum

Mark-Simulacrum commented on Jul 24, 2017

@Mark-Simulacrum
Member

With -Zunstable-options --enable-commonmark, rustdoc emits the following today, so I'm going to close this.

WARNING: test.rs - main (line 2) Code block is not currently run as a test, but will in future versions of rustdoc. Please ensure this code block is a runnable test, or use the `ignore` directive.
/// This is a test:
/// ```rust
/// let x = SomeUnknownStructure::new();
/// ```
pub fn main() {}
added a commit that references this issue on Mar 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @steveklabnik@netvl@Aatch@sfackler@cjsut

        Issue actions

          Rustdoc does not compile code pieces if they are not separated from the surrounding text · Issue #28712 · rust-lang/rust