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 does not compile code pieces if they are not separated from the surrounding text #28712

Closed
netvl opened this issue Sep 28, 2015 · 7 comments
Labels
T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@netvl
Copy link
Contributor

netvl commented Sep 28, 2015

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.

@steveklabnik steveklabnik added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 29, 2015
@Aatch
Copy link
Contributor

Aatch commented Sep 30, 2015

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

@netvl
Copy link
Contributor Author

netvl commented Sep 30, 2015

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
Copy link
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
Copy link
Contributor

Aatch commented Oct 2, 2015

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

@steveklabnik
Copy link
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.

@insaneinside
Copy link
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

@Mark-Simulacrum
Copy link
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() {}

dlukes added a commit to dlukes/rustfmt that referenced this issue Mar 10, 2018
Doctests were disabled globally because up until rust-lang#2456, they were just
formatting examples which were not supposed to compile. Now that there
is one runnable doctest, I disabled the other ones individually (by
adding the ignore directive).

I also added some empty lines around the code blocks to avoid the
following warning and instead ignore the code blocks cleanly:

WARNING: ... 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.

See rust-lang/rust#28712 for further details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants