immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.81k stars 220 forks source link

bitfields: error when using `derive(BitfieldStruct)` on a struct with lifetime parameters #993

Open spernsteiner opened 1 year ago

spernsteiner commented 1 year ago
use c2rust_bitfields::BitfieldStruct;

#[derive(BitfieldStruct)]
pub struct Foo {
    pub x: &'static i32,
    #[bitfield(name = "flags", ty = "u32", bits = "0..=7")]
    pub flags: [u8; 1],
}

#[derive(BitfieldStruct)]
pub struct Bar<'a> {
    pub x: &'a i32,
    #[bitfield(name = "flags", ty = "u32", bits = "0..=7")]
    pub flags: [u8; 1],
}

struct Foo works, struct Bar doesn't:

error[E0726]: implicit elided lifetime not allowed here
  --> src/main.rs:11:12
   |
11 | pub struct Bar<'a> {
   |            ^^^ expected lifetime parameter
   |
   = note: assuming a `'static` lifetime...
help: indicate the anonymous lifetime
   |
11 | pub struct Bar<'_><'a> {
   |               ++++

Presumably the weird error reporting is due to the Bar token being reused somewhere in the derive(BitfieldStruct) output (without the necessary lifetime arguments) while keeping its original span.