Skip to content

Multiline module level docs cannot handle /* in a string #129685

Closed
rust-lang/reference
#1602
@nathanosdev

Description

@nathanosdev

I tried this code:

/*!
 * ```
 * let thing = "**/*.css";
 * ```
 */

/// ```
/// let thing = "**/*.css";
/// ```
pub fn get_thing() -> &'static str {
    let thing = "**/*.css";

    thing
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn it_works() {
        let result = get_thing();
        assert_eq!(result, "**/*.css");
    }
}

I expected to see this happen: The docs to compile.

Instead, this happened:

The docs fail to compile with this message:

error: prefix css is unknown
--> src/lib.rs:3:22
|
3 | * let thing = "/*.css";
| ^^^ unknown prefix
|
= note: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
|
3 | * let thing = "
/*.css ";
| +

error: prefix css is unknown
--> src/lib.rs:11:23
|
11 | let thing = "/*.css";
| ^^^ unknown prefix
|
= note: prefixed identifiers and literals are reserved since Rust 2021
help: consider inserting whitespace here
|
11 | let thing = "
/*.css ";
| +

error[E0758]: unterminated block comment
--> src/lib.rs:23:31
|
23 | assert_eq!(result, "**/*.css");
| _______________________________^
24 | | }
25 | | }
| |__^

For more information about this error, try rustc --explain E0758.
error: could not document rustdoc_issue

Meta

rustc --version --verbose:

rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: x86_64-unknown-linux-gnu
release: 1.80.0
LLVM version: 18.1.7

I've also reproduced on nightly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTC-discussionCategory: Discussion or questions that doesn't represent real issues.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

    Issue actions