[FFI] Rust's warnings are driving me crazy

Someone please tell me where I can find the entire list of warnings, I searched and found nothing recent, most are from 2016 and it did not work for me. The snake case, camel case and upper case warnings are infesting my file. Help me get them out of the file.
I need to remove the warnings and not change the original name, which are native to C.

Just change the cases to follow the recommendations. This is the correct thing to do. Not following the recommendations is ignoring standards of the language the community has established. Going against these standards is not something that the community supports.

2 Likes

Impossible, I marked the question with FFI, I cannot change the name of the functions, structs and consts so as not to break the functionality.
I need to remove the warnings, that's all.

Derp. I missed that. In that case, I believe what you are looking for is the lints for case conventions built into the compiler. These can be viewed by: rustc -W help which will show (amongst other things):

nonstandard-style  non-camel-case-types, non-snake-case, non-upper-case-globals

So, to allow non-camel-case-types you would use #[allow(non-camel-case-types)] etc. You can put these in the modules that contain your FFI code.

2 Likes

You can write #![allow(warnings)], but that's... frowned upon.

The whole list of declared lints is in the code. There should be an authoritative page, like clippy does.

2 Likes

Does this give you the info you need?

rustc -W help
1 Like

The name of the lint is also included in the warning message:

warning: type `foo` should have an upper camel case name
 --> src/lib.rs:1:8
  |
1 | struct foo;
  |        ^^^ help: convert the identifier to upper camel case (notice the capitalization): `Foo`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

The last line is where you can find the name of the lint (non_camel_case_types).

3 Likes

The usage of such nonstandard style element doesn't triggers the warning, only declaration does. The bindgen should put appropriate allow flags to the generated code. Maybe you're generating the binding code manually?

1 Like

That was strange, cargo always gives me useful tips but in this case he only issued warnings without information on how to resolve it.

warning: structure field rayTraversalPrimitiveCulling should have a snake case name
--> src/mana_vulkan_loader.rs:62087:9
|
62087 | pub rayTraversalPrimitiveCulling: VkBool32,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: ray_traversal_primitive_culling

warning: structure field sType should have a snake case name
--> src/mana_vulkan_loader.rs:62203:9
|
62203 | pub sType: VkStructureType,
| ^^^^^ help: convert the identifier to snake case: s_type

No, I'm using bindgen and the code is full of warnings.

[build-dependencies]
bindgen = "0.57"

Those are all #[allow(nonstandard_style)] warnings.

But if you just want to silence all of the warnings, use #[allow(warnings)]. It's frowned upon, but this is generated code anyway, so you might not care.

Right. It wasn't prevented by the bindgen. The official tutorial covers this case.

1 Like

Oops, I'm using a script to process the file produced by bindgen and produce a new rust file and I didn't pay attention to that part. I apologize for the mistake.

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.