Bindgen generated doc comments are interpreted as tests


I have a C code that looks something like that:

 * This is a comment.
 *              SOME_CONSANT_NAME - this is obviously not a valid rustcode
int item(void);

bindgen (rightfully) generated the following code, which is great:

extern "C" {
    #[doc = " This is a comment."]
    #[doc = ""]
    #[doc = "\t\t\t\tSOME_CONSANT_NAME - this is obviously not a valid rustcode"]
    pub fn item() -> ::std::os::raw::c_int;

The problem is that due to the indentation, Rust (rustdoc? libtest?) tries to compile and test the comment, which will obviously always fail.

This works fine if I run bindgen with .generate_comments(false), but I wonder if there's some other workaround (i.e. ignoring doctests for a whole module) that will let me keep the docs.

Okay it looks like a long known issue without a solution:

I solve it by running sed on the bindgen-generated file and find'n'replace #[doc = "\t\t\t\t with #[doc = "

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.