Comment indentation creates failing doctests

Open
#3,530 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
tooling

Research direction

Start by reproducing the failure with the Rust doc attribute shown in the issue and the documented .clang_arg options. Read the bindgen code that handles C comments and generates Rust documentation to find where indentation becomes a failing doctest. Done means the generated documentation no longer creates a failing doctest for the example; the issue leaves the implementation approach open.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Rust
Stars
5.3k
Forks
846
Avg merge
2d 6h
Merged PRs (30d)
11

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rust-lang/rust-bindgen

All issues in rust-lang/rust-bindgen

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.