Allow non_snake_case for individual fields

Is it possible to put #[allow(non_snake_case)] on individual fields?

pub struct Foo {
    #[allow(non_snake_case)]
    pub x____y____z: u8,
}

Despite the #[allow], this still generates a warning:

warning: structure field `x____y____z` should have a snake case name
 --> src/lib.rs:3:9
  |
3 |     pub x____y____z: u8,
  |         ^^^^^^^^^^^ help: convert the identifier to snake case: `x_y_z`
  |
  = note: `#[warn(non_snake_case)]` on by default

(Playground)

My use case is that I have a macro that adds hidden bookkeeping fields to a struct. Sometimes the fields have multiple underscores in a row. I'd like to be able to disable the snake-case check for the hidden fields but not do it for the struct as a whole.

I believe this is the issue (despite the title).

1 Like

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.