Skip to content

C javadoc comments are not Markdown-escaped, triggering rustdoc warnings #2057

Closed
@ojeda

Description

@ojeda

This comes up in Rust for Linux when generating the bindings for some C APIs that happen to have javadoc-like comments that end up being broken Markdown: Rust-for-Linux/linux#323.

Input C/C++ Header

/**
 * vdso_data.cs[x].shift
 */
void f(void);

Bindgen Invocation

$ bindgen f.h

Actual Results

extern "C" {
    #[doc = " vdso_data.cs[x].shift"]
    pub fn f();
}

Which leads to rustdoc warnings such as:

warning: unresolved link to `x`
 --> f.rs:4:5
  |
4 |     #[doc = " vdso_data.cs[x].shift"]
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
  = note: the link appears in this line:
          
          vdso_data.cs[x].shift
                       ^
  = note: no item named `x` in scope
  = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`

Expected Results

extern "C" {
    #[doc = " vdso_data.cs\\[x\\].shift"]
    pub fn f();
}

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