Disable warnings in ffi module generated by bindgen

I have generated an ffi-module from a C header file. Now I am writing a crate that makes use of this C-lib. Unfortunately the rust linter is burying error messages under a bunch of dead code and camel case warnings, so that it is sometimes tedious to spot the real error.

I tried to #[allow(dead_code)] at the top of the ffi generated file, but the warnings remain. Same for the camel case ones.

you have to use #![allow(dead_code)] (note the !) if you want disable the lint for the whole file

1 Like

Ah, that worked. I thought the ! was only for crate-wide lints and I just want it on the ffi-module. But it works exactly how I want it.

Thank you very much.

without the ! it's for the next struct, enum, fn, ... and with the ! it's for it's parent so

#[allow(dead_code]
mod foo {
    ...
}

and

mod foo {
    #![allow(dead_cose)]
    ...
}

are the same

2 Likes

so I have the same problem but, the generated code is going to ... get regenerated.
how I do insert the ```
#![allow(dead_cose)]

at the top of the file after it's been generated.
I should shove it in with build.rs but that's a bit heavyhanded.
is there a way to do it in the module  that refers to it?

I tried this:

mod bindings
{
    #![allow(dead_code)]
}

but that just made it look like the actual definition.

ideas? Thanks.

You should be able to put it as an attribute on the mod declaration. In this case you would not need the exclamation mark.

Like this,

#[allow(dead_code)]
mod bindings;

(@nixomose also, please don't revive year old threads, it's fine to create a new threads)

#[allow(dead_code)]
mod bindings;

so yeah, that worked swimmingly, thanks.

1 Like