Skip to content

rustdoc fails unpleasantly when it can't tokenise a code block #12834

@chris-morgan

Description

@chris-morgan
Member

Consider a file like this:

#[crate_id = "sad"];

/// ```
/// a + b ∈ Self ∀ a, b ∈ Self
/// ```
pub fn foo() {}

Here's rustdoc's opinion of this:

<stdin>:1:7: 1:8 error: unknown start of token: \u2208
<stdin>:1 a + b ∈ Self ∀ a, b ∈ Self
                ^
task '<unnamed>' failed at '~Any', /home/chris/vc/rust/src/libsyntax/diagnostic.rs:48

You see, it attempted to tokenise the contents of that code block.

The current solution for this is marking that code block as "notrust":

/// ```notrust
/// a + b ∈ Self ∀ a, b ∈ Self
/// ```
pub fn foo() {}

rustdoc should do one of two things:

  1. Permit tokenisation to fail silently, discarding the notion of syntax highlighting should it fail; or

  2. Retain the current notrust-must-be-explicit behaviour, but with two alterations:

    1. Give meaningful spans, if at all possible—sad.rs:4:11: 4:12 as the error span rather than <stdin>:1:7: 1:7.
    2. Give you a hint that that might be want you meant.

    In total, perhaps something like this:

    <stdin>:1:7: 1:8 error: unknown start of token: \u2208
    <stdin>:1 a + b ∈ Self ∀ a, b ∈ Self
                    ^
    sad.rs:3:5: 3:8 info: that code block does not tokenise as Rust code; perhaps you meant to mark it as notrust?
                          (e.g. use the opening fence "```notrust")
    sad.rs:3 /// ```
                 ^~~
    

Activity

dennisoh

dennisoh commented on Jan 14, 2015

@dennisoh

I think that "A-rustdoc" label can be added.

added
T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
on Jan 14, 2015
steveklabnik

steveklabnik commented on Nov 7, 2015

@steveklabnik
Contributor

Triage: no changes.

frewsxcv

frewsxcv commented on Feb 24, 2016

@frewsxcv
Contributor

Relevant issue: servo/servo#9704

added a commit that references this issue on Apr 27, 2016
cda7c1c
added a commit that references this issue on Jul 22, 2022
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-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

      Participants

      @steveklabnik@chris-morgan@frewsxcv@huonw@dennisoh

      Issue actions

        rustdoc fails unpleasantly when it can't tokenise a code block · Issue #12834 · rust-lang/rust