Robbepop / modular-bitfield

Macro to generate bitfields for structs that allow for modular use of enums.
Apache License 2.0
155 stars 40 forks source link

fixup! [impl] silence most repetitive dead_code warnings #58

Closed lkolbly closed 3 years ago

lkolbly commented 3 years ago

Adds a bunch more dead_code warnings.

With this playground:

//#![allow(dead_code, unused_attributes, unused_imports)]

use modular_bitfield::prelude::*;

#[bitfield]
struct MyFourBytes {
    a: B1,
    b: B3,
    c: B4,
    d: B24,
}

fn main() {
    let x = MyFourBytes::new();
    println!("{}", x.a());
}

I get no warnings.

This may affect #56, since it seemed like the issue there was more about silencing warnings than reducing generated code. (I won't say the magic words to make it auto-close, though)

Robbepop commented 3 years ago

Hey sorry for missing the review here! I'd rather like #56 to be implemented rather than silencing all warnings as warnings are actually a feature, even for generated code. E.g. a user can take those warnings and add the #[skip(..)] attributes where needed to reduce code bloat. If warnings were not in place the user would not be notified about the potential code bloat.

lkolbly commented 3 years ago

Yeah, code bloat is a problem, and although LTO should ideally eliminate it from the binary it still slows down compilation. The getters and setters already have allow(dead_code) set on them, so this PR just matches that.

Robbepop commented 3 years ago

The getters and setters already have allow(dead_code) set on them, so this PR just matches that.

IIRC only some of the setters and getters do have #[allow(dead_code)] on them. Enough to not have duplicate warnings, so only ever one of the many generated getters is warned about for the entirety of the getters.

lkolbly commented 3 years ago

Hm, okay, I'd buy that. I'll close this PR then.