Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ojeda opened this issue May 29, 2021 · 4 comments
Closed

Comments

@ojeda
Copy link

ojeda commented May 29, 2021

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();
}
@emilio
Copy link
Contributor

emilio commented Jun 21, 2021

This is #1313 basically... I suspect the best path forward here is probably making sure we treat all doc comments as literal blocks of code (basically prepending triple-quotes or something) so that we don't mess up whitespace and other things people do on doc comments. There's some other discussion about this somewhere else, IIRC.

@pvdrz
Copy link
Contributor

pvdrz commented Nov 14, 2022

#2347 could provide a solution for this.

@zopsicle
Copy link

zopsicle commented Nov 22, 2022

making sure we treat all doc comments as literal blocks of code

It would be nice to still offer the original behavior, in case a library is bindgenned which uses Markdown comments.

@pvdrz
Copy link
Contributor

pvdrz commented Nov 22, 2022

now that #2347 landed. This can be solved by implementing ParseCallbacks::process_comments to either wrap the comment in backticks:

#[derive(Debug)]
struct Cb;

impl ParseCallbacks for Cb {
    fn process_comment(&self, comment: &str) -> Option<String> {
        Some(format!("````\n{}\n````", comment))
    }
}

or parsing it with a javadoc parser (not sure if such thing exists in Rust)

@pvdrz pvdrz closed this as completed Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants