c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

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

Open spernsteiner opened this issue 2 years ago • 0 comments

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.

spernsteiner avatar Jul 17 '23 18:07 spernsteiner