rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

[0.71.1]: Invalid generated method names.

Open Kangie opened this issue 7 months ago • 3 comments

Unable to compile Mesa with 0.71.1 for Fedora in a Mesa CI container due to the following:

[3762/4770] Compiling Rust source src/etnaviv/isa/isa_bindings.rs
FAILED: src/etnaviv/isa/libisa_bindings.rlib 
rustc -C linker=cc --color=always -C debug-assertions=no -C overflow-checks=no --crate-type rlib -D warnings --edition=2021 -C opt-level=3 --crate-name isa_bindings --emit dep-info=src/etnaviv/isa/isa_bindings.d --emit link=src/etnaviv/isa/libisa_bindings.rlib --out-dir src/etnaviv/isa/libisa_bindings.rlib.p -C metadata=5824fa0@@isa_bindings@sta -Anon_camel_case_types src/etnaviv/isa/isa_bindings.rs
error: method `use__raw` should have a snake case name
 --> src/etnaviv/isa/isa_bindings.rs:1:9453
  |
1 | ...s u64) } } # [inline] pub unsafe fn use__raw (this : * const Self) -> :: std :: os :: raw :: c_uint { unsafe { :: std :: mem :: transm...
  |                                        ^^^^^^^^ help: convert the identifier to snake case: `use_raw`
  |
  = note: `-D non-snake-case` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(non_snake_case)]`
error: method `use__raw` should have a snake case name
 --> src/etnaviv/isa/isa_bindings.rs:1:29259
  |
1 | ...s u64) } } # [inline] pub unsafe fn use__raw (this : * const Self) -> :: std :: os :: raw :: c_uint { unsafe { :: std :: mem :: transm...
  |                                        ^^^^^^^^ help: convert the identifier to snake case: `use_raw`
error: aborting due to 2 previous errors

The field is called use on the C side, however as this is a reserved keyword bindgen is suffixing a _, but not dropping it when the function is named.

Encountered in the following Mesa MR: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33725#note_2909634

Kangie avatar May 14 '25 08:05 Kangie

well, this is in any case a warning tho, right? It's just you're using -D warnings.

emilio avatar Jun 08 '25 11:06 emilio

These warnings have since been #![allow()]ed for the generated bindings on the Mesa side. It would still be nice for bindgen not to generate names resulting in warnings.

LingMan avatar Jun 08 '25 11:06 LingMan

Yeah, so the issue is that we re-use the already-mangled name and just append _raw to it. It comes from 3c09db0b5646b3d229d5c5f5e13cf2b2373ae2d9.

It should be relatively straight-forward to do this by either undoing the mangling, or by keeping the original pre-mangling name.

emilio avatar Jun 08 '25 11:06 emilio